Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import torch
|
@@ -27,21 +27,60 @@ auth = tw.OAuthHandler(consumer_key, consumer_secret)
|
|
27 |
auth.set_access_token(access_token, access_token_secret)
|
28 |
api = tw.API(auth, wait_on_rate_limit=True)
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
st.title('Analisis de comentarios sexistas en Twitter con Tweepy and HuggingFace Transformers')
|
34 |
st.markdown('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')
|
35 |
|
36 |
def run():
|
37 |
-
with st.form(key='Introduzca
|
38 |
-
search_words = st.text_input('Introduzca el termino para analizar')
|
39 |
number_of_tweets = st.number_input('Introduzca número de twweets a analizar. Máximo 50', 0,50,10)
|
40 |
-
|
|
|
|
|
41 |
if submit_button:
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
tweet_list = [i.text for i in tweets]
|
|
|
44 |
text= pd.DataFrame(tweet_list)
|
|
|
45 |
text1=text[0].values
|
46 |
indices1=tokenizer.batch_encode_plus(text1.tolist(),
|
47 |
max_length=128,
|
|
|
1 |
+
iimport tweepy as tw
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import torch
|
|
|
27 |
auth.set_access_token(access_token, access_token_secret)
|
28 |
api = tw.API(auth, wait_on_rate_limit=True)
|
29 |
|
30 |
+
def preprocess(text):
|
31 |
+
text=text.lower()
|
32 |
+
# remove hyperlinks
|
33 |
+
text = re.sub(r'https?:\/\/.*[\r\n]*', '', text)
|
34 |
+
text = re.sub(r'http?:\/\/.*[\r\n]*', '', text)
|
35 |
+
#Replace &, <, > with &,<,> respectively
|
36 |
+
text=text.replace(r'&?',r'and')
|
37 |
+
text=text.replace(r'<',r'<')
|
38 |
+
text=text.replace(r'>',r'>')
|
39 |
+
#remove hashtag sign
|
40 |
+
#text=re.sub(r"#","",text)
|
41 |
+
#remove mentions
|
42 |
+
text = re.sub(r"(?:\@)\w+", '', text)
|
43 |
+
#text=re.sub(r"@","",text)
|
44 |
+
#remove non ascii chars
|
45 |
+
text=text.encode("ascii",errors="ignore").decode()
|
46 |
+
#remove some puncts (except . ! ?)
|
47 |
+
text=re.sub(r'[:"#$%&\*+,-/:;<=>@\\^_`{|}~]+','',text)
|
48 |
+
text=re.sub(r'[!]+','!',text)
|
49 |
+
text=re.sub(r'[?]+','?',text)
|
50 |
+
text=re.sub(r'[.]+','.',text)
|
51 |
+
text=re.sub(r"'","",text)
|
52 |
+
text=re.sub(r"\(","",text)
|
53 |
+
text=re.sub(r"\)","",text)
|
54 |
+
text=" ".join(text.split())
|
55 |
+
return text
|
56 |
|
57 |
|
58 |
st.title('Analisis de comentarios sexistas en Twitter con Tweepy and HuggingFace Transformers')
|
59 |
st.markdown('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')
|
60 |
|
61 |
def run():
|
62 |
+
with st.form(key='Introduzca Texto'):
|
63 |
+
search_words = st.text_input('Introduzca el termino o usuario para analizar y pulse el check ')
|
64 |
number_of_tweets = st.number_input('Introduzca número de twweets a analizar. Máximo 50', 0,50,10)
|
65 |
+
termino=st.checkbox('Término')
|
66 |
+
usuario=st.checkbox('Usuario')
|
67 |
+
submit_button = st.form_submit_button(label='Analizar')
|
68 |
if submit_button:
|
69 |
+
date_since = "2020-09-14"
|
70 |
+
if (termino):
|
71 |
+
new_search = search_words + " -filter:retweets"
|
72 |
+
tweets =tw.Cursor(api.search_tweets,q=new_search,lang="es",since=date_since).items(number_of_tweets)
|
73 |
+
elif (usuario):
|
74 |
+
tweets = api.user_timeline(screen_name = search_words,count=number_of_tweets)
|
75 |
+
|
76 |
+
#new_search = search_words + " -filter:retweets"
|
77 |
+
#tweets = tweepy.Cursor(api.search,q=new_search,lang="es",since=date_since).items(number_of_tweets)
|
78 |
+
#tweets =tw.Cursor(api.search_tweets,q=search_words).items(number_of_tweets)
|
79 |
+
#tweets =tw.Cursor(api.search_tweets,q=new_search,lang="es",since=date_since).items(number_of_tweets)
|
80 |
tweet_list = [i.text for i in tweets]
|
81 |
+
#tweet_list = [strip_undesired_chars(i.text) for i in tweets]
|
82 |
text= pd.DataFrame(tweet_list)
|
83 |
+
text[0] = text[0].apply(preprocess)
|
84 |
text1=text[0].values
|
85 |
indices1=tokenizer.batch_encode_plus(text1.tolist(),
|
86 |
max_length=128,
|