Spaces:
Runtime error
Runtime error
import tweepy as tw | |
import streamlit as st | |
import pandas as pd | |
from transformers import pipeline | |
consumer_key = '9jIZw6aJxenAhwrbfiymcP1FL' | |
consumer_secret = 'PtwmIIHckaGIe4XyJsen1Oy9qCPbhce66UdWIlrnKVEMfLwKg5' | |
access_token = '975820852901097473-sv2EVjyrOR0TwNmnv8gyyHXu30XzJC7' | |
access_token_secret = 'K8bGe0Neqil5BcHMjJdE1vBecYFTvXa3AHvLZoLNQ8WBO' | |
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() |