api-blue-voice / app.py
agusswardanaa's picture
add nltk stopwords
d66986d verified
raw
history blame contribute delete
925 Bytes
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
@app.get("/")
def root():
return {"message": "Welcome to Blue Voice API!", "version": "1.0", "documentation": "/docs"}
# Predict endpoint
@app.post("/predict")
def predict(request: SentimentRequest):
"""
Endpoint to predict sentiment from the input text.
"""
result = predict_sentiment(request.text)
return {"status": "success", "data": result}