Joshua1808 commited on
Commit
f9ed481
·
1 Parent(s): 9ffd42a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -32
app.py CHANGED
@@ -80,38 +80,40 @@ with colT2:
80
  font-size:16px ; font-family: 'Times New Roman'; color: #3358ff;}
81
  </style> """, unsafe_allow_html=True)
82
 
83
- def analizar_tweets(search_words, number_of_tweets ):
84
- tweets = api.user_timeline(screen_name = search_words,tweet_mode="extended", count= number_of_tweets)
85
- result = []
86
- for tweet in tweets:
87
- if (tweet.full_text.startswith('RT')):
88
- continue
89
- elif not tweet.full_text.strip():
90
- continue
91
- else:
92
- datos = preprocess(tweet.full_text)
93
- prediction = pipeline_nlp(datos)
94
- for predic in prediction:
95
- etiqueta = {'Tweets': datos,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
96
- result.append(etiqueta)
97
-
98
- df = pd.DataFrame(result)
99
- df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
100
- df = df[df["Prediccion"] == 'Sexista']
101
- df = df[df["Probabilidad"] > 0.80]
102
- tabla = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
103
- resultado=df.groupby('Prediccion')['Probabilidad'].sum()
104
- colores=["#aae977","#EE3555"]
105
- fig, ax = plt.subplots(figsize=(2, 2), subplotpars=None)
106
- plt.pie(resultado,labels=resultado.index,autopct='%1.1f%%',colors=colores)
107
- ax.set_title("Porcentajes por Categorias", fontsize=8, fontweight="bold")
108
- plt.rcParams.update({'font.size':8, 'font.weight':'bold'})
109
- ax.legend()
110
- # Muestra el gráfico
111
- plt.show()
112
- st.set_option('deprecation.showPyplotGlobalUse', False)
113
- st.pyplot()
114
-
 
 
115
  return tabla
116
 
117
  def tweets_localidad(buscar_localidad):
 
80
  font-size:16px ; font-family: 'Times New Roman'; color: #3358ff;}
81
  </style> """, unsafe_allow_html=True)
82
 
83
+ def analizar_tweets(search_words, number_of_tweets):
84
+ if(number_of_tweets > 0):
85
+ tweets = api.user_timeline(screen_name = search_words,tweet_mode="extended", count= number_of_tweets)
86
+ result = []
87
+ for tweet in tweets:
88
+ if (tweet.full_text.startswith('RT')):
89
+ continue
90
+ elif not tweet.full_text.strip():
91
+ continue
92
+ else:
93
+ datos = preprocess(tweet.full_text)
94
+ prediction = pipeline_nlp(datos)
95
+ for predic in prediction:
96
+ etiqueta = {'Tweets': datos,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
97
+ result.append(etiqueta)
98
+ df = pd.DataFrame(result)
99
+ df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
100
+ df = df[df["Prediccion"] == 'Sexista']
101
+ df = df[df["Probabilidad"] > 0.5]
102
+ tabla = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
103
+ resultado=df.groupby('Prediccion')['Probabilidad'].sum()
104
+ colores=["#aae977","#EE3555"]
105
+ fig, ax = plt.subplots(figsize=(1, 1), subplotpars=None)
106
+ plt.pie(resultado,labels=resultado.index,autopct='%1.1f%%',colors=colores)
107
+ ax.set_title("Porcentajes por Categorias", fontsize=1, fontweight="bold")
108
+ plt.rcParams.update({'font.size':1, 'font.weight':'bold'})
109
+ ax.legend()
110
+ # Muestra el gráfico
111
+ plt.show()
112
+ st.set_option('deprecation.showPyplotGlobalUse', False)
113
+ st.pyplot()
114
+ else:
115
+ tabla = st.text("Ingrese los valores")
116
+
117
  return tabla
118
 
119
  def tweets_localidad(buscar_localidad):