Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Cargar pipelines predefinidos
|
5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
6 |
+
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
7 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
8 |
+
response_generator = pipeline("text2text-generation", model="google/flan-t5-large")
|
9 |
+
|
10 |
+
# Categor铆as de reclamos
|
11 |
+
categories = [
|
12 |
+
"Accidentes de coche",
|
13 |
+
"Hogar",
|
14 |
+
"Salud",
|
15 |
+
"Vida",
|
16 |
+
"Viajes",
|
17 |
+
"Responsabilidad civil",
|
18 |
+
]
|
19 |
+
|
20 |
+
def analyze_claim(claim_text):
|
21 |
+
# Resumen del reclamo
|
22 |
+
summary = summarizer(claim_text, max_length=50, min_length=20, do_sample=False)[0]["summary_text"]
|
23 |
+
|
24 |
+
# Clasificaci贸n del reclamo
|
25 |
+
classification = classifier(claim_text, candidate_labels=categories)
|
26 |
+
top_category = classification["labels"][0]
|
27 |
+
|
28 |
+
# An谩lisis de sentimiento
|
29 |
+
sentiment = sentiment_analyzer(claim_text)[0]
|
30 |
+
|
31 |
+
# Respuesta sugerida generada por LLM
|
32 |
+
response_prompt = (
|
33 |
+
f"Genera una respuesta para un cliente que tiene un reclamo relacionado con {top_category}."
|
34 |
+
f" El sentimiento del cliente es {sentiment['label']} con un nivel de confianza de {sentiment['score']:.2f}."
|
35 |
+
)
|
36 |
+
response = response_generator(response_prompt, max_length=50)[0]["generated_text"]
|
37 |
+
|
38 |
+
return summary, top_category, sentiment["label"], sentiment["score"], response
|
39 |
+
|
40 |
+
# Interfaz de Gradio
|
41 |
+
with gr.Blocks() as demo:
|
42 |
+
gr.Markdown("#Company ClaimSense")
|
43 |
+
gr.Markdown(
|
44 |
+
"Esta herramienta analiza reclamos de seguros y proporciona un resumen, categor铆a, an谩lisis de sentimiento y una respuesta sugerida."
|
45 |
+
)
|
46 |
+
|
47 |
+
with gr.Row():
|
48 |
+
claim_input = gr.Textbox(
|
49 |
+
label="Descripci贸n del Reclamo", placeholder="Describe tu reclamo en detalle..."
|
50 |
+
)
|
51 |
+
analyze_button = gr.Button("Analizar Reclamo")
|
52 |
+
|
53 |
+
with gr.Row():
|
54 |
+
summary_output = gr.Textbox(label="Resumen del Reclamo")
|
55 |
+
category_output = gr.Textbox(label="Categor铆a Identificada")
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
sentiment_output = gr.Textbox(label="Sentimiento Detectado")
|
59 |
+
score_output = gr.Number(label="Confianza del Sentimiento")
|
60 |
+
|
61 |
+
response_output = gr.Textbox(label="Respuesta Sugerida")
|
62 |
+
|
63 |
+
analyze_button.click(
|
64 |
+
analyze_claim,
|
65 |
+
inputs=[claim_input],
|
66 |
+
outputs=[summary_output, category_output, sentiment_output, score_output, response_output],
|
67 |
+
)
|
68 |
+
|
69 |
+
# Lanzar el Space
|
70 |
+
demo.launch()
|