Joshua1808 commited on
Commit
9273222
·
1 Parent(s): edb53bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -46
app.py CHANGED
@@ -121,6 +121,7 @@ def analizar_tweets(search_words, number_of_tweets ):
121
  return tabla
122
 
123
  def analizar_frase(frase):
 
124
  #palabra = frase.split()
125
  #palabra = frase
126
  predictions = pipeline_nlp(frase)
@@ -138,54 +139,55 @@ def analizar_frase(frase):
138
  return tabla
139
 
140
  def tweets_localidad(buscar_localidad):
141
- geolocator = Nominatim(user_agent="nombre_del_usuario")
142
- location = geolocator.geocode(buscar_localidad)
143
- radius = "10km"
144
- tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 50, tweet_mode="extended")
145
- tweet_list = [i.full_text for i in tweets]
146
- text= pd.DataFrame(tweet_list)
147
- text[0] = text[0].apply(preprocess_tweet)
148
- text_list = text[0].tolist()
149
- result = []
150
- for text in text_list:
151
- if (text.startswith('RT')):
152
- continue
153
- else:
154
- prediction = pipeline_nlp(text)
155
- for predic in prediction:
156
- etiqueta = {'Tweets': text,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
157
- result.append(etiqueta)
158
-
159
- df = pd.DataFrame(result)
160
- df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
161
- #tabla = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
162
- #df['Tweets'] = df['Tweets'].str.replace('RT|@', '')
163
- df=df[df["Prediccion"] == 'Sexista']
164
- tabla = st.table(df.reset_index(drop=True).head(50).style.applymap(color_survived, subset=['Prediccion']))
 
 
 
 
 
165
 
166
- df_sexista = df[df['Prediccion']=="Sexista"]
167
- df_no_sexista = df[df['Probabilidad'] > 0]
168
- sexista = len(df_sexista)
169
- no_sexista = len(df_no_sexista)
170
-
171
- # Crear un gráfico de barras
172
- labels = ['Sexista ', ' No sexista']
173
- counts = [sexista, no_sexista]
174
- plt.bar(labels, counts)
175
- plt.xlabel('Categoría')
176
- plt.ylabel('Cantidad de tweets')
177
- plt.title('Cantidad de tweets sexistas y no sexistas')
178
- plt.figure(figsize=(10,6))
179
- plt.show()
180
- st.pyplot()
181
-
182
- st.set_option('deprecation.showPyplotGlobalUse', False)
183
-
184
- return tabla
185
-
186
 
187
-
188
-
189
  def run():
190
  with st.form("my_form"):
191
  col,buff1, buff2 = st.columns([2,2,1])
 
121
  return tabla
122
 
123
  def analizar_frase(frase):
124
+
125
  #palabra = frase.split()
126
  #palabra = frase
127
  predictions = pipeline_nlp(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 error:
187
+ st.text¨("Error")
188
+
189
+ return tabla
 
 
190
 
 
 
191
  def run():
192
  with st.form("my_form"):
193
  col,buff1, buff2 = st.columns([2,2,1])