Spaces:
Sleeping
Sleeping
from fastapi import FastAPI | |
from fastapi.middleware.cors import CORSMiddleware | |
from pydantic import BaseModel | |
from src.inference import predict_sentiment | |
import nltk | |
nltk.download("punkt") | |
nltk.download("punkt_tab") | |
nltk.download("stopwords") | |
app = FastAPI() | |
origins = [ | |
"https://blue-voice.vercel.app" | |
] | |
# Tambahkan middleware CORS | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=origins, | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"] | |
) | |
class SentimentRequest(BaseModel): | |
text: str | |
# Root endpoint | |
def root(): | |
return {"message": "Welcome to Blue Voice API!", "version": "1.0", "documentation": "/docs"} | |
# Predict endpoint | |
def predict(request: SentimentRequest): | |
""" | |
Endpoint to predict sentiment from the input text. | |
""" | |
result = predict_sentiment(request.text) | |
return {"status": "success", "data": result} |