Joshua1808 commited on
Commit
4518611
·
1 Parent(s): cf4d177

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -206,8 +206,11 @@ def tweets_localidad(buscar_localidad):
206
  location = geolocator.geocode(buscar_localidad)
207
  radius = "100km"
208
  tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 50)
209
- #for tweet in tweets:
210
- # print(tweet.text)
 
 
 
211
  tweet_list = [i.text for i in tweets]
212
  text= pd.DataFrame(tweet_list)
213
  text[0] = text[0].apply(preprocess_tweet)
@@ -250,7 +253,7 @@ def tweets_localidad(buscar_localidad):
250
 
251
  probability = np.amax(logits1,axis=1).flatten()
252
  Tweets =['Últimos 50 Tweets'+' de '+ buscar_localidad]
253
- df = pd.DataFrame(list(zip(text1, flat_predictions,probability)), columns = ['Tweets' , 'Prediccion','Probabilidad'])
254
 
255
  df['Prediccion']= np.where(df['Prediccion']== 0, 'No Sexista', 'Sexista')
256
  #df['Tweets'] = df['Tweets'].str.replace('RT|@', '')
@@ -258,7 +261,20 @@ def tweets_localidad(buscar_localidad):
258
  #df['Tweets'] = df['Tweets'].apply(lambda x: re.sub(r'[:;][-o^]?[)\]DpP3]|[(/\\]|[\U0001f600-\U0001f64f]|[\U0001f300-\U0001f5ff]|[\U0001f680-\U0001f6ff]|[\U0001f1e0-\U0001f1ff]','', x))
259
 
260
  tabla = st.table(df.reset_index(drop=True).head(50).style.applymap(color_survived, subset=['Prediccion']))
 
 
 
 
 
261
 
 
 
 
 
 
 
 
 
262
 
263
  return df
264
 
 
206
  location = geolocator.geocode(buscar_localidad)
207
  radius = "100km"
208
  tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 50)
209
+ localidad = [i.user.location for i in tweets]
210
+ text_localidad = pd.DataFrame(localidad)
211
+ username = [i.user.screen_name for i in tweets]
212
+ text_user= pd.DataFrame(username)
213
+
214
  tweet_list = [i.text for i in tweets]
215
  text= pd.DataFrame(tweet_list)
216
  text[0] = text[0].apply(preprocess_tweet)
 
253
 
254
  probability = np.amax(logits1,axis=1).flatten()
255
  Tweets =['Últimos 50 Tweets'+' de '+ buscar_localidad]
256
+ df = pd.DataFrame(list(zip(text1, localidad,username, flat_predictions,probability)), columns = ['Tweets' ,'Localidad' , 'Usuario','Prediccion','Probabilidad'])
257
 
258
  df['Prediccion']= np.where(df['Prediccion']== 0, 'No Sexista', 'Sexista')
259
  #df['Tweets'] = df['Tweets'].str.replace('RT|@', '')
 
261
  #df['Tweets'] = df['Tweets'].apply(lambda x: re.sub(r'[:;][-o^]?[)\]DpP3]|[(/\\]|[\U0001f600-\U0001f64f]|[\U0001f300-\U0001f5ff]|[\U0001f680-\U0001f6ff]|[\U0001f1e0-\U0001f1ff]','', x))
262
 
263
  tabla = st.table(df.reset_index(drop=True).head(50).style.applymap(color_survived, subset=['Prediccion']))
264
+
265
+ df_sexista = df[df['Prediccion']=="Sexista"]
266
+ df_no_sexista = df[df['Probabilidad'] > 0]
267
+ sexista = len(df_sexista)
268
+ no_sexista = len(df_no_sexista)
269
 
270
+ # Crear un gráfico de barras
271
+ labels = ['Sexista ', ' No sexista']
272
+ counts = [sexista, no_sexista]
273
+ plt.bar(labels, counts)
274
+ plt.xlabel('Categoría')
275
+ plt.ylabel('Cantidad de tweets')
276
+ plt.title('Cantidad de tweets sexistas y no sexistas')
277
+ plt.show()
278
 
279
  return df
280