File size: 870 Bytes
fc5d042
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
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)