Spaces:
Runtime error
Runtime error
Commit
·
6396a19
1
Parent(s):
e830ce8
Update app.py
Browse files
app.py
CHANGED
|
@@ -139,52 +139,51 @@ def analizar_frase(frase):
|
|
| 139 |
return tabla
|
| 140 |
|
| 141 |
def tweets_localidad(buscar_localidad):
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
prediction = pipeline_nlp(text)
|
| 157 |
for predic in prediction:
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 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 |
|