malek-messaoudii
commited on
Commit
·
54b5a2a
1
Parent(s):
15da915
update name
Browse files- models/label.py +98 -1
models/label.py
CHANGED
|
@@ -1 +1,98 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pydantic schemas for key-point matching prediction endpoints"""
|
| 2 |
+
|
| 3 |
+
from pydantic import BaseModel, Field, ConfigDict
|
| 4 |
+
from typing import List, Optional, Dict
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class PredictionRequest(BaseModel):
|
| 8 |
+
"""Request model for single key-point/argument prediction"""
|
| 9 |
+
model_config = ConfigDict(
|
| 10 |
+
json_schema_extra={
|
| 11 |
+
"example": {
|
| 12 |
+
"argument": "Climate change is accelerating due to industrial emissions.",
|
| 13 |
+
"key_point": "Human industry contributes significantly to global warming."
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
argument: str = Field(
|
| 19 |
+
..., min_length=5, max_length=1000,
|
| 20 |
+
description="The argument text to evaluate"
|
| 21 |
+
)
|
| 22 |
+
key_point: str = Field(
|
| 23 |
+
..., min_length=5, max_length=500,
|
| 24 |
+
description="The key point used for comparison"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class PredictionResponse(BaseModel):
|
| 29 |
+
"""Response model for single prediction"""
|
| 30 |
+
model_config = ConfigDict(
|
| 31 |
+
json_schema_extra={
|
| 32 |
+
"example": {
|
| 33 |
+
"prediction": 1,
|
| 34 |
+
"confidence": 0.874,
|
| 35 |
+
"label": "MATCH",
|
| 36 |
+
"probabilities": {
|
| 37 |
+
"match": 0.874,
|
| 38 |
+
"no_match": 0.126
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
prediction: int = Field(..., description="1 = match, 0 = no match")
|
| 45 |
+
confidence: float = Field(..., ge=0.0, le=1.0,
|
| 46 |
+
description="Confidence score of the prediction")
|
| 47 |
+
label: str = Field(..., description="MATCH or NO_MATCH")
|
| 48 |
+
probabilities: Dict[str, float] = Field(
|
| 49 |
+
..., description="Dictionary of class probabilities"
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class BatchPredictionRequest(BaseModel):
|
| 54 |
+
"""Request model for batch predictions"""
|
| 55 |
+
model_config = ConfigDict(
|
| 56 |
+
json_schema_extra={
|
| 57 |
+
"example": {
|
| 58 |
+
"pairs": [
|
| 59 |
+
{
|
| 60 |
+
"argument": "Schools should implement AI tools to support learning.",
|
| 61 |
+
"key_point": "AI can improve student engagement."
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"argument": "Governments must reduce plastic usage.",
|
| 65 |
+
"key_point": "Plastic waste harms the environment."
|
| 66 |
+
}
|
| 67 |
+
]
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
pairs: List[PredictionRequest] = Field(
|
| 73 |
+
..., max_length=100,
|
| 74 |
+
description="List of argument-keypoint pairs (max 100)"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class BatchPredictionResponse(BaseModel):
|
| 79 |
+
"""Response model for batch key-point predictions"""
|
| 80 |
+
predictions: List[PredictionResponse]
|
| 81 |
+
total_processed: int = Field(..., description="Number of processed items")
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class HealthResponse(BaseModel):
|
| 85 |
+
"""Health check model for the API"""
|
| 86 |
+
model_config = ConfigDict(
|
| 87 |
+
json_schema_extra={
|
| 88 |
+
"example": {
|
| 89 |
+
"status": "ok",
|
| 90 |
+
"model_loaded": True,
|
| 91 |
+
"device": "cuda"
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
status: str = Field(..., description="API health status")
|
| 97 |
+
model_loaded: bool = Field(..., description="Whether the model is loaded")
|
| 98 |
+
device: str = Field(..., description="Device used for inference (cpu/cuda)")
|