Joshua1808 commited on
Commit
d0e7d06
·
1 Parent(s): 2f14689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -37
app.py CHANGED
@@ -82,47 +82,52 @@ with colT2:
82
 
83
  def analizar_tweets(search_words, number_of_tweets):
84
  tabla = []
85
- if(number_of_tweets > 0 || search_words == "" ):
86
- tweets = api.user_timeline(screen_name = search_words,tweet_mode="extended", count= number_of_tweets)
87
- result = []
88
-
89
- for tweet in tweets:
90
- if (tweet.full_text.startswith('RT')):
91
- continue
92
- elif not tweet.full_text.strip():
93
- continue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  else:
95
- datos = preprocess(tweet.full_text)
96
- prediction = pipeline_nlp(datos)
97
- for predic in prediction:
98
- etiqueta = {'Tweets': datos,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
99
- result.append(etiqueta)
100
- df = pd.DataFrame(result)
101
- if df.empty:
102
- df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
103
- df = df[df["Prediccion"] == 'Sexista']
104
- df = df[df["Probabilidad"] > 0.5]
105
- muestra = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
106
- tabla.append(muestra)
107
- resultado=df.groupby('Prediccion')['Probabilidad'].sum()
108
- colores=["#aae977","#EE3555"]
109
- fig, ax = plt.subplots(figsize=(1, 1), subplotpars=None)
110
- plt.pie(resultado,labels=resultado.index,autopct='%1.1f%%',colors=colores)
111
- ax.set_title("Porcentajes por Categorias", fontsize=1, fontweight="bold")
112
- plt.rcParams.update({'font.size':1, 'font.weight':'bold'})
113
- ax.legend()
114
- # Muestra el gráfico
115
- plt.show()
116
- st.set_option('deprecation.showPyplotGlobalUse', False)
117
- st.pyplot()
118
- else:
119
- muestra = st.text("No hay tweets a analizar")
120
- tabla.append(muestra)
121
-
122
  else:
123
  muestra = st.text("Ingrese los parametros correspondientes")
124
  tabla.append(muestra)
125
-
126
  return tabla
127
 
128
  def tweets_localidad(buscar_localidad):
 
82
 
83
  def analizar_tweets(search_words, number_of_tweets):
84
  tabla = []
85
+ if(number_of_tweets > 0 and search_words != "" ):
86
+ try:
87
+ # Buscar la información del perfil de usuario
88
+ user = api.get_user(screen_name=search_words)
89
+ st.text(f"La cuenta @{search_words} existe.")
90
+ tweets = api.user_timeline(screen_name = search_words,tweet_mode="extended", count= number_of_tweets)
91
+ result = []
92
+ for tweet in tweets:
93
+ if (tweet.full_text.startswith('RT')):
94
+ continue
95
+ elif not tweet.full_text.strip():
96
+ continue
97
+ else:
98
+ datos = preprocess(tweet.full_text)
99
+ prediction = pipeline_nlp(datos)
100
+ for predic in prediction:
101
+ etiqueta = {'Tweets': datos,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
102
+ result.append(etiqueta)
103
+ df = pd.DataFrame(result)
104
+ if df.empty:
105
+ df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
106
+ df = df[df["Prediccion"] == 'Sexista']
107
+ df = df[df["Probabilidad"] > 0.5]
108
+ muestra = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
109
+ tabla.append(muestra)
110
+ resultado=df.groupby('Prediccion')['Probabilidad'].sum()
111
+ colores=["#aae977","#EE3555"]
112
+ fig, ax = plt.subplots(figsize=(1, 1), subplotpars=None)
113
+ plt.pie(resultado,labels=resultado.index,autopct='%1.1f%%',colors=colores)
114
+ ax.set_title("Porcentajes por Categorias", fontsize=1, fontweight="bold")
115
+ plt.rcParams.update({'font.size':1, 'font.weight':'bold'})
116
+ ax.legend()
117
+ # Muestra el gráfico
118
+ plt.show()
119
+ st.set_option('deprecation.showPyplotGlobalUse', False)
120
+ st.pyplot()
121
  else:
122
+ muestra = st.text("No hay tweets a analizar")
123
+ tabla.append(muestra)
124
+ except tw.TweepError as e:
125
+ st.text(f"La cuenta @{search_words} no existe.")
126
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  else:
128
  muestra = st.text("Ingrese los parametros correspondientes")
129
  tabla.append(muestra)
130
+
131
  return tabla
132
 
133
  def tweets_localidad(buscar_localidad):