Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,112 +20,187 @@ except Exception as e:
|
|
20 |
model_loaded_successfully = False
|
21 |
print("Sentiment analysis model failed to load. Please check MODEL_ID and network connection.")
|
22 |
|
23 |
-
# --- Custom CSS with the NEW COLOR PALETTE ---
|
24 |
custom_css = """
|
|
|
25 |
body {
|
26 |
background-color: #1E2B38; /* Fondo General Oscuro */
|
27 |
color: #FFFFFF; /* Blanco para texto principal */
|
28 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
|
|
|
|
30 |
.gradio-container {
|
31 |
-
box-shadow: 0 4px
|
32 |
-
border-radius:
|
33 |
overflow: hidden;
|
34 |
-
background-color: #1E2B38; /* Fondo de la tarjeta, coincide con el body
|
35 |
-
padding:
|
36 |
-
margin-bottom:
|
37 |
border: 1px solid #007ACC; /* Borde sutil con Azul Oscuro */
|
|
|
|
|
|
|
38 |
}
|
|
|
|
|
39 |
h1, h2, h3 {
|
40 |
color: #00BFFF; /* Azul Brillante para títulos */
|
41 |
text-align: center;
|
42 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
43 |
animation: fadeIn 1s ease-in-out;
|
44 |
-
margin-top: 5px; /*
|
45 |
-
margin-bottom:
|
|
|
46 |
}
|
|
|
|
|
|
|
47 |
p {
|
48 |
color: #AAB7C4; /* Gris medio para texto secundario */
|
49 |
text-align: center;
|
50 |
-
margin-bottom:
|
|
|
|
|
51 |
}
|
|
|
|
|
52 |
.gr-textbox label, .gradio-output .label {
|
53 |
-
color: #AAB7C4 !important; /* Gris medio para las etiquetas
|
54 |
font-weight: bold;
|
|
|
|
|
55 |
}
|
56 |
.gr-textbox textarea {
|
57 |
-
background-color:
|
58 |
border: 1px solid #007ACC; /* Borde con Azul Oscuro */
|
59 |
color: #FFFFFF; /* Texto blanco en el textarea */
|
60 |
-
border-radius:
|
61 |
-
padding:
|
|
|
62 |
}
|
|
|
|
|
63 |
.gr-button.primary {
|
64 |
background-color: #00BFFF !important; /* Azul Brillante para el botón primario */
|
65 |
color: #1E2B38 !important; /* Texto oscuro para el botón primario */
|
66 |
-
border-radius:
|
67 |
transition: background-color 0.3s ease;
|
68 |
-
padding: 12px
|
69 |
-
font-size:
|
70 |
font-weight: bold;
|
71 |
-
margin-top:
|
|
|
72 |
}
|
73 |
.gr-button.primary:hover {
|
74 |
background-color: #007ACC !important; /* Azul Oscuro al pasar el ratón */
|
75 |
color: #FFFFFF !important; /* Texto blanco al pasar el ratón */
|
76 |
}
|
|
|
|
|
77 |
.gradio-output {
|
78 |
border: 1px solid #4A5B6C; /* Borde sutil con Gris Claro */
|
79 |
-
border-radius:
|
80 |
-
padding:
|
81 |
-
margin-top:
|
82 |
-
background-color:
|
83 |
color: #FFFFFF; /* Texto blanco en la salida */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
.sentiment-display {
|
86 |
text-align: center;
|
87 |
-
padding:
|
88 |
-
border-radius:
|
89 |
-
margin-top:
|
90 |
-
font-size:
|
91 |
font-weight: bold;
|
92 |
color: #FFFFFF; /* Texto blanco para todos los sentimientos */
|
93 |
}
|
94 |
-
.sentiment-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
}
|
100 |
-
.sentiment-neutral {
|
101 |
-
background-color: #007BFF; /* Azul Bootstrap similar */
|
102 |
}
|
|
|
|
|
|
|
|
|
|
|
103 |
.gradio-example-highlighted {
|
104 |
-
background-color:
|
105 |
border: 1px solid #00BFFF !important;
|
106 |
}
|
107 |
.gradio-example-button {
|
108 |
background-color: #4A5B6C !important; /* Gris Claro para los botones de ejemplo */
|
109 |
color: #FFFFFF !important;
|
110 |
border: 1px solid #4A5B6C;
|
111 |
-
border-radius:
|
112 |
-
padding: 8px
|
113 |
-
margin:
|
114 |
transition: background-color 0.3s ease;
|
|
|
|
|
|
|
115 |
}
|
116 |
.gradio-example-button:hover {
|
117 |
background-color: #007ACC !important; /* Azul Oscuro al pasar el ratón por los ejemplos */
|
118 |
border-color: #00BFFF !important;
|
119 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
hr {
|
121 |
border-top: 1px solid #4A5B6C; /* Línea divisoria con Gris Claro */
|
122 |
-
margin-top:
|
123 |
-
margin-bottom:
|
124 |
}
|
|
|
|
|
125 |
@keyframes fadeIn {
|
126 |
from { opacity: 0; }
|
127 |
to { opacity: 1; }
|
128 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
"""
|
130 |
|
131 |
# --- Helper Function for Sentiment Interpretation ---
|
@@ -138,36 +213,36 @@ def interpret_sentiment(label, score):
|
|
138 |
# 'LABEL_0' es negativo, 'LABEL_1' es neutral, 'LABEL_2' es positivo
|
139 |
if label.lower() == "positive" or label.lower() == "label_2":
|
140 |
emoji = "😊"
|
141 |
-
description = "
|
142 |
color_class = "sentiment-positive"
|
143 |
elif label.lower() == "negative" or label.lower() == "label_0":
|
144 |
emoji = "😠"
|
145 |
-
description = "
|
146 |
color_class = "sentiment-negative"
|
147 |
elif label.lower() == "neutral" or label.lower() == "label_1":
|
148 |
emoji = "😐"
|
149 |
-
description = "
|
150 |
color_class = "sentiment-neutral"
|
151 |
else:
|
152 |
emoji = "❓"
|
153 |
-
description = "
|
154 |
color_class = ""
|
155 |
|
156 |
return f"<div class='sentiment-display {color_class}'>{emoji} {label.upper()} ({score:.2f})</div>" + \
|
157 |
-
f"<p style='color: #FFFFFF;'>{description}</p>" # Asegurar que la descripción
|
158 |
|
159 |
# --- Sentiment Analysis Function ---
|
160 |
def analyze_sentiment(text):
|
161 |
if not model_loaded_successfully:
|
162 |
return (
|
163 |
-
"<div class='sentiment-display'>⚠️ Model
|
164 |
{},
|
165 |
{"error": "Model loading failed."}
|
166 |
)
|
167 |
|
168 |
if not text.strip():
|
169 |
return (
|
170 |
-
"<div class='sentiment-display'>✍️
|
171 |
{},
|
172 |
{"info": "No text entered."}
|
173 |
)
|
@@ -189,7 +264,7 @@ def analyze_sentiment(text):
|
|
189 |
|
190 |
except Exception as e:
|
191 |
return (
|
192 |
-
f"<div class='sentiment-display'>❌ Error ❌</div><p style='color: #FFFFFF;'>
|
193 |
{},
|
194 |
{"error_message": str(e)}
|
195 |
)
|
@@ -197,11 +272,11 @@ def analyze_sentiment(text):
|
|
197 |
# --- Gradio Interface ---
|
198 |
with gr.Blocks(css=custom_css, theme=None) as demo:
|
199 |
gr.Markdown("<h1 style='color: #00BFFF;'>🌌 Sentiment Analyzer 🌌</h1>")
|
200 |
-
gr.Markdown("<p style='color: #AAB7C4;'>
|
201 |
|
202 |
with gr.Column(elem_classes="gradio-container"):
|
203 |
text_input = gr.Textbox(
|
204 |
-
lines=
|
205 |
placeholder="Type your English text here...",
|
206 |
label="Your Text",
|
207 |
interactive=True,
|
@@ -210,29 +285,30 @@ with gr.Blocks(css=custom_css, theme=None) as demo:
|
|
210 |
analyze_btn = gr.Button("Analyze Sentiment", variant="primary")
|
211 |
|
212 |
gr.Markdown("<hr>")
|
213 |
-
gr.Markdown("<h3 style='color: #00BFFF;'>Try
|
214 |
|
215 |
-
|
216 |
-
examples=
|
217 |
-
[
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
229 |
|
230 |
gr.Markdown("<hr>")
|
231 |
-
gr.Markdown("<h2 style='color: #00BFFF;'>📊
|
232 |
|
233 |
overall_sentiment_output = gr.HTML(label="Overall Sentiment")
|
234 |
confidence_scores_output = gr.Label(num_top_classes=3, label="Confidence Scores")
|
235 |
-
# Deja Raw Model Output como visible=False para ahorrar espacio en el iframe por defecto
|
236 |
raw_output = gr.JSON(label="Raw Model Output", visible=False)
|
237 |
|
238 |
# --- Event Listeners ---
|
@@ -245,7 +321,7 @@ with gr.Blocks(css=custom_css, theme=None) as demo:
|
|
245 |
fn=analyze_sentiment,
|
246 |
inputs=text_input,
|
247 |
outputs=[overall_sentiment_output, confidence_scores_output, raw_output],
|
248 |
-
# live=True
|
249 |
)
|
250 |
|
251 |
# Launch the Gradio application
|
|
|
20 |
model_loaded_successfully = False
|
21 |
print("Sentiment analysis model failed to load. Please check MODEL_ID and network connection.")
|
22 |
|
23 |
+
# --- Custom CSS with the NEW COLOR PALETTE and MAXIMUM COMPACTNESS ---
|
24 |
custom_css = """
|
25 |
+
/* RESETEO BÁSICO Y FONDOS GENERALES */
|
26 |
body {
|
27 |
background-color: #1E2B38; /* Fondo General Oscuro */
|
28 |
color: #FFFFFF; /* Blanco para texto principal */
|
29 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
30 |
+
padding: 0;
|
31 |
+
margin: 0;
|
32 |
+
overflow: hidden; /* Ocultar scrollbar si hay un pequeño desbordamiento */
|
33 |
+
height: 100vh; /* Asegurar que el body ocupe toda la altura del viewport */
|
34 |
+
display: flex;
|
35 |
+
flex-direction: column;
|
36 |
}
|
37 |
+
|
38 |
+
/* CONTENEDOR PRINCIPAL DE GRADIO */
|
39 |
.gradio-container {
|
40 |
+
box-shadow: 0 2px 4px rgba(0, 122, 204, 0.1); /* Sombra más sutil */
|
41 |
+
border-radius: 6px; /* Borde más pequeño */
|
42 |
overflow: hidden;
|
43 |
+
background-color: #1E2B38; /* Fondo de la tarjeta, coincide con el body */
|
44 |
+
padding: 10px; /* Reducir padding general del contenedor */
|
45 |
+
margin-bottom: 5px; /* Reducir margen inferior */
|
46 |
border: 1px solid #007ACC; /* Borde sutil con Azul Oscuro */
|
47 |
+
flex-grow: 1; /* Permite que el contenedor ocupe el espacio disponible */
|
48 |
+
display: flex;
|
49 |
+
flex-direction: column;
|
50 |
}
|
51 |
+
|
52 |
+
/* AJUSTES DE TÍTULOS Y PÁRRAFOS */
|
53 |
h1, h2, h3 {
|
54 |
color: #00BFFF; /* Azul Brillante para títulos */
|
55 |
text-align: center;
|
56 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
57 |
animation: fadeIn 1s ease-in-out;
|
58 |
+
margin-top: 5px; /* Margen superior muy pequeño */
|
59 |
+
margin-bottom: 8px; /* Margen inferior reducido */
|
60 |
+
font-size: 1.4em; /* h1 más pequeño */
|
61 |
}
|
62 |
+
h2 { font-size: 1.1em; } /* h2 más pequeño */
|
63 |
+
h3 { font-size: 0.95em; } /* h3 más pequeño, casi texto normal */
|
64 |
+
|
65 |
p {
|
66 |
color: #AAB7C4; /* Gris medio para texto secundario */
|
67 |
text-align: center;
|
68 |
+
margin-bottom: 10px; /* Margen debajo de los párrafos reducido */
|
69 |
+
font-size: 0.8em; /* Tamaño de fuente más pequeño para párrafos */
|
70 |
+
line-height: 1.3; /* Espaciado entre líneas para legibilidad */
|
71 |
}
|
72 |
+
|
73 |
+
/* COMPONENTES DE ENTRADA (TEXTBOX) */
|
74 |
.gr-textbox label, .gradio-output .label {
|
75 |
+
color: #AAB7C4 !important; /* Gris medio para las etiquetas */
|
76 |
font-weight: bold;
|
77 |
+
font-size: 0.85em; /* Etiqueta más pequeña */
|
78 |
+
margin-bottom: 3px; /* Espacio mínimo entre etiqueta y caja */
|
79 |
}
|
80 |
.gr-textbox textarea {
|
81 |
+
background-color: rgba(0, 122, 204, 0.1); /* Azul Oscuro muy transparente */
|
82 |
border: 1px solid #007ACC; /* Borde con Azul Oscuro */
|
83 |
color: #FFFFFF; /* Texto blanco en el textarea */
|
84 |
+
border-radius: 5px; /* Bordes más pequeños */
|
85 |
+
padding: 6px; /* Reducir padding del textarea */
|
86 |
+
font-size: 0.9em; /* Fuente más pequeña en el textarea */
|
87 |
}
|
88 |
+
|
89 |
+
/* BOTONES PRINCIPALES */
|
90 |
.gr-button.primary {
|
91 |
background-color: #00BFFF !important; /* Azul Brillante para el botón primario */
|
92 |
color: #1E2B38 !important; /* Texto oscuro para el botón primario */
|
93 |
+
border-radius: 5px;
|
94 |
transition: background-color 0.3s ease;
|
95 |
+
padding: 7px 12px; /* Padding más pequeño del botón */
|
96 |
+
font-size: 0.9em; /* Un poco más pequeño para el botón */
|
97 |
font-weight: bold;
|
98 |
+
margin-top: 8px; /* Reducir margen superior */
|
99 |
+
margin-bottom: 5px; /* Añadir un pequeño margen inferior */
|
100 |
}
|
101 |
.gr-button.primary:hover {
|
102 |
background-color: #007ACC !important; /* Azul Oscuro al pasar el ratón */
|
103 |
color: #FFFFFF !important; /* Texto blanco al pasar el ratón */
|
104 |
}
|
105 |
+
|
106 |
+
/* COMPONENTES DE SALIDA (HTML, LABEL, JSON) */
|
107 |
.gradio-output {
|
108 |
border: 1px solid #4A5B6C; /* Borde sutil con Gris Claro */
|
109 |
+
border-radius: 5px; /* Borde más pequeño */
|
110 |
+
padding: 8px; /* Reducir padding de la salida */
|
111 |
+
margin-top: 8px; /* Reducir margen superior */
|
112 |
+
background-color: rgba(0, 122, 204, 0.08); /* Fondo más sutil para la salida */
|
113 |
color: #FFFFFF; /* Texto blanco en la salida */
|
114 |
+
flex-grow: 1; /* Permitir que ocupe el espacio restante */
|
115 |
+
display: flex;
|
116 |
+
flex-direction: column;
|
117 |
+
justify-content: center; /* Centrar verticalmente el contenido */
|
118 |
+
min-height: 80px; /* Altura mínima para asegurar visibilidad */
|
119 |
+
}
|
120 |
+
.gradio-output .label-text {
|
121 |
+
color: #00BFFF !important; /* Color de acento para el texto del label (LABEL_1, LABEL_0, etc.) */
|
122 |
+
font-weight: bold;
|
123 |
}
|
124 |
+
.gradio-output .label-score {
|
125 |
+
color: #FFFFFF !important; /* Blanco para el score del label */
|
126 |
+
}
|
127 |
+
.gradio-output .label-container {
|
128 |
+
padding-bottom: 5px !important; /* Reducir padding entre elementos del label */
|
129 |
+
}
|
130 |
+
|
131 |
+
/* DISPLAY DE SENTIMIENTO (DENTRO DE HTML OUTPUT) */
|
132 |
.sentiment-display {
|
133 |
text-align: center;
|
134 |
+
padding: 6px; /* Reducir padding */
|
135 |
+
border-radius: 4px; /* Borde más pequeño */
|
136 |
+
margin-top: 3px; /* Margen muy pequeño */
|
137 |
+
font-size: 1em; /* Un poco más pequeño */
|
138 |
font-weight: bold;
|
139 |
color: #FFFFFF; /* Texto blanco para todos los sentimientos */
|
140 |
}
|
141 |
+
.sentiment-display p { /* Estilo específico para el párrafo de descripción */
|
142 |
+
font-size: 0.75em; /* Tamaño más pequeño para la descripción */
|
143 |
+
margin-top: 3px;
|
144 |
+
margin-bottom: 0;
|
145 |
+
line-height: 1.2;
|
|
|
|
|
|
|
146 |
}
|
147 |
+
.sentiment-positive { background-color: #28a745; } /* Mantener estos colores por claridad de sentimiento */
|
148 |
+
.sentiment-negative { background-color: #dc3545; }
|
149 |
+
.sentiment-neutral { background-color: #007BFF; }
|
150 |
+
|
151 |
+
/* EJEMPLOS */
|
152 |
.gradio-example-highlighted {
|
153 |
+
background-color: rgba(0, 191, 255, 0.1) !important; /* Azul Brillante transparente */
|
154 |
border: 1px solid #00BFFF !important;
|
155 |
}
|
156 |
.gradio-example-button {
|
157 |
background-color: #4A5B6C !important; /* Gris Claro para los botones de ejemplo */
|
158 |
color: #FFFFFF !important;
|
159 |
border: 1px solid #4A5B6C;
|
160 |
+
border-radius: 3px; /* Borde más pequeño */
|
161 |
+
padding: 5px 8px; /* Padding más pequeño */
|
162 |
+
margin: 2px; /* Margen mínimo entre botones */
|
163 |
transition: background-color 0.3s ease;
|
164 |
+
font-size: 0.75em; /* Tamaño de fuente más pequeño para los ejemplos */
|
165 |
+
white-space: nowrap; /* Evitar que el texto se rompa en varias líneas */
|
166 |
+
flex-shrink: 0; /* No permitir que se encojan si hay poco espacio */
|
167 |
}
|
168 |
.gradio-example-button:hover {
|
169 |
background-color: #007ACC !important; /* Azul Oscuro al pasar el ratón por los ejemplos */
|
170 |
border-color: #00BFFF !important;
|
171 |
}
|
172 |
+
.example-buttons-row {
|
173 |
+
flex-wrap: wrap; /* Permitir que los botones se envuelvan si no hay suficiente ancho */
|
174 |
+
justify-content: center; /* Centrar los botones de ejemplo */
|
175 |
+
margin-bottom: 5px !important; /* Reducir margen inferior */
|
176 |
+
}
|
177 |
+
|
178 |
+
|
179 |
+
/* LÍNEAS DIVISORIAS */
|
180 |
hr {
|
181 |
border-top: 1px solid #4A5B6C; /* Línea divisoria con Gris Claro */
|
182 |
+
margin-top: 10px; /* Reducir margen superior */
|
183 |
+
margin-bottom: 10px; /* Reducir margen inferior */
|
184 |
}
|
185 |
+
|
186 |
+
/* ANIMACIÓN */
|
187 |
@keyframes fadeIn {
|
188 |
from { opacity: 0; }
|
189 |
to { opacity: 1; }
|
190 |
}
|
191 |
+
|
192 |
+
/* OCULTAR EL PIE DE PÁGINA DE GRADIO (CRUCIAL PARA IFRAMES PEQUEÑOS) */
|
193 |
+
footer {
|
194 |
+
opacity: 0; /* Hacerlo invisible */
|
195 |
+
height: 0 !important; /* Eliminar su altura */
|
196 |
+
margin: 0 !important; /* Eliminar sus márgenes */
|
197 |
+
padding: 0 !important; /* Eliminar su padding */
|
198 |
+
pointer-events: none; /* No interactuable */
|
199 |
+
visibility: hidden; /* Asegurar que no ocupe espacio visual */
|
200 |
+
}
|
201 |
+
.gradio-app > div > :last-child:not(.gradio-container) { /* Apuntar al elemento del pie de página */
|
202 |
+
display: none !important; /* Otra forma de ocultar completamente si lo anterior no funciona */
|
203 |
+
}
|
204 |
"""
|
205 |
|
206 |
# --- Helper Function for Sentiment Interpretation ---
|
|
|
213 |
# 'LABEL_0' es negativo, 'LABEL_1' es neutral, 'LABEL_2' es positivo
|
214 |
if label.lower() == "positive" or label.lower() == "label_2":
|
215 |
emoji = "😊"
|
216 |
+
description = "Positive sentiment detected." # Mensaje más corto
|
217 |
color_class = "sentiment-positive"
|
218 |
elif label.lower() == "negative" or label.lower() == "label_0":
|
219 |
emoji = "😠"
|
220 |
+
description = "Negative sentiment detected." # Mensaje más corto
|
221 |
color_class = "sentiment-negative"
|
222 |
elif label.lower() == "neutral" or label.lower() == "label_1":
|
223 |
emoji = "😐"
|
224 |
+
description = "Neutral sentiment detected." # Mensaje más corto
|
225 |
color_class = "sentiment-neutral"
|
226 |
else:
|
227 |
emoji = "❓"
|
228 |
+
description = "Sentiment not determined." # Mensaje más corto
|
229 |
color_class = ""
|
230 |
|
231 |
return f"<div class='sentiment-display {color_class}'>{emoji} {label.upper()} ({score:.2f})</div>" + \
|
232 |
+
f"<p style='color: #FFFFFF; font-size: 0.75em; margin-top: 3px; margin-bottom: 0;'>{description}</p>" # Asegurar que la descripción sea pequeña
|
233 |
|
234 |
# --- Sentiment Analysis Function ---
|
235 |
def analyze_sentiment(text):
|
236 |
if not model_loaded_successfully:
|
237 |
return (
|
238 |
+
"<div class='sentiment-display'>⚠️ Model Error ⚠️</div><p style='color: #FFFFFF; font-size: 0.75em;'>Model not loaded.</p>", # Mensaje más corto
|
239 |
{},
|
240 |
{"error": "Model loading failed."}
|
241 |
)
|
242 |
|
243 |
if not text.strip():
|
244 |
return (
|
245 |
+
"<div class='sentiment-display'>✍️ Enter text ✍️</div><p style='color: #FFFFFF; font-size: 0.75em;'>Type text to analyze.</p>", # Mensaje más corto
|
246 |
{},
|
247 |
{"info": "No text entered."}
|
248 |
)
|
|
|
264 |
|
265 |
except Exception as e:
|
266 |
return (
|
267 |
+
f"<div class='sentiment-display'>❌ Error ❌</div><p style='color: #FFFFFF; font-size: 0.75em;'>Analysis failed.</p>", # Mensaje más corto
|
268 |
{},
|
269 |
{"error_message": str(e)}
|
270 |
)
|
|
|
272 |
# --- Gradio Interface ---
|
273 |
with gr.Blocks(css=custom_css, theme=None) as demo:
|
274 |
gr.Markdown("<h1 style='color: #00BFFF;'>🌌 Sentiment Analyzer 🌌</h1>")
|
275 |
+
gr.Markdown("<p style='color: #AAB7C4;'>Analyze the emotional tone of your English text.</p>") # Párrafo más corto
|
276 |
|
277 |
with gr.Column(elem_classes="gradio-container"):
|
278 |
text_input = gr.Textbox(
|
279 |
+
lines=2, # REDUCIDO A 2 LÍNEAS
|
280 |
placeholder="Type your English text here...",
|
281 |
label="Your Text",
|
282 |
interactive=True,
|
|
|
285 |
analyze_btn = gr.Button("Analyze Sentiment", variant="primary")
|
286 |
|
287 |
gr.Markdown("<hr>")
|
288 |
+
gr.Markdown("<h3 style='color: #00BFFF;'>Try examples:</h3>") # Título de ejemplos más corto
|
289 |
|
290 |
+
with gr.Row():
|
291 |
+
examples = gr.Examples(
|
292 |
+
examples=[
|
293 |
+
["Amazing product!"], # Ejemplos más cortos
|
294 |
+
["Very slow service."],
|
295 |
+
["Light rain tomorrow."],
|
296 |
+
["Fantastic experience!"],
|
297 |
+
["Frustrated with internet."],
|
298 |
+
["Meeting concluded."]
|
299 |
+
],
|
300 |
+
inputs=text_input,
|
301 |
+
fn=analyze_sentiment,
|
302 |
+
outputs=[gr.HTML(label="Sentiment"), gr.Label(num_top_classes=3, label="Scores"), gr.JSON(label="Raw Output", visible=False)], # Labels de salida más cortos
|
303 |
+
cache_examples=False,
|
304 |
+
elem_classes="example-buttons-row"
|
305 |
+
)
|
306 |
|
307 |
gr.Markdown("<hr>")
|
308 |
+
gr.Markdown("<h2 style='color: #00BFFF;'>📊 Results</h2>") # Título de resultados más corto
|
309 |
|
310 |
overall_sentiment_output = gr.HTML(label="Overall Sentiment")
|
311 |
confidence_scores_output = gr.Label(num_top_classes=3, label="Confidence Scores")
|
|
|
312 |
raw_output = gr.JSON(label="Raw Model Output", visible=False)
|
313 |
|
314 |
# --- Event Listeners ---
|
|
|
321 |
fn=analyze_sentiment,
|
322 |
inputs=text_input,
|
323 |
outputs=[overall_sentiment_output, confidence_scores_output, raw_output],
|
324 |
+
# live=True
|
325 |
)
|
326 |
|
327 |
# Launch the Gradio application
|