Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import torch
|
|
| 5 |
import numpy as np
|
| 6 |
import re
|
| 7 |
|
|
|
|
| 8 |
from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
|
| 9 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification,AdamW
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/twitter_sexismo-finetuned-exist2021-metwo')
|
|
@@ -53,18 +54,46 @@ def preprocess(text):
|
|
| 53 |
text=re.sub(r"\)","",text)
|
| 54 |
text=" ".join(text.split())
|
| 55 |
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
st.set_page_config(layout="wide")
|
| 58 |
-
st.
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
def run():
|
| 64 |
with st.form(key='Introduzca Texto'):
|
| 65 |
col,buff1, buff2 = st.columns([2,2,1])
|
| 66 |
#col.text_input('smaller text window:')
|
| 67 |
-
search_words = col.text_input(
|
| 68 |
number_of_tweets = col.number_input('Introduzca número de twweets a analizar. Máximo 50', 0,50,10)
|
| 69 |
termino=st.checkbox('Término')
|
| 70 |
usuario=st.checkbox('Usuario')
|
|
@@ -129,8 +158,14 @@ def run():
|
|
| 129 |
predictions.append(logits1)
|
| 130 |
flat_predictions = [item for sublist in predictions for item in sublist]
|
| 131 |
flat_predictions = np.argmax(flat_predictions, axis=1).flatten()#p = [i for i in classifier(tweet_list)]
|
| 132 |
-
df = pd.DataFrame(list(zip(tweet_list, flat_predictions)),columns =['
|
| 133 |
df['Sexista']= np.where(df['Sexista']== 0, 'No Sexista', 'Sexista')
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
#st.write(df)
|
| 136 |
run()
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import re
|
| 7 |
|
| 8 |
+
|
| 9 |
from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
|
| 10 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification,AdamW
|
| 11 |
tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/twitter_sexismo-finetuned-exist2021-metwo')
|
|
|
|
| 54 |
text=re.sub(r"\)","",text)
|
| 55 |
text=" ".join(text.split())
|
| 56 |
return text
|
| 57 |
+
|
| 58 |
+
def highlight_survived(s):
|
| 59 |
+
return ['background-color: red']*len(s) if (s.Sexista == 1) else ['background-color: green']*len(s)
|
| 60 |
+
|
| 61 |
+
def color_survived(val):
|
| 62 |
+
color = 'red' if val=='Sexista' else 'white'
|
| 63 |
+
return f'background-color: {color}'
|
| 64 |
|
| 65 |
st.set_page_config(layout="wide")
|
| 66 |
+
st.markdown('<style>body{background-color: Blue;}</style>',unsafe_allow_html=True)
|
| 67 |
+
|
| 68 |
+
#background-color: Blue;
|
| 69 |
+
|
| 70 |
+
colT1,colT2 = st.columns([2,8])
|
| 71 |
+
with colT2:
|
| 72 |
+
#st.title('Analisis de comentarios sexistas en Twitter')
|
| 73 |
+
st.markdown(""" <style> .font {
|
| 74 |
+
font-size:40px ; font-family: 'Cooper Black'; color: #FF9633;}
|
| 75 |
+
</style> """, unsafe_allow_html=True)
|
| 76 |
+
st.markdown('<p class="font">Análisis de comentarios sexistas en Twitter</p>', unsafe_allow_html=True)
|
| 77 |
+
|
| 78 |
+
st.markdown(""" <style> .font1 {
|
| 79 |
+
font-size:28px ; font-family: 'Times New Roman'; color: #8d33ff;}
|
| 80 |
+
</style> """, unsafe_allow_html=True)
|
| 81 |
+
st.markdown('<p class="font1">Objetivo 5 de los ODS. Lograr la igualdad entre los géneros y empoderar a todas las mujeres y las niñas</p>', unsafe_allow_html=True)
|
| 82 |
+
#st.header('Objetivo 5 de los ODS, Lograr la igualdad entre los géneros y empoderar a todas las mujeres y las niñas')
|
| 83 |
+
with colT1:
|
| 84 |
+
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Sustainable_Development_Goal-es-13.jpg/1200px-Sustainable_Development_Goal-es-13.jpg",width=200)
|
| 85 |
+
|
| 86 |
+
st.markdown(""" <style> .font2 {
|
| 87 |
+
font-size:16px ; font-family: 'Times New Roman'; color: #3358ff;}
|
| 88 |
+
</style> """, unsafe_allow_html=True)
|
| 89 |
+
st.markdown('<p class="font2">Esta app utiliza tweepy para descargar tweets de twitter en base a la información de entrada y procesa los tweets usando transformers de HuggingFace para detectar comentarios sexistas. El resultado y los tweets correspondientes se almacenan en un dataframe para mostrarlo que es lo que se ve como resultado.La finalidad del proyecto, es en línea con el Objetivo 5 de los ODS, eliminar todas las formas de violencia contra todas las mujeres y las niñas en los ámbitos público y privado, incluidas la trata y la explotación sexual y otros tipos de explotación. Los comentarios sexistas son una forma de violencia contra la mujer con está aplicación puede ayudar a hacer un estudio sistemático de la misma.</p>',unsafe_allow_html=True)
|
| 90 |
|
| 91 |
|
| 92 |
def run():
|
| 93 |
with st.form(key='Introduzca Texto'):
|
| 94 |
col,buff1, buff2 = st.columns([2,2,1])
|
| 95 |
#col.text_input('smaller text window:')
|
| 96 |
+
search_words = col.text_input("Introduzca el termino o usuario para analizar y pulse el check correspondiente")
|
| 97 |
number_of_tweets = col.number_input('Introduzca número de twweets a analizar. Máximo 50', 0,50,10)
|
| 98 |
termino=st.checkbox('Término')
|
| 99 |
usuario=st.checkbox('Usuario')
|
|
|
|
| 158 |
predictions.append(logits1)
|
| 159 |
flat_predictions = [item for sublist in predictions for item in sublist]
|
| 160 |
flat_predictions = np.argmax(flat_predictions, axis=1).flatten()#p = [i for i in classifier(tweet_list)]
|
| 161 |
+
df = pd.DataFrame(list(zip(tweet_list, flat_predictions)),columns =['Últimos '+ str(number_of_tweets)+' Tweets'+' de '+search_words, 'Sexista'])
|
| 162 |
df['Sexista']= np.where(df['Sexista']== 0, 'No Sexista', 'Sexista')
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
st.table(df.reset_index(drop=True).head(20).style.applymap(color_survived, subset=['Sexista']))
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
#st.dataframe(df.style.apply(highlight_survived, axis=1))
|
| 169 |
+
#st.table(df)
|
| 170 |
#st.write(df)
|
| 171 |
run()
|