File size: 3,549 Bytes
7823eb7
6d8e32f
6a243b1
82c37b3
6d8e32f
7823eb7
82c37b3
6d8e32f
 
 
 
 
 
 
 
 
 
 
 
98ec384
82c37b3
7823eb7
4d9f7f2
 
82c37b3
4d9f7f2
 
b7739ef
6d8e32f
b7739ef
 
6d8e32f
 
82c37b3
4d9f7f2
b7739ef
82c37b3
6d8e32f
82c37b3
 
6d8e32f
 
 
 
82c37b3
4d9f7f2
82c37b3
6d8e32f
82c37b3
 
 
6d8e32f
 
 
82c37b3
4d9f7f2
b7739ef
6d8e32f
 
 
 
 
 
 
 
4d9f7f2
b7739ef
6d8e32f
 
 
 
 
 
 
 
4d9f7f2
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
72
73
74
75
76
77
import streamlit as st
from transformers import pipeline, RobertaTokenizerFast, TFRobertaForSequenceClassification, AutoTokenizer, AutoModelForSequenceClassification

# Sentiment Analysis Pipeline
sentiment_pipe = pipeline('sentiment-analysis')

# Toxicity Classifier
model_path_toxic = "citizenlab/distilbert-base-multilingual-cased-toxicity"
toxicity_classifier = pipeline("text-classification", model=model_path_toxic, tokenizer=model_path_toxic)

# Emotion Analysis
tokenizer_emotion = RobertaTokenizerFast.from_pretrained("arpanghoshal/EmoRoBERTa")
model_emotion = TFRobertaForSequenceClassification.from_pretrained("arpanghoshal/EmoRoBERTa")
emotion = pipeline('sentiment-analysis', model=model_emotion, tokenizer=tokenizer_emotion)

# User Needs Analysis
tokenizer_needs = AutoTokenizer.from_pretrained("thusken/nb-bert-base-user-needs")
model_needs = AutoModelForSequenceClassification.from_pretrained("thusken/nb-bert-base-user-needs")
user_needs = pipeline('text-classification', model=model_needs, tokenizer=tokenizer_needs)

st.title("Plataforma de Diálogos Participativos")

# Text area for input in sidebar
text = st.sidebar.text_area("Añade el texto a evaluar")

# Create columns for buttons in sidebar
col1, col2, col3, col4 = st.sidebar.columns(4)

# Place each button in a separate column
run_sentiment_analysis = col1.button("Evaluar Sentimiento")
run_toxicity_analysis = col2.button("Evaluar Toxicidad")
run_emotion_analysis = col3.button("Evaluar Emoción")
run_user_needs_analysis = col4.button("Evaluar Necesidades del Usuario")

# Container for output in main layout
output_container = st.container()

# Sentiment analysis
if run_sentiment_analysis and text:
    with output_container:
        sentiment_output = sentiment_pipe(text)
        label = sentiment_output[0]['label']
        score = round(sentiment_output[0]['score'] * 100, 2)
        st.markdown(f"**Resultado del análisis de sentimiento:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
elif run_sentiment_analysis and not text:
    st.sidebar.warning("Por favor, añade un texto para evaluar el sentimiento.")

# Toxicity analysis
if run_toxicity_analysis and text:
    with output_container:
        toxicity_output = toxicity_classifier(text)
        label = toxicity_output[0]['label']
        score = round(toxicity_output[0]['score'] * 100, 2)
        st.markdown(f"**Resultado del análisis de toxicidad:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
elif run_toxicity_analysis and not text:
    st.sidebar.warning("Por favor, añade un texto para evaluar la toxicidad.")

# Emotion analysis
if run_emotion_analysis and text:
    with output_container:
        emotion_output = emotion(text)
        label = emotion_output[0]['label']
        score = round(emotion_output[0]['score'] * 100, 2)
        st.markdown(f"**Resultado del análisis de emoción:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
elif run_emotion_analysis and not text:
    st.sidebar.warning("Por favor, añade un texto para evaluar la emoción.")

# User needs analysis
if run_user_needs_analysis and text:
    with output_container:
        needs_output = user_needs(text)
        label = needs_output[0]['label']
        score = round(needs_output[0]['score'] * 100, 2)
        st.markdown(f"**Resultado del análisis de necesidades del usuario:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
elif run_user_needs_analysis and not text:
    st.sidebar.warning("Por favor, añade un texto para evaluar las necesidades del usuario.")