Spaces:
Build error
Build error
Commit History
-
Update app.py
Verified signaturefrom fastapi import FastAPI, HTTPException from pydantic import BaseModel from textblob import TextBlob import numpy as np from typing import List, Optional import uvicorn app = FastAPI() class SentimentRequest(BaseModel): texts: List[str] candidates: Optional[List[str]] = ["A", "B"] @app.get("/health") def health(): return {"status": "ok"} @app.post("/") async def analyze_sentiment(req: SentimentRequest): if not req.texts: raise HTTPException(status_code=400, detail="No texts provided") scores = [] for text in req.texts: try: blob = TextBlob(text) # TextBlob devuelve -1 a 1 scores.append(blob.sentiment.polarity) except: scores.append(0.0) avg_score = np.mean(scores) if scores else 0.0 pos = sum(1 for s in scores if s > 0.2) / len(scores) if scores else 0 neg = sum(1 for s in scores if s < -0.2) / len(scores) if scores else 0 neu = 1 - pos - neg sentime…93747bf -
Update app.py
Verified signaturee506238
-
Upload 4 files
Verified signaturebcf5dd0