File size: 1,485 Bytes
60d1809
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import gradio as gr

classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment")

def sentiment_analysis(message, history):
    """
    Funci贸n para analizar el sentimiento de un mensaje.
    Retorna la etiqueta de sentimiento con su probabilidad.
    """
    result = classifier(message)
    return f"Sentimiento : {result[0]['label']} (Probabilidad: {result[0]['score']:.2f})"

def create_sentiment_tab():
    with gr.Blocks() as sentiment_app:
        gr.Markdown("""
        # An谩lisis de Sentimientos
        Esta aplicaci贸n utiliza un modelo de Machine Learning para analizar el sentimiento de los mensajes ingresados. 
        Puede detectar si un texto es positivo, negativo o neutral con su respectiva probabilidad.
        """)
        
        chat = gr.ChatInterface(sentiment_analysis, type="messages")
        
        gr.Markdown("""
        ---
        ### Con茅ctate conmigo:
        [Instagram 馃摳](https://www.instagram.com/srjosueaaron/)
        
        [TikTok 馃幍](https://www.tiktok.com/@srjosueaaron)
        
        [YouTube 馃幀](https://www.youtube.com/@srjosueaaron)

        ---
        Demostraci贸n de An谩lisis de Sentimientos usando el modelo de [CardiffNLP](https://huggingface.co/cardiffnlp/twitter-xlm-roberta-base-sentiment).
        
        Desarrollado con 鉂わ笍 por [@srjosueaaron](https://www.instagram.com/srjosueaaron/).
        """)

    return sentiment_app