Sentiment / app.py
abeerrai01
INTIAL
fc5d042
raw
history blame contribute delete
870 Bytes
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from suicidality_model import predict_suicidality
from translator import to_english
app = FastAPI(title="๐ŸŒพ Farmer Mental Health AI")
# โœ… Define a request model
class TextInput(BaseModel):
text: str
@app.get("/")
def home():
return {"message": "Farmer Mental Health AI is up and running ๐Ÿš€"}
# โœ… Accept JSON body input
@app.post("/analyze/")
def analyze_text(data: TextInput):
text = data.text
text_en = to_english(text)
result = predict_suicidality(text_en)
return {
"original_text": text,
"translated_to_english": text_en,
"label": result["label"],
"confidence": result["confidence"],
"sentiment": result["sentiment"]
}
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=9000, reload=True)