File size: 2,451 Bytes
d2cbb70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import gradio as gr
from transformers import pipeline

# Cargar pipelines predefinidos
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
sentiment_analyzer = pipeline("sentiment-analysis")
response_generator = pipeline("text2text-generation", model="google/flan-t5-large")

# Categorías de reclamos
categories = [
    "Accidentes de coche",
    "Hogar",
    "Salud",
    "Vida",
    "Viajes",
    "Responsabilidad civil",
]

def analyze_claim(claim_text):
    # Resumen del reclamo
    summary = summarizer(claim_text, max_length=50, min_length=20, do_sample=False)[0]["summary_text"]

    # Clasificación del reclamo
    classification = classifier(claim_text, candidate_labels=categories)
    top_category = classification["labels"][0]

    # Análisis de sentimiento
    sentiment = sentiment_analyzer(claim_text)[0]

    # Respuesta sugerida generada por LLM
    response_prompt = (
        f"Genera una respuesta para un cliente que tiene un reclamo relacionado con {top_category}."
        f" El sentimiento del cliente es {sentiment['label']} con un nivel de confianza de {sentiment['score']:.2f}."
    )
    response = response_generator(response_prompt, max_length=50)[0]["generated_text"]

    return summary, top_category, sentiment["label"], sentiment["score"], response

# Interfaz de Gradio
with gr.Blocks() as demo:
    gr.Markdown("#Company ClaimSense")
    gr.Markdown(
        "Esta herramienta analiza reclamos de seguros y proporciona un resumen, categoría, análisis de sentimiento y una respuesta sugerida."
    )

    with gr.Row():
        claim_input = gr.Textbox(
            label="Descripción del Reclamo", placeholder="Describe tu reclamo en detalle..."
        )
        analyze_button = gr.Button("Analizar Reclamo")

    with gr.Row():
        summary_output = gr.Textbox(label="Resumen del Reclamo")
        category_output = gr.Textbox(label="Categoría Identificada")

    with gr.Row():
        sentiment_output = gr.Textbox(label="Sentimiento Detectado")
        score_output = gr.Number(label="Confianza del Sentimiento")

    response_output = gr.Textbox(label="Respuesta Sugerida")

    analyze_button.click(
        analyze_claim,
        inputs=[claim_input],
        outputs=[summary_output, category_output, sentiment_output, score_output, response_output],
    )

# Lanzar el Space
demo.launch()