File size: 1,477 Bytes
f6ea7de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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!"
    )
    
    @field_validator('text')
    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