Spaces:
Runtime error
Runtime error
Commit
·
6de011c
1
Parent(s):
12f1886
Update app.py
Browse files
app.py
CHANGED
@@ -129,27 +129,31 @@ def tweets_localidad(buscar_localidad):
|
|
129 |
continue
|
130 |
else:
|
131 |
datos = preprocess(tweet.full_text)
|
132 |
-
prediction = pipeline_nlp(
|
133 |
for predic in prediction:
|
134 |
-
etiqueta = {'Tweets':
|
135 |
result.append(etiqueta)
|
136 |
-
df
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
153 |
|
154 |
except AttributeError:
|
155 |
st.text("No existe ninguna localidad con ese nombre")
|
|
|
129 |
continue
|
130 |
else:
|
131 |
datos = preprocess(tweet.full_text)
|
132 |
+
prediction = pipeline_nlp(datos)
|
133 |
for predic in prediction:
|
134 |
+
etiqueta = {'Tweets': datos,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
|
135 |
result.append(etiqueta)
|
136 |
+
if df.empty:
|
137 |
+
st.text("No se encontraron tweets sexistas dentro de la localidad")
|
138 |
+
else:
|
139 |
+
df = pd.DataFrame(result)
|
140 |
+
df['Prediccion'] = np.where(df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
|
141 |
+
df = df[df["Prediccion"] == 'Sexista']
|
142 |
+
df = df[df["Probabilidad"] > 0.5]
|
143 |
+
df = df.sort_values(by='Probabilidad', ascending=False)
|
144 |
+
muestra = st.table(df.reset_index(drop=True).head(5).style.applymap(color_survived, subset=['Prediccion']))
|
145 |
+
tabla.append(muestra)
|
146 |
+
resultado=df.groupby('Prediccion')['Probabilidad'].sum()
|
147 |
+
colores=["#aae977","#EE3555"]
|
148 |
+
fig, ax = plt.subplots(figsize=(1, 1), subplotpars=None)
|
149 |
+
plt.pie(resultado,labels=resultado.index,autopct='%1.1f%%',colors=colores)
|
150 |
+
ax.set_title("Porcentajes por Categorias", fontsize=8, fontweight="bold")
|
151 |
+
plt.rcParams.update({'font.size':8, 'font.weight':'bold'})
|
152 |
+
ax.legend()
|
153 |
+
# Muestra el gráfico
|
154 |
+
plt.show()
|
155 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
156 |
+
st.pyplot()
|
157 |
|
158 |
except AttributeError:
|
159 |
st.text("No existe ninguna localidad con ese nombre")
|