File size: 1,464 Bytes
40b93ed
 
 
 
 
f0760f0
40b93ed
 
 
 
32e5660
40b93ed
 
 
 
9b86f4b
 
 
 
40b93ed
9b86f4b
40b93ed
 
bb8f3e5
9b86f4b
32e5660
40b93ed
 
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
import tweepy as tw
import streamlit as st
import pandas as pd
from transformers import pipeline


auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth, wait_on_rate_limit=True)

classifier = pipeline('sentiment-analysis')
st.title('Analisis de comentarios sexistas en Twitter con Tweepy and HuggingFace Transformers')
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')

def run():
    with st.form(key='Introduzca nombre'):
        search_words = st.text_input('Introduzca el termino para analizar')
        number_of_tweets = st.number_input('Introduzca número de twweets a analizar. Máximo 50', 0,50,10)
        submit_button = st.form_submit_button(label='Submit')
        if submit_button:
            tweets =tw.Cursor(api.search_tweets,q=search_words).items(number_of_tweets)
            tweet_list = [i.text for i in tweets]
            p = [i for i in classifier(tweet_list)]
            q=[p[i]['label'] for i in range(len(p))]
            df = pd.DataFrame(list(zip(tweet_list, q)),columns =['Latest'+str(number_of_tweets)+'Tweets'+'on'+search_words, 'sentiment'])
            st.write(df)

run()