| 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"] | |
| 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)) | |
| } | |
| } | |
| def root(): | |
| with open("README.md", "r") as f: | |
| return f.read() | |