Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tweepy as tw
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
consumer_key = '9jIZw6aJxenAhwrbfiymcP1FL'
|
7 |
+
consumer_secret = 'PtwmIIHckaGIe4XyJsen1Oy9qCPbhce66UdWIlrnKVEMfLwKg5'
|
8 |
+
access_token = '975820852901097473-sv2EVjyrOR0TwNmnv8gyyHXu30XzJC7'
|
9 |
+
access_token_secret = 'K8bGe0Neqil5BcHMjJdE1vBecYFTvXa3AHvLZoLNQ8WBO'
|
10 |
+
auth = tw.OAuthHandler(consumer_key, consumer_secret)
|
11 |
+
auth.set_access_token(access_token, access_token_secret)
|
12 |
+
api = tw.API(auth, wait_on_rate_limit=True)
|
13 |
+
|
14 |
+
st.title('Analisis de comentarios sexistas en Twitter con Tweepy and HuggingFace Transformers')
|
15 |
+
st.markdown('Esta app utiliza tweepy para descargar get tweets de twitter en base a la información de de entrada y procesa los tweets usando transformers de HuggingFace para detectar comentarios sexsitas. El resultado y los tweets correspondientes se almacenan en un dataframe para mostrarlo que es lo que se ve como resultado')
|
16 |
+
|
17 |
+
def run():
|
18 |
+
with st.form(key=’Enter name’):
|
19 |
+
search_words = st.text_input(‘Enter the name for which you want to know the sentiment’)
|
20 |
+
number_of_tweets = st.number_input(‘Enter the number of latest tweets for which you want to know the sentiment(Maximum 50 tweets)’, 0,50,10)
|
21 |
+
submit_button = st.form_submit_button(label=’Submit’)
|
22 |
+
if submit_button:
|
23 |
+
tweets =tw.Cursor(api.search_tweets,q=search_words,lang=”en”).items(number_of_tweets)
|
24 |
+
tweet_list = [i.text for i in tweets]
|
25 |
+
p = [i for i in classifier(tweet_list)]
|
26 |
+
q=[p[i][‘label’] for i in range(len(p))]
|
27 |
+
df = pd.DataFrame(list(zip(tweet_list, q)),columns =[‘Latest ‘+str(number_of_tweets)+’ Tweets’+’ on ‘+search_words, ‘sentiment’])
|
28 |
+
st.write(df)
|
29 |
+
|
30 |
+
if __name__==’__main__’:
|
31 |
+
run()
|