Spaces:
Sleeping
Sleeping
Prima versione della struttura del sistema
Browse files- Dockerfile +0 -0
- app/__init__.py +0 -0
- app/api/__init__.py +0 -0
- app/api/main.py +47 -0
- app/model/__init__.py +0 -0
- requirements.txt +15 -0
Dockerfile
ADDED
|
File without changes
|
app/__init__.py
ADDED
|
File without changes
|
app/api/__init__.py
ADDED
|
File without changes
|
app/api/main.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
# 1. Inizializziamo l'app
|
| 5 |
+
app = FastAPI(
|
| 6 |
+
title="Reputation Monitor API",
|
| 7 |
+
description="API per l'analisi del sentiment della reputazione aziendale",
|
| 8 |
+
version="1.0.0"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# 2. Definiamo il "modello dei dati" in input (Data Validation)
|
| 12 |
+
# Questo serve a garantire che chi chiama l'API mandi i dati giusti
|
| 13 |
+
class SentimentRequest(BaseModel):
|
| 14 |
+
text: str
|
| 15 |
+
language: str = "it" # default italiano
|
| 16 |
+
|
| 17 |
+
class SentimentResponse(BaseModel):
|
| 18 |
+
sentiment: str
|
| 19 |
+
confidence: float
|
| 20 |
+
|
| 21 |
+
# 3. Endpoint di Health Check (fondamentale per MLOps e Docker)
|
| 22 |
+
# Serve a capire se il container è vivo
|
| 23 |
+
@app.get("/health")
|
| 24 |
+
def health_check():
|
| 25 |
+
return {"status": "ok", "message": "Service is running"}
|
| 26 |
+
|
| 27 |
+
# 4. Endpoint di Previsione (Dummy per ora)
|
| 28 |
+
@app.post("/predict", response_model=SentimentResponse)
|
| 29 |
+
def predict_sentiment(request: SentimentRequest):
|
| 30 |
+
"""
|
| 31 |
+
Riceve un testo e restituisce il sentiment (Positive, Neutral, Negative).
|
| 32 |
+
"""
|
| 33 |
+
# TODO: Qui caricheremo il modello ML vero!
|
| 34 |
+
# Per ora simuliamo una risposta logica
|
| 35 |
+
print(f"Analyzing text: {request.text}")
|
| 36 |
+
|
| 37 |
+
# Logica finta (Mock) per testare l'API
|
| 38 |
+
mock_sentiment = "neutral"
|
| 39 |
+
if "ottimo" in request.text.lower():
|
| 40 |
+
mock_sentiment = "positive"
|
| 41 |
+
elif "pessimo" in request.text.lower():
|
| 42 |
+
mock_sentiment = "negative"
|
| 43 |
+
|
| 44 |
+
return {
|
| 45 |
+
"sentiment": mock_sentiment,
|
| 46 |
+
"confidence": 0.95
|
| 47 |
+
}
|
app/model/__init__.py
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- Web API ---
|
| 2 |
+
fastapi==0.109.0
|
| 3 |
+
uvicorn[standard]==0.27.0
|
| 4 |
+
pydantic==2.6.0
|
| 5 |
+
|
| 6 |
+
# --- Machine Learning (Base) ---
|
| 7 |
+
# Per ora mettiamo scikit-learn/pandas per testare,
|
| 8 |
+
# poi aggiungeremo transformers/torch se usiamo RoBERTa
|
| 9 |
+
pandas
|
| 10 |
+
scikit-learn
|
| 11 |
+
joblib
|
| 12 |
+
|
| 13 |
+
# --- Testing ---
|
| 14 |
+
pytest
|
| 15 |
+
httpx
|