Spaces:
Sleeping
Sleeping
| 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() | |