shivamjadhav's picture
created Bug Priority model and hugging face deployment read project
9d7cbf3
raw
history blame contribute delete
834 Bytes
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()