This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| from litserve import LitAPI, LitServer | |
| from pydantic import BaseModel, conint | |
| from pydantic_settings import BaseSettings | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| class ToxicitySettings(BaseSettings): | |
| model_id: str = "s-nlp/roberta_toxicity_classifier" | |
| port: conint(ge=1024, le=65535) = 8000 # type: ignore |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Union | |
| def is_valid_type(object): | |
| return isinstance(object, Union[str, None]) | |
| def is_valid_type_new(object): | |
| return isinstance(object, str | None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from pandas.testing import assert_frame_equal | |
| df_one = pd.DataFrame( | |
| {"city": ["Tokyo", "Delhi"], "population": [13_515_271, 16_753_235]} | |
| ) | |
| df_two = df_one[["population", "city"]].copy(deep=True) | |
| assert_frame_equal(left=df_one, right=df_two) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| names = ['a', 'b', 'c'] | |
| values = [10, 54, 2] | |
| values_too_long = values + [10] | |
| """ | |
| >>> {k: v for k, v in zip(names, values_too_long, strict=True)} | |
| ValueError: zip() argument 2 is longer than argument 1 | |
| >>> {k: v for k, v in zip(names, values_too_long, strict=False)} | |
| {'a': 10, 'b': 54, 'c': 2} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from pandarallel import pandarallel | |
| from sklearn.datasets import fetch_20newsgroups | |
| def preprocess_text(row: pd.Series) -> float: | |
| return [word.lower() for word in row.text.split()] | |
| def get_data() -> pd.DataFrame: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import pytest | |
| @pytest.fixture | |
| def min_dict(): | |
| return {"name": "foo"} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pydantic import BaseSettings, Field, SecretStr | |
| class Credentials(BaseSettings): | |
| password: SecretStr = Field(..., env="DB_PASSWORD") | |
| """ | |
| >>> Credentials() | |
| pydantic.error_wrappers.ValidationError: 1 validation error for Credentials |
NewerOlder