File size: 834 Bytes
7b41c88
 
 
 
 
 
 
 
 
 
 
 
9d7cbf3
7b41c88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from pydantic import BaseModel
from classifier.Bug_Priority import get_model
from fastapi.responses import PlainTextResponse

app = FastAPI()
model = get_model()

# Request body schema
class Issue(BaseModel):
    text: str

PRIORITY_LABELS = ["Blocker", "Critical", "Major", "Minor"]

@app.post("/predict")
async def predict(issue: Issue):
    probs, predicted_label = model.predict(issue.text)
    return {
        "input_text": issue.text,
        "predicted_label": predicted_label,
        "label_index": PRIORITY_LABELS.index(predicted_label),
        "confidence_scores": {
            PRIORITY_LABELS[i]: f"{probs[i]:.4f}" for i in range(len(PRIORITY_LABELS))
        }
    }

@app.get("/", response_class=PlainTextResponse)
def root():
    with open("README.md", "r") as f:
        return f.read()