Joshua1808 commited on
Commit
6396a19
·
1 Parent(s): e830ce8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -41
app.py CHANGED
@@ -139,52 +139,51 @@ def analizar_frase(frase):
139
  return tabla
140
 
141
  def tweets_localidad(buscar_localidad):
142
- try:
143
- geolocator = Nominatim(user_agent="nombre_del_usuario")
144
- location = geolocator.geocode(buscar_localidad)
145
- radius = "10km"
146
- tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 50, tweet_mode="extended")
147
- tweet_list = [i.full_text for i in tweets]
148
- text= pd.DataFrame(tweet_list)
149
- text[0] = text[0].apply(preprocess_tweet)
150
- text_list = text[0].tolist()
151
- result = []
152
- for text in text_list:
153
- if (text.startswith('RT')):
154
- continue
155
- else:
156
  prediction = pipeline_nlp(text)
157
  for predic in prediction:
158
- etiqueta = {'Tweets': text,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
159
- result.append(etiqueta)
160
- df = pd.DataFrame(result)
161
- df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
162
- #tabla = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
163
- #df['Tweets'] = df['Tweets'].str.replace('RT|@', '')
164
- df=df[df["Prediccion"] == 'Sexista']
165
- tabla = st.table(df.reset_index(drop=True).head(50).style.applymap(color_survived, subset=['Prediccion']))
 
 
 
166
 
167
- df_sexista = df[df['Prediccion']=="Sexista"]
168
- df_no_sexista = df[df['Probabilidad'] > 0]
169
- sexista = len(df_sexista)
170
- no_sexista = len(df_no_sexista)
171
 
172
- # Crear un gráfico de barras
173
- labels = ['Sexista ', ' No sexista']
174
- counts = [sexista, no_sexista]
175
- plt.bar(labels, counts)
176
- plt.xlabel('Categoría')
177
- plt.ylabel('Cantidad de tweets')
178
- plt.title('Cantidad de tweets sexistas y no sexistas')
179
- plt.figure(figsize=(10,6))
180
- plt.show()
181
- st.pyplot()
182
-
183
- st.set_option('deprecation.showPyplotGlobalUse', False)
184
 
185
-
186
- except FileNotFoundError:
187
- st.text("Error: no existe ninguna localidad con ese Nombre ")
188
 
189
  return tabla
190
 
 
139
  return tabla
140
 
141
  def tweets_localidad(buscar_localidad):
142
+ geolocator = Nominatim(user_agent="nombre_del_usuario")
143
+ location = geolocator.geocode(buscar_localidad)
144
+ radius = "10km"
145
+ tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 50, tweet_mode="extended")
146
+ tweet_list = [i.full_text for i in tweets]
147
+ text= pd.DataFrame(tweet_list)
148
+ text[0] = text[0].apply(preprocess_tweet)
149
+ text_list = text[0].tolist()
150
+ result = []
151
+ for text in text_list:
152
+ if (text.startswith('RT')):
153
+ continue
154
+ else:
155
+ try:
156
  prediction = pipeline_nlp(text)
157
  for predic in prediction:
158
+ etiqueta = {'Tweets': text,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
159
+ result.append(etiqueta)
160
+
161
+ except FileNotFoundError:
162
+ st.text("No existe ninguna localidad con ese nombre")
163
+ df = pd.DataFrame(result)
164
+ df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
165
+ #tabla = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
166
+ #df['Tweets'] = df['Tweets'].str.replace('RT|@', '')
167
+ df=df[df["Prediccion"] == 'Sexista']
168
+ tabla = st.table(df.reset_index(drop=True).head(50).style.applymap(color_survived, subset=['Prediccion']))
169
 
170
+ df_sexista = df[df['Prediccion']=="Sexista"]
171
+ df_no_sexista = df[df['Probabilidad'] > 0]
172
+ sexista = len(df_sexista)
173
+ no_sexista = len(df_no_sexista)
174
 
175
+ # Crear un gráfico de barras
176
+ labels = ['Sexista ', ' No sexista']
177
+ counts = [sexista, no_sexista]
178
+ plt.bar(labels, counts)
179
+ plt.xlabel('Categoría')
180
+ plt.ylabel('Cantidad de tweets')
181
+ plt.title('Cantidad de tweets sexistas y no sexistas')
182
+ plt.figure(figsize=(10,6))
183
+ plt.show()
184
+ st.pyplot()
 
 
185
 
186
+ st.set_option('deprecation.showPyplotGlobalUse', False)
 
 
187
 
188
  return tabla
189