Spaces:
Build error
Build error
Commit
·
608a73e
1
Parent(s):
87d4d83
update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,77 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
# Using object notation
|
| 4 |
-
add_selectbox = st.sidebar.selectbox(
|
| 5 |
-
"How would you like to be contacted?",
|
| 6 |
-
("Email", "Home phone", "Mobile phone")
|
| 7 |
-
)
|
| 8 |
-
|
| 9 |
-
# Using "with" notation
|
| 10 |
-
with st.sidebar:
|
| 11 |
-
add_radio = st.radio(
|
| 12 |
-
"Choose a shipping method",
|
| 13 |
-
("Standard (5-15 days)", "Express (2-5 days)")
|
| 14 |
-
)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline, RobertaTokenizerFast, TFRobertaForSequenceClassification, AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
|
| 4 |
+
# Sentiment Analysis Pipeline
|
| 5 |
+
sentiment_pipe = pipeline('sentiment-analysis')
|
| 6 |
+
|
| 7 |
+
# Toxicity Classifier
|
| 8 |
+
model_path_toxic = "citizenlab/distilbert-base-multilingual-cased-toxicity"
|
| 9 |
+
toxicity_classifier = pipeline("text-classification", model=model_path_toxic, tokenizer=model_path_toxic)
|
| 10 |
+
|
| 11 |
+
# Emotion Analysis
|
| 12 |
+
tokenizer_emotion = RobertaTokenizerFast.from_pretrained("arpanghoshal/EmoRoBERTa")
|
| 13 |
+
model_emotion = TFRobertaForSequenceClassification.from_pretrained("arpanghoshal/EmoRoBERTa")
|
| 14 |
+
emotion = pipeline('sentiment-analysis', model=model_emotion, tokenizer=tokenizer_emotion)
|
| 15 |
+
|
| 16 |
+
# User Needs Analysis
|
| 17 |
+
tokenizer_needs = AutoTokenizer.from_pretrained("thusken/nb-bert-base-user-needs")
|
| 18 |
+
model_needs = AutoModelForSequenceClassification.from_pretrained("thusken/nb-bert-base-user-needs")
|
| 19 |
+
user_needs = pipeline('text-classification', model=model_needs, tokenizer=tokenizer_needs)
|
| 20 |
+
|
| 21 |
+
st.title("Plataforma de Diálogos Participativos")
|
| 22 |
+
|
| 23 |
+
# Text area for input in sidebar
|
| 24 |
+
text = st.sidebar.text_area("Añade el texto a evaluar")
|
| 25 |
+
|
| 26 |
+
# Create columns for buttons in sidebar
|
| 27 |
+
col1, col2, col3, col4 = st.sidebar.columns(4)
|
| 28 |
+
|
| 29 |
+
# Place each button in a separate column
|
| 30 |
+
run_sentiment_analysis = col1.button("Evaluar Sentimiento")
|
| 31 |
+
run_toxicity_analysis = col2.button("Evaluar Toxicidad")
|
| 32 |
+
run_emotion_analysis = col3.button("Evaluar Emoción")
|
| 33 |
+
run_user_needs_analysis = col4.button("Evaluar Necesidades del Usuario")
|
| 34 |
+
|
| 35 |
+
# Container for output in main layout
|
| 36 |
+
output_container = st.container()
|
| 37 |
+
|
| 38 |
+
# Sentiment analysis
|
| 39 |
+
if run_sentiment_analysis and text:
|
| 40 |
+
with output_container:
|
| 41 |
+
sentiment_output = sentiment_pipe(text)
|
| 42 |
+
label = sentiment_output[0]['label']
|
| 43 |
+
score = round(sentiment_output[0]['score'] * 100, 2)
|
| 44 |
+
st.markdown(f"**Resultado del análisis de sentimiento:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
|
| 45 |
+
elif run_sentiment_analysis and not text:
|
| 46 |
+
st.sidebar.warning("Por favor, añade un texto para evaluar el sentimiento.")
|
| 47 |
+
|
| 48 |
+
# Toxicity analysis
|
| 49 |
+
if run_toxicity_analysis and text:
|
| 50 |
+
with output_container:
|
| 51 |
+
toxicity_output = toxicity_classifier(text)
|
| 52 |
+
label = toxicity_output[0]['label']
|
| 53 |
+
score = round(toxicity_output[0]['score'] * 100, 2)
|
| 54 |
+
st.markdown(f"**Resultado del análisis de toxicidad:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
|
| 55 |
+
elif run_toxicity_analysis and not text:
|
| 56 |
+
st.sidebar.warning("Por favor, añade un texto para evaluar la toxicidad.")
|
| 57 |
+
|
| 58 |
+
# Emotion analysis
|
| 59 |
+
if run_emotion_analysis and text:
|
| 60 |
+
with output_container:
|
| 61 |
+
emotion_output = emotion(text)
|
| 62 |
+
label = emotion_output[0]['label']
|
| 63 |
+
score = round(emotion_output[0]['score'] * 100, 2)
|
| 64 |
+
st.markdown(f"**Resultado del análisis de emoción:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
|
| 65 |
+
elif run_emotion_analysis and not text:
|
| 66 |
+
st.sidebar.warning("Por favor, añade un texto para evaluar la emoción.")
|
| 67 |
+
|
| 68 |
+
# User needs analysis
|
| 69 |
+
if run_user_needs_analysis and text:
|
| 70 |
+
with output_container:
|
| 71 |
+
needs_output = user_needs(text)
|
| 72 |
+
label = needs_output[0]['label']
|
| 73 |
+
score = round(needs_output[0]['score'] * 100, 2)
|
| 74 |
+
st.markdown(f"**Resultado del análisis de necesidades del usuario:**\n\n- **Etiqueta:** {label}\n- **Confianza:** {score}%")
|
| 75 |
+
elif run_user_needs_analysis and not text:
|
| 76 |
+
st.sidebar.warning("Por favor, añade un texto para evaluar las necesidades del usuario.")
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|