File size: 707 Bytes
c7e5db4 050ab1a c7e5db4 |
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 |
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
# Import Logic dari Core
from .core.nlp_handler import NLPHandler
app = FastAPI()
class UserInput(BaseModel):
text: str
@app.post("/api/predict")
def predict_endpoint(input_data: UserInput):
if not input_data.text:
raise HTTPException(status_code=400, detail="No text provided")
# Panggil Logic NLP (Auto-Translate -> Predict)
result = NLPHandler.predict_all(input_data.text)
# Return format JSON
return {
"success": True,
"mbti_type": result["mbti"],
"emotion": result["emotion"],
"keywords": result["keywords"],
"reasoning": result["reasoning"]
} |