Spaces:
Sleeping
Sleeping
| 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 | |
| def home(): | |
| return {"message": "Farmer Mental Health AI is up and running ๐"} | |
| # โ Accept JSON body input | |
| 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) |