Spaces:
Sleeping
Sleeping
from pydantic import BaseSettings, Field | |
import logging | |
# Configure logger | |
logger = logging.getLogger(__name__) | |
class Settings(BaseSettings): | |
# Default values for the processor and model | |
processor: str = Field(default="senga-ml/donut-v16") | |
model: str = Field(default="senga-ml/donut-v16") | |
dataset: str = Field(default="senga-ml/dnotes-data-v6") | |
base_config: str = Field(default="naver-clova-ix/donut-base") | |
base_processor: str = Field(default="naver-clova-ix/donut-base") | |
base_model: str = Field(default="naver-clova-ix/donut-base") | |
inference_stats_file: str = Field(default="data/donut_inference_stats.json") | |
training_stats_file: str = Field(default="data/donut_training_stats.json") | |
evaluate_stats_file: str = Field(default="data/donut_evaluate_stats.json") | |
# The shipper_id to dynamically select model and processor | |
shipper_id: str = Field(default="default_shipper") | |
class Config: | |
validate_assignment = True | |
def __init__(self, **kwargs): | |
super().__init__(**kwargs) | |
self.set_model() | |
# Dynamically select model and processor based on shipper_id | |
def set_model(self): | |
shipper_model_map = { | |
# Shippers using donut-v16 | |
"61": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"}, # Tropical Heat | |
"81": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"}, # Clique | |
"139": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"}, # Winnie's | |
"67": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"}, # Skypex | |
"193": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"}, # Storesome | |
"195": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"}, # On Demand | |
"194": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"}, # Healthy U | |
# Shippers using donut-v17 | |
"165": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"}, # Loki | |
"127": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"}, # Jumbo Spices | |
"145": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"}, # Carolines | |
"80": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"}, # Portcross | |
"220": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"}, # Zulu | |
# Shippers using donut-v18 | |
"177": {"model": "senga-ml/donut-v18", "processor": "senga-ml/donut-v18"}, # Smart Global | |
"216": {"model": "senga-ml/donut-v18", "processor": "senga-ml/donut-v18"}, # Melvins | |
"182": {"model": "senga-ml/donut-v18", "processor": "senga-ml/donut-v18"}, # Roshni | |
"226": {"model": "senga-ml/donut-v18", "processor": "senga-ml/donut-v18"}, # Fayaz | |
"145": {"model": "senga-ml/donut-v18", "processor": "senga-ml/donut-v18"}, # Beyond Opinion | |
"232": {"model": "senga-ml/donut-v18", "processor": "senga-ml/donut-v18"}, # Gel x | |
} | |
previous_model = self.model | |
previous_processor = self.processor | |
shipper_id_str = str(self.shipper_id) | |
config = shipper_model_map.get( | |
shipper_id_str, | |
{"model": self.base_model, "processor": self.base_processor} | |
) | |
self.model = config["model"] | |
self.processor = config["processor"] | |
return self.model, self.processor | |
settings = Settings() | |
logger.info(f"Initial model setup: {settings.model}") | |
# trigger model change | |
def update_shipper(new_shipper_id): | |
""" | |
Update the shipper ID and change the model accordingly | |
Args: | |
new_shipper_id: The new shipper ID to use | |
Returns: | |
tuple: (model, processor) that were selected | |
""" | |
logger.info(f"Updating shipper ID to {new_shipper_id}") | |
settings.shipper_id = new_shipper_id | |
return settings.set_model() |