holypug1274's picture
deploy: privacy-sanitizer backend 2026-04-27
dc6630c
Raw
History Blame
2.39 kB
from pydantic_settings import BaseSettings
# Each entry: full metadata shown in the model picker UI
AVAILABLE_MODELS: list[dict] = [
{
"id": "iiiorg/piiranha-v1-detect-personal-information",
"label": "Piiranha v1",
"provider": "iiiorg",
"params": "110M",
"quality": "good",
"quality_score": 2,
"speed": "fast",
"entity_types": ["PER", "EMAIL", "PHONE", "ADDRESS", "ORG", "LOC", "DATE", "ID"],
"description": "Lightweight BERT-based model fine-tuned specifically for PII detection across 8+ entity types. Best for general-purpose anonymization with minimal latency.",
},
{
"id": "dslim/bert-base-NER",
"label": "BERT-base NER",
"provider": "dslim",
"params": "110M",
"quality": "good",
"quality_score": 2,
"speed": "fast",
"entity_types": ["PER", "ORG", "LOC", "MISC"],
"description": "Standard CoNLL-2003 NER model. High precision on person names, organizations and locations. Limited to 4 entity types — ideal when false positives matter more than coverage.",
},
{
"id": "Jean-Baptiste/roberta-large-ner-english",
"label": "RoBERTa-large NER",
"provider": "Jean-Baptiste",
"params": "355M",
"quality": "best",
"quality_score": 3,
"speed": "slow",
"entity_types": ["PER", "ORG", "LOC", "MISC"],
"description": "355M parameter RoBERTa fine-tuned on OntoNotes 5.0. Highest accuracy on complex/ambiguous text. Significantly slower — use when precision is critical.",
},
]
DEFAULT_MODEL_ID: str = AVAILABLE_MODELS[0]["id"]
class Settings(BaseSettings):
# Environment: "local" | "staging" | "production"
app_env: str = "local"
default_model_name: str = DEFAULT_MODEL_ID
host: str = "0.0.0.0"
port: int = 8000
# Staging: set FRONTEND_URL=https://your-app.vercel.app in HF Space secrets
frontend_url: str = ""
# Base origins always allowed; staging/production add the deployed frontend URL
@property
def allowed_origins(self) -> list[str]:
origins = ["http://localhost:3000", "http://127.0.0.1:3000"]
if self.frontend_url:
origins.append(self.frontend_url)
return origins
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
settings = Settings()