Joshua1808 commited on
Commit
f99d3df
·
1 Parent(s): d76af9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -132,7 +132,7 @@ def tweets_localidad(buscar_localidad):
132
  try:
133
  geolocator = Nominatim(user_agent="nombre_del_usuario")
134
  location = geolocator.geocode(buscar_localidad)
135
- radius = "15km"
136
  tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 1000, tweet_mode="extended")
137
  result = []
138
  for tweet in tweets:
@@ -157,10 +157,19 @@ def tweets_localidad(buscar_localidad):
157
  #df.sort_values(by='Prediccion', ascending=False, inplace=True)
158
  df['Prediccion'] = np.where(df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
159
  df['Probabilidad'] = df['Probabilidad'].round(3)
 
 
 
 
160
 
 
 
 
 
 
161
  col1, col2 = st.columns(2)
162
  with col1:
163
- muestra = st.table(df.reset_index(drop=True).head(5).style.applymap(color_survived, subset=['Prediccion']))
164
  with col2:
165
  resultado = df['Prediccion'].value_counts()
166
  def autopct_fun(abs_values):
@@ -169,10 +178,10 @@ def tweets_localidad(buscar_localidad):
169
 
170
  colores=["#EE3555","#aae977"]
171
  fig, ax = plt.subplots()
172
- fig.set_size_inches(1.8, 1.8)
173
- plt.pie(resultado,labels=resultado.index,autopct=autopct_fun(resultado),colors=colores, textprops={'fontsize': 3})
174
- ax.set_title("Porcentajes por Categorias", fontsize=3.5, fontweight="bold")
175
- plt.rcParams.update({'font.size':3, 'font.weight':'bold'})
176
  ax.legend()
177
  # Muestra el gráfico
178
  plt.show()
 
132
  try:
133
  geolocator = Nominatim(user_agent="nombre_del_usuario")
134
  location = geolocator.geocode(buscar_localidad)
135
+ radius = "50km"
136
  tweets = api.search_tweets(q="",lang="es",geocode=f"{location.latitude},{location.longitude},{radius}", count = 1000, tweet_mode="extended")
137
  result = []
138
  for tweet in tweets:
 
157
  #df.sort_values(by='Prediccion', ascending=False, inplace=True)
158
  df['Prediccion'] = np.where(df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
159
  df['Probabilidad'] = df['Probabilidad'].round(3)
160
+ # Obtener los datos con probabilidad mayor a 0.50
161
+ df = df[df['Probabilidad'] > 0.50]
162
+ # Obtener los 3 primeros datos con mayor probabilidad sexista
163
+ sexista_df = df[df['Prediccion'] == 'Sexista'].head(3)
164
 
165
+ # Obtener los 3 primeros datos con mayor probabilidad no sexista
166
+ no_sexista_df = df[df['Prediccion'] == 'No Sexista'].head(3)
167
+
168
+ # Concatenar ambos dataframes
169
+ muestra_df = pd.concat([sexista_df, no_sexista_df], axis=0)
170
  col1, col2 = st.columns(2)
171
  with col1:
172
+ muestra = st.table(muestra_df.reset_index(drop=True).head(5).style.applymap(color_survived, subset=['Prediccion']))
173
  with col2:
174
  resultado = df['Prediccion'].value_counts()
175
  def autopct_fun(abs_values):
 
178
 
179
  colores=["#EE3555","#aae977"]
180
  fig, ax = plt.subplots()
181
+ fig.set_size_inches(1.2, 1.2)
182
+ plt.pie(resultado,labels=resultado.index,autopct=autopct_fun(resultado),colors=colores, textprops={'fontsize': 2})
183
+ ax.set_title("Porcentajes por Categorias", fontsize=2.4, fontweight="bold")
184
+ plt.rcParams.update({'font.size':2, 'font.weight':'bold'})
185
  ax.legend()
186
  # Muestra el gráfico
187
  plt.show()