Spaces:
Runtime error
Runtime error
Commit
·
25d1d99
1
Parent(s):
8a0bbec
Update app.py
Browse files
app.py
CHANGED
@@ -84,6 +84,7 @@ 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
|
@@ -94,30 +95,30 @@ def analizar_tweets(search_words, number_of_tweets):
|
|
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 |
-
|
99 |
df = pd.DataFrame(result)
|
100 |
if df.empty:
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
116 |
else:
|
117 |
-
|
118 |
|
119 |
else:
|
120 |
-
|
121 |
|
122 |
return tabla
|
123 |
|
|
|
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 |
+
tabla = []
|
88 |
for tweet in tweets:
|
89 |
if (tweet.full_text.startswith('RT')):
|
90 |
continue
|
|
|
95 |
prediction = pipeline_nlp(datos)
|
96 |
for predic in prediction:
|
97 |
etiqueta = {'Tweets': datos,'Prediccion': predic['label'], 'Probabilidad': predic['score']}
|
98 |
+
result.append(etiqueta)
|
|
|
99 |
df = pd.DataFrame(result)
|
100 |
if df.empty:
|
101 |
+
df['Prediccion'] = np.where( df['Prediccion'] == 'LABEL_1', 'Sexista', 'No Sexista')
|
102 |
+
df = df[df["Prediccion"] == 'Sexista']
|
103 |
+
df = df[df["Probabilidad"] > 0.5]
|
104 |
+
muestra = st.table(df.reset_index(drop=True).head(30).style.applymap(color_survived, subset=['Prediccion']))
|
105 |
+
tabla.append(muestra)
|
106 |
+
resultado=df.groupby('Prediccion')['Probabilidad'].sum()
|
107 |
+
colores=["#aae977","#EE3555"]
|
108 |
+
fig, ax = plt.subplots(figsize=(1, 1), subplotpars=None)
|
109 |
+
plt.pie(resultado,labels=resultado.index,autopct='%1.1f%%',colors=colores)
|
110 |
+
ax.set_title("Porcentajes por Categorias", fontsize=1, fontweight="bold")
|
111 |
+
plt.rcParams.update({'font.size':1, 'font.weight':'bold'})
|
112 |
+
ax.legend()
|
113 |
+
# Muestra el gráfico
|
114 |
+
plt.show()
|
115 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
116 |
+
st.pyplot()
|
117 |
else:
|
118 |
+
st.text("No hay tweets a analizar")
|
119 |
|
120 |
else:
|
121 |
+
st.text("Ingrese la cantidad de tweets")
|
122 |
|
123 |
return tabla
|
124 |
|