Spaces:
Runtime error
Runtime error
Commit
·
b2185ad
1
Parent(s):
3d2732d
Working with NaNs
Browse files
app.py
CHANGED
|
@@ -35,11 +35,18 @@ def load_reviews(category):
|
|
| 35 |
df = pd.read_json(file_path, lines=True, compression='gzip')
|
| 36 |
return df
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def sentiment_counts_by_category(category):
|
| 40 |
df_category = load_reviews(category)
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
fig = plot_sentiment_distribution(df_category)
|
| 44 |
return fig
|
| 45 |
|
|
|
|
| 35 |
df = pd.read_json(file_path, lines=True, compression='gzip')
|
| 36 |
return df
|
| 37 |
|
| 38 |
+
def analyze_sentiment(text):
|
| 39 |
+
# Verifica si el texto es una cadena de texto (string)
|
| 40 |
+
if isinstance(text, str):
|
| 41 |
+
return sentiment_pipeline(text[:512])[0]['label']
|
| 42 |
+
else:
|
| 43 |
+
return "Unknown" # O algún valor por defecto para datos no procesables
|
| 44 |
+
|
| 45 |
def sentiment_counts_by_category(category):
|
| 46 |
df_category = load_reviews(category)
|
| 47 |
+
# Aplica la función de análisis de sentimientos modificada
|
| 48 |
+
df_category['sentiment'] = df_category['reviewText'].apply(analyze_sentiment)
|
| 49 |
+
# Llama a la función de trazado y devuelve el gráfico
|
| 50 |
fig = plot_sentiment_distribution(df_category)
|
| 51 |
return fig
|
| 52 |
|