Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -172,7 +172,7 @@ def predict_audio_stream(audio_data, sample_rate):
|
|
| 172 |
crying_probabilities = probabilities[:, 1]
|
| 173 |
avg_crying_probability = crying_probabilities.mean()
|
| 174 |
|
| 175 |
-
if avg_crying_probability < 0.
|
| 176 |
|
| 177 |
inputs = preprocess_audio(audio_segments)
|
| 178 |
with torch.no_grad():
|
|
@@ -199,6 +199,7 @@ def update_status_to_predicting(audio, visual_threshold):
|
|
| 199 |
return f"Esperando... Decibelios: {db_level}"
|
| 200 |
else:
|
| 201 |
return f"Prediciendo... Decibelios: {db_level}"
|
|
|
|
| 202 |
|
| 203 |
#Función que realiza la predicción
|
| 204 |
def capture_and_predict(audio,visual_threshold, sample_rate=16000, duration=5):
|
|
@@ -285,10 +286,6 @@ my_theme = gr.themes.Soft(
|
|
| 285 |
def mostrar_pagina_1():
|
| 286 |
return gr.update(visible=False), gr.update(visible=True)
|
| 287 |
|
| 288 |
-
#Función para mostrar la página del Monitor
|
| 289 |
-
def mostrar_pagina_2():
|
| 290 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 291 |
-
|
| 292 |
#Función para regresar a la pantalla inicial
|
| 293 |
def redirigir_a_pantalla_inicial():
|
| 294 |
return gr.update(visible=True), gr.update(visible=False)
|
|
@@ -335,18 +332,14 @@ with gr.Blocks(theme = my_theme) as demo:
|
|
| 335 |
|
| 336 |
with gr.Row():
|
| 337 |
with gr.Column():
|
| 338 |
-
gr.
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
with gr.Column():
|
| 342 |
-
gr.Markdown("<h2>Monitor</h2>")
|
| 343 |
-
boton_pagina_2 = gr.Button("Prueba el monitor")
|
| 344 |
-
gr.Markdown("<p>Un monitor inteligente que detecta si tu hijo está llorando y te indica el motivo antes de que puedas levantarte del sofá</p>")
|
| 345 |
-
|
| 346 |
with gr.Column(visible=False) as pagina_1:
|
| 347 |
with gr.Row():
|
| 348 |
with gr.Column():
|
| 349 |
gr.Markdown("<h2>Predictor</h2>")
|
|
|
|
| 350 |
audio_input = gr.Audio(type="numpy", label="Baby recorder")
|
| 351 |
classify_btn = gr.Button("¿Por qué llora?")
|
| 352 |
classification_output = gr.Textbox(label="Tu bebé llora por:")
|
|
@@ -354,14 +347,40 @@ with gr.Blocks(theme = my_theme) as demo:
|
|
| 354 |
classify_btn.click(predict_audio, inputs=audio_input, outputs=classification_output)
|
| 355 |
audio_input.change(fn=clear_audio_input, inputs=audio_input, outputs=classification_output)
|
| 356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
|
|
|
| 358 |
with gr.Column():
|
| 359 |
gr.Markdown("<h2>Assistant</h2>")
|
|
|
|
| 360 |
system_message = "Eres un chatbot especializado en el cuidado y la salud de los bebés. Estás dispuesto a ayudar amablemente a cualquier padre que tenga dudas o preocupaciones sobre su hijo o hija."
|
| 361 |
max_tokens = 512
|
| 362 |
temperature = 0.7
|
| 363 |
top_p = 0.95
|
| 364 |
-
|
| 365 |
chatbot = gr.ChatInterface(
|
| 366 |
respond,
|
| 367 |
additional_inputs=[
|
|
@@ -371,38 +390,13 @@ with gr.Blocks(theme = my_theme) as demo:
|
|
| 371 |
gr.State(value=top_p)
|
| 372 |
],
|
| 373 |
)
|
| 374 |
-
|
| 375 |
gr.Markdown("Este chatbot no sustituye a un profesional de la salud. Ante cualquier preocupación o duda, consulta con tu pediatra.")
|
| 376 |
|
| 377 |
boton_volver_inicio_1 = gr.Button("Volver a la pantalla inicial")
|
| 378 |
boton_volver_inicio_1.click(redirigir_a_pantalla_inicial, inputs=None, outputs=[pantalla_inicial, pagina_1])
|
| 379 |
|
| 380 |
-
with gr.Column(visible=False) as pagina_2:
|
| 381 |
-
|
| 382 |
-
gr.Markdown("<h2>Monitor</h2>")
|
| 383 |
-
gr.Markdown("<h4 style='text-align: center; font-size: 1.5em'>Detección en tiempo real del llanto del bebé</h4>")
|
| 384 |
-
|
| 385 |
-
audio_stream = gr.Audio(sources=["microphone"], streaming=True)
|
| 386 |
-
|
| 387 |
-
threshold_db = gr.Slider(minimum=0, maximum=200, step=1, value=50, label="Umbral de dB para activar la predicción")
|
| 388 |
-
|
| 389 |
-
status_label = gr.Textbox(value="Esperando...", label="Estado")
|
| 390 |
-
prediction_label = gr.Textbox(label="Predicción")
|
| 391 |
-
|
| 392 |
-
audio_stream.stream(
|
| 393 |
-
fn=update_status_to_predicting,
|
| 394 |
-
inputs=[audio_stream, threshold_db],
|
| 395 |
-
outputs=status_label
|
| 396 |
-
)
|
| 397 |
-
|
| 398 |
-
# Captura el audio y realiza la predicción si se supera el umbral
|
| 399 |
-
audio_stream.stream(
|
| 400 |
-
fn=capture_and_predict,
|
| 401 |
-
inputs=[audio_stream,threshold_db],
|
| 402 |
-
outputs=prediction_label
|
| 403 |
-
)
|
| 404 |
|
| 405 |
boton_pagina_1.click(mostrar_pagina_1, inputs=None, outputs=[pantalla_inicial, pagina_1])
|
| 406 |
-
boton_pagina_2.click(mostrar_pagina_2, inputs=None, outputs=[pantalla_inicial, pagina_2])
|
| 407 |
|
| 408 |
demo.launch()
|
|
|
|
| 172 |
crying_probabilities = probabilities[:, 1]
|
| 173 |
avg_crying_probability = crying_probabilities.mean()
|
| 174 |
|
| 175 |
+
if avg_crying_probability < 0.25:
|
| 176 |
|
| 177 |
inputs = preprocess_audio(audio_segments)
|
| 178 |
with torch.no_grad():
|
|
|
|
| 199 |
return f"Esperando... Decibelios: {db_level}"
|
| 200 |
else:
|
| 201 |
return f"Prediciendo... Decibelios: {db_level}"
|
| 202 |
+
time.sleep(5)
|
| 203 |
|
| 204 |
#Función que realiza la predicción
|
| 205 |
def capture_and_predict(audio,visual_threshold, sample_rate=16000, duration=5):
|
|
|
|
| 286 |
def mostrar_pagina_1():
|
| 287 |
return gr.update(visible=False), gr.update(visible=True)
|
| 288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
#Función para regresar a la pantalla inicial
|
| 290 |
def redirigir_a_pantalla_inicial():
|
| 291 |
return gr.update(visible=True), gr.update(visible=False)
|
|
|
|
| 332 |
|
| 333 |
with gr.Row():
|
| 334 |
with gr.Column():
|
| 335 |
+
boton_pagina_1 = gr.Button("¡Prueba nuestros modelos!")
|
| 336 |
+
gr.Markdown("<p>Descubre por qué llora tu bebé, prueba nuestro monitor inteligente y resuelve dudas sobre el cuidado de tu pequeño con nuestras herramientas de última tecnología</p>")
|
| 337 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
with gr.Column(visible=False) as pagina_1:
|
| 339 |
with gr.Row():
|
| 340 |
with gr.Column():
|
| 341 |
gr.Markdown("<h2>Predictor</h2>")
|
| 342 |
+
gr.Markdown("<h4 style='text-align: center; font-size: 1.5em'>Descubre por qué tu bebé está llorando</h4>")
|
| 343 |
audio_input = gr.Audio(type="numpy", label="Baby recorder")
|
| 344 |
classify_btn = gr.Button("¿Por qué llora?")
|
| 345 |
classification_output = gr.Textbox(label="Tu bebé llora por:")
|
|
|
|
| 347 |
classify_btn.click(predict_audio, inputs=audio_input, outputs=classification_output)
|
| 348 |
audio_input.change(fn=clear_audio_input, inputs=audio_input, outputs=classification_output)
|
| 349 |
|
| 350 |
+
with gr.Column():
|
| 351 |
+
|
| 352 |
+
gr.Markdown("<h2>Monitor</h2>")
|
| 353 |
+
gr.Markdown("<h4 style='text-align: center; font-size: 1.5em'>Detecta en tiempo real si tu bebé está llorando</h4>")
|
| 354 |
+
|
| 355 |
+
audio_stream = gr.Audio(sources=["microphone"], streaming=True)
|
| 356 |
+
|
| 357 |
+
threshold_db = gr.Slider(minimum=0, maximum=200, step=1, value=50, label="Umbral de dB para activar la predicción")
|
| 358 |
+
|
| 359 |
+
status_label = gr.Textbox(value="Esperando...", label="Estado")
|
| 360 |
+
prediction_label = gr.Textbox(label="Predicción")
|
| 361 |
+
|
| 362 |
+
audio_stream.stream(
|
| 363 |
+
fn=update_status_to_predicting,
|
| 364 |
+
inputs=[audio_stream, threshold_db],
|
| 365 |
+
outputs=status_label
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
# Captura el audio y realiza la predicción si se supera el umbral
|
| 369 |
+
audio_stream.stream(
|
| 370 |
+
fn=capture_and_predict,
|
| 371 |
+
inputs=[audio_stream,threshold_db],
|
| 372 |
+
outputs=prediction_label
|
| 373 |
+
)
|
| 374 |
|
| 375 |
+
with gr.Row():
|
| 376 |
with gr.Column():
|
| 377 |
gr.Markdown("<h2>Assistant</h2>")
|
| 378 |
+
gr.Markdown("<h4 style='text-align: center; font-size: 1.5em'>Pregunta a nuestro asistente cualquier duda que tengas sobre tu pequeño</h4>")
|
| 379 |
system_message = "Eres un chatbot especializado en el cuidado y la salud de los bebés. Estás dispuesto a ayudar amablemente a cualquier padre que tenga dudas o preocupaciones sobre su hijo o hija."
|
| 380 |
max_tokens = 512
|
| 381 |
temperature = 0.7
|
| 382 |
top_p = 0.95
|
| 383 |
+
|
| 384 |
chatbot = gr.ChatInterface(
|
| 385 |
respond,
|
| 386 |
additional_inputs=[
|
|
|
|
| 390 |
gr.State(value=top_p)
|
| 391 |
],
|
| 392 |
)
|
| 393 |
+
|
| 394 |
gr.Markdown("Este chatbot no sustituye a un profesional de la salud. Ante cualquier preocupación o duda, consulta con tu pediatra.")
|
| 395 |
|
| 396 |
boton_volver_inicio_1 = gr.Button("Volver a la pantalla inicial")
|
| 397 |
boton_volver_inicio_1.click(redirigir_a_pantalla_inicial, inputs=None, outputs=[pantalla_inicial, pagina_1])
|
| 398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
boton_pagina_1.click(mostrar_pagina_1, inputs=None, outputs=[pantalla_inicial, pagina_1])
|
|
|
|
| 401 |
|
| 402 |
demo.launch()
|