Spaces:
Sleeping
Sleeping
Initial commit: severity classifier endpoint
Browse files- main.py +51 -0
- requirements.txt +3 -0
main.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import Dict
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# Schemas
|
| 8 |
+
class IssueData(BaseModel):
|
| 9 |
+
count: int
|
| 10 |
+
severity: int
|
| 11 |
+
impact_score: int
|
| 12 |
+
|
| 13 |
+
class EmotionSummary(BaseModel):
|
| 14 |
+
positive_total: int
|
| 15 |
+
negative_total: int
|
| 16 |
+
overall_mood: str
|
| 17 |
+
|
| 18 |
+
class InputPayload(BaseModel):
|
| 19 |
+
issues: Dict[str, IssueData]
|
| 20 |
+
positive_emotions: Dict[str, int]
|
| 21 |
+
negative_emotions: Dict[str, int]
|
| 22 |
+
emotion_summary: EmotionSummary
|
| 23 |
+
|
| 24 |
+
# Logic
|
| 25 |
+
def compute_combined_score(issue: IssueData, alpha=1.0, beta=4.0):
|
| 26 |
+
return alpha * issue.impact_score + beta * issue.severity
|
| 27 |
+
|
| 28 |
+
def classify_severity(score: float) -> str:
|
| 29 |
+
if score < 20:
|
| 30 |
+
return "low"
|
| 31 |
+
elif score < 40:
|
| 32 |
+
return "medium"
|
| 33 |
+
else:
|
| 34 |
+
return "high"
|
| 35 |
+
|
| 36 |
+
@app.post("/classify-severity")
|
| 37 |
+
def classify_issues(payload: InputPayload):
|
| 38 |
+
results = {}
|
| 39 |
+
for issue_name, issue_data in payload.issues.items():
|
| 40 |
+
score = compute_combined_score(issue_data)
|
| 41 |
+
results[issue_name] = {
|
| 42 |
+
"combined_score": score,
|
| 43 |
+
"final_severity": classify_severity(score),
|
| 44 |
+
"original_count": issue_data.count,
|
| 45 |
+
"original_impact_score": issue_data.impact_score,
|
| 46 |
+
"original_severity": issue_data.severity
|
| 47 |
+
}
|
| 48 |
+
return {
|
| 49 |
+
"classified_issues": results,
|
| 50 |
+
"overall_mood": payload.emotion_summary.overall_mood
|
| 51 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
pydantic
|