Joshua1808 commited on
Commit
6de011c
·
1 Parent(s): 12f1886

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
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(text)
133
  for predic in prediction:
134
- etiqueta = {'Tweets': text,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
135
  result.append(etiqueta)
136
- df = pd.DataFrame(result)
137
- df['Prediccion'] = np.where(df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
138
- df = df[df["Prediccion"] == 'Sexista']
139
- df = df[df["Probabilidad"] > 0.80]
140
- muestra = st.table(df.reset_index(drop=True).head(5).style.applymap(color_survived, subset=['Prediccion']))
141
- tabla.append(muestra)
142
- resultado=df.groupby('Prediccion')['Probabilidad'].sum()
143
- colores=["#aae977","#EE3555"]
144
- fig, ax = plt.subplots(figsize=(4, 4), subplotpars=None)
145
- plt.pie(resultado,labels=resultado.index,autopct='%1.1f%%',colors=colores)
146
- ax.set_title("Porcentajes por Categorias", fontsize=8, fontweight="bold")
147
- plt.rcParams.update({'font.size':8, 'font.weight':'bold'})
148
- ax.legend()
149
- # Muestra el gráfico
150
- plt.show()
151
- st.set_option('deprecation.showPyplotGlobalUse', False)
152
- st.pyplot()
 
 
 
 
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")