Spaces:
Running
Running
Create sentiment.py
Browse files- sentiment.py +39 -0
sentiment.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment")
|
5 |
+
|
6 |
+
def sentiment_analysis(message, history):
|
7 |
+
"""
|
8 |
+
Funci贸n para analizar el sentimiento de un mensaje.
|
9 |
+
Retorna la etiqueta de sentimiento con su probabilidad.
|
10 |
+
"""
|
11 |
+
result = classifier(message)
|
12 |
+
return f"Sentimiento : {result[0]['label']} (Probabilidad: {result[0]['score']:.2f})"
|
13 |
+
|
14 |
+
def create_sentiment_tab():
|
15 |
+
with gr.Blocks() as sentiment_app:
|
16 |
+
gr.Markdown("""
|
17 |
+
# An谩lisis de Sentimientos
|
18 |
+
Esta aplicaci贸n utiliza un modelo de Machine Learning para analizar el sentimiento de los mensajes ingresados.
|
19 |
+
Puede detectar si un texto es positivo, negativo o neutral con su respectiva probabilidad.
|
20 |
+
""")
|
21 |
+
|
22 |
+
chat = gr.ChatInterface(sentiment_analysis, type="messages")
|
23 |
+
|
24 |
+
gr.Markdown("""
|
25 |
+
---
|
26 |
+
### Con茅ctate conmigo:
|
27 |
+
[Instagram 馃摳](https://www.instagram.com/srjosueaaron/)
|
28 |
+
|
29 |
+
[TikTok 馃幍](https://www.tiktok.com/@srjosueaaron)
|
30 |
+
|
31 |
+
[YouTube 馃幀](https://www.youtube.com/@srjosueaaron)
|
32 |
+
|
33 |
+
---
|
34 |
+
Demostraci贸n de An谩lisis de Sentimientos usando el modelo de [CardiffNLP](https://huggingface.co/cardiffnlp/twitter-xlm-roberta-base-sentiment).
|
35 |
+
|
36 |
+
Desarrollado con 鉂わ笍 por [@srjosueaaron](https://www.instagram.com/srjosueaaron/).
|
37 |
+
""")
|
38 |
+
|
39 |
+
return sentiment_app
|