Marcos12886 commited on
Commit
0f202d9
·
verified ·
1 Parent(s): 017e65e

Última mejora etiquetas

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -40,7 +40,11 @@ def predict(audio_path_pred):
40
  label_class = id2label_class[predicted_class_ids_class]
41
  label_mapping = {0: 'Cansancio/Incomodidad', 1: 'Dolor', 2: 'Hambre', 3: 'Problemas para respirar'}
42
  label_class = label_mapping.get(predicted_class_ids_class, label_class)
43
- return label_class
 
 
 
 
44
 
45
  def predict_stream(audio_path_stream):
46
  with torch.no_grad():
@@ -70,14 +74,24 @@ def mostrar_decibelios(audio_path_stream, visual_threshold):
70
  status = "Prediciendo..."
71
  else:
72
  status = "Esperando..."
73
- return f"<h3 style='text-align: center; font-size: 1.5em;'>{status} Decibelios: {db_level:.2f}</h3>"
 
 
 
 
 
74
 
75
  def predict_stream_decib(audio_path_stream, visual_threshold):
76
  db_level = decibelios(audio_path_stream)
77
  if db_level > visual_threshold:
78
- return display_prediction_stream(audio_path_stream)
79
  else:
80
- return ""
 
 
 
 
 
81
 
82
  def chatbot_config(message, history: list[tuple[str, str]]):
83
  system_message = "You are a Chatbot specialized in baby health and care."
@@ -239,7 +253,7 @@ with gr.Blocks(theme=my_theme) as demo:
239
  audio_stream.stream(
240
  mostrar_decibelios,
241
  inputs=[audio_stream, threshold_db],
242
- outputs=gr.HTML(value="<h3 style='text-align: center; font-size: 1.5em;'>Esperando...</h3>")
243
  )
244
  audio_stream.stream(
245
  predict_stream_decib,
 
40
  label_class = id2label_class[predicted_class_ids_class]
41
  label_mapping = {0: 'Cansancio/Incomodidad', 1: 'Dolor', 2: 'Hambre', 3: 'Problemas para respirar'}
42
  label_class = label_mapping.get(predicted_class_ids_class, label_class)
43
+ return f"""
44
+ <div style='text-align: center; font-size: 1.5em'>
45
+ <span style='display: inline-block; min-width: 300px;'>{label_class}</span>
46
+ </div>
47
+ """
48
 
49
  def predict_stream(audio_path_stream):
50
  with torch.no_grad():
 
74
  status = "Prediciendo..."
75
  else:
76
  status = "Esperando..."
77
+ return f"""
78
+ <div style='text-align: center; font-size: 1.5em'>
79
+ <span>{status}</span>
80
+ <span style='display: inline-block; min-width: 120px;'>Decibelios: {db_level:.2f}</span>
81
+ </div>
82
+ """
83
 
84
  def predict_stream_decib(audio_path_stream, visual_threshold):
85
  db_level = decibelios(audio_path_stream)
86
  if db_level > visual_threshold:
87
+ prediction = display_prediction_stream(audio_path_stream)
88
  else:
89
+ prediction = ""
90
+ return f"""
91
+ <div style='text-align: center; font-size: 1.5em; min-height: 2em;'>
92
+ <span style='display: inline-block; min-width: 300px;'>{prediction}</span>
93
+ </div>
94
+ """
95
 
96
  def chatbot_config(message, history: list[tuple[str, str]]):
97
  system_message = "You are a Chatbot specialized in baby health and care."
 
253
  audio_stream.stream(
254
  mostrar_decibelios,
255
  inputs=[audio_stream, threshold_db],
256
+ outputs=gr.HTML()
257
  )
258
  audio_stream.stream(
259
  predict_stream_decib,