Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, Request | |
| from transformers import pipeline | |
| app = FastAPI() | |
| # Usiamo un modello DISTILLATO (molto leggero per CPU Free) | |
| classifier = pipeline("zero-shot-classification", model="typeform/distilbert-base-uncased-mnli") | |
| def home(): | |
| return {"status": "SICURISSIMO AI V170 ONLINE"} | |
| async def analyze(request: Request): | |
| try: | |
| data = await request.json() | |
| testo = data.get("text", "") | |
| cliente = data.get("client_name", "Anonimo") | |
| # Etichette semplificate per stabilità | |
| labels = ["pericolo sicurezza", "haccp igiene", "scadenza documenti", "formazione"] | |
| # Analisi | |
| res = classifier(testo, labels) | |
| top_label = res['labels'][0] | |
| score = res['scores'][0] | |
| # Calcolo Lead Score (0-100) | |
| lead_heat = int(score * 100) | |
| if top_label == "pericolo sicurezza": | |
| lead_heat = min(lead_heat + 20, 100) | |
| return { | |
| "cliente": cliente, | |
| "analisi_top": top_label, | |
| "punteggio": round(score, 2), | |
| "intervento_necessario": True if score > 0.6 else False, | |
| "lead_score": lead_heat | |
| } | |
| except Exception as e: | |
| return {"error": str(e)} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |