Update app.py
Browse files
app.py
CHANGED
@@ -122,19 +122,19 @@ def interpret_sentiment(label, score):
|
|
122 |
# --- Sentiment Analysis Function ---
|
123 |
def analyze_sentiment(text):
|
124 |
if not model_loaded_successfully:
|
125 |
-
# Devuelve 3 valores: HTML, dict,
|
126 |
return (
|
127 |
"<div class='sentiment-display'>⚠️ Model Not Loaded ⚠️</div><p>Please contact the administrator. The sentiment analysis model failed to load.</p>",
|
128 |
{}, # Diccionario vacío para Confidence Scores
|
129 |
-
"Model loading failed." #
|
130 |
)
|
131 |
|
132 |
if not text.strip():
|
133 |
-
# Devuelve 3 valores: HTML, dict,
|
134 |
return (
|
135 |
"<div class='sentiment-display'>✍️ Please enter some text! ✍️</div><p>Start typing to analyze its sentiment.</p>",
|
136 |
{}, # Diccionario vacío para Confidence Scores
|
137 |
-
"" #
|
138 |
)
|
139 |
|
140 |
try:
|
@@ -155,14 +155,16 @@ def analyze_sentiment(text):
|
|
155 |
# Generar el HTML para mostrar el sentimiento general
|
156 |
overall_sentiment_display = interpret_sentiment(label, score)
|
157 |
|
158 |
-
# ¡
|
159 |
-
|
|
|
|
|
160 |
except Exception as e:
|
161 |
# En caso de cualquier error durante el análisis, devuelve 3 valores de error
|
162 |
return (
|
163 |
f"<div class='sentiment-display'>❌ Error ❌</div><p>An error occurred during analysis: {e}</p>",
|
164 |
{}, # Diccionario vacío para Confidence Scores
|
165 |
-
|
166 |
)
|
167 |
|
168 |
# --- Gradio Interface ---
|
|
|
122 |
# --- Sentiment Analysis Function ---
|
123 |
def analyze_sentiment(text):
|
124 |
if not model_loaded_successfully:
|
125 |
+
# Devuelve 3 valores: HTML, dict, dict (para JSON)
|
126 |
return (
|
127 |
"<div class='sentiment-display'>⚠️ Model Not Loaded ⚠️</div><p>Please contact the administrator. The sentiment analysis model failed to load.</p>",
|
128 |
{}, # Diccionario vacío para Confidence Scores
|
129 |
+
{"error": "Model loading failed."} # Diccionario de error para Raw Output JSON
|
130 |
)
|
131 |
|
132 |
if not text.strip():
|
133 |
+
# Devuelve 3 valores: HTML, dict, dict (para JSON)
|
134 |
return (
|
135 |
"<div class='sentiment-display'>✍️ Please enter some text! ✍️</div><p>Start typing to analyze its sentiment.</p>",
|
136 |
{}, # Diccionario vacío para Confidence Scores
|
137 |
+
{"info": "No text entered."} # Diccionario de info para Raw Output JSON
|
138 |
)
|
139 |
|
140 |
try:
|
|
|
155 |
# Generar el HTML para mostrar el sentimiento general
|
156 |
overall_sentiment_display = interpret_sentiment(label, score)
|
157 |
|
158 |
+
# ¡CORRECCIÓN FINAL AQUÍ! Pasa 'results' directamente, no str(results)
|
159 |
+
# Gradio se encargará de serializar este objeto Python a JSON
|
160 |
+
return (overall_sentiment_display, confidence_scores_output, results)
|
161 |
+
|
162 |
except Exception as e:
|
163 |
# En caso de cualquier error durante el análisis, devuelve 3 valores de error
|
164 |
return (
|
165 |
f"<div class='sentiment-display'>❌ Error ❌</div><p>An error occurred during analysis: {e}</p>",
|
166 |
{}, # Diccionario vacío para Confidence Scores
|
167 |
+
{"error_message": str(e)} # Diccionario de error para Raw Output JSON
|
168 |
)
|
169 |
|
170 |
# --- Gradio Interface ---
|