Spaces:
Paused
Paused
Download api/models/spam.py from mrqadeer/email-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/models/spam.py
- Command line
-
hf download hf://spaces/mrqadeer/email-classifier/api/models/spam.py
-
curl -L -o spam.py https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/models/spam.py
1.48 kB
| from pydantic import BaseModel, Field, field_validator | |
| from typing import List, Optional | |
| class EmailContent(BaseModel): | |
| """Single email content request model""" | |
| text: str = Field( | |
| ..., | |
| min_length=1, | |
| max_length=100000, | |
| description="Email content text", | |
| example="Get a free gift card now!" | |
| ) | |
| def text_must_not_be_empty(cls, v): | |
| v = v.strip() | |
| if not v: | |
| raise ValueError('Email text cannot be empty') | |
| return v | |
| class BatchEmailsRequest(BaseModel): | |
| """Batch email request model""" | |
| emails: List[EmailContent] = Field( | |
| default=..., | |
| min_items=1, | |
| max_items=100 | |
| ) | |
| class SpamPredictionResult(BaseModel): | |
| """Single prediction result model""" | |
| is_spam: bool | |
| spam_probability: float = Field( | |
| default=..., | |
| ge=0.0, | |
| le=1.0 | |
| ) | |
| classification: str # 'SPAM' or 'HAM' | |
| text: Optional[str] = None # Original text might be included in response | |
| class BatchPredictionResponse(BaseModel): | |
| """Batch prediction response model""" | |
| results: List[SpamPredictionResult] | |
| summary: dict = Field( | |
| default=..., | |
| example={ | |
| "total": 10, | |
| "spam_count": 7, | |
| "ham_count": 3, | |
| "spam_percentage": 70.0 | |
| } | |
| ) | |
| class SinglePredictionResponse(BaseModel): | |
| """Single prediction response model""" | |
| result: SpamPredictionResult | |