Update app.py
Browse files
app.py
CHANGED
|
@@ -191,66 +191,75 @@ theme = gr.themes.Base(
|
|
| 191 |
neutral_hue="neutral",
|
| 192 |
)
|
| 193 |
|
|
|
|
|
|
|
|
|
|
| 194 |
with gr.Blocks(theme=theme) as iface:
|
| 195 |
gr.Markdown("# Aplicaci贸n de Procesamiento de Audio y PDFs")
|
| 196 |
|
| 197 |
iterative_output = gr.Textbox(
|
| 198 |
label="Registro Cl铆nico Organizado",
|
| 199 |
value="""
|
| 200 |
-
MOTIVO DE CONSULTA:
|
| 201 |
-
|
| 202 |
-
ENFERMEDAD ACTUAL:
|
| 203 |
-
|
| 204 |
-
REVISI脫N POR SISTEMAS:
|
| 205 |
-
|
| 206 |
-
ANTECEDENTES:
|
| 207 |
-
**Patol贸gicos:
|
| 208 |
-
** Al茅rgicos:
|
| 209 |
-
** T贸xicos:
|
| 210 |
-
** Familiares:
|
| 211 |
-
** Transfusionales:
|
| 212 |
-
** Traum谩ticos:
|
| 213 |
-
** Ginecol贸gicos:
|
| 214 |
-
** Quir煤rgicos:
|
| 215 |
-
** Estado de vacunaci贸n:
|
| 216 |
-
** Hospitalizaciones previas:
|
| 217 |
-
** Medicamentos:
|
| 218 |
-
|
| 219 |
-
AYUDAS DIAGNOSTICAS:
|
| 220 |
-
""",
|
| 221 |
lines=20,
|
| 222 |
)
|
| 223 |
-
|
| 224 |
-
current_state
|
| 225 |
|
| 226 |
-
audio_filepath = gr.Audio(
|
| 227 |
-
|
| 228 |
-
)
|
| 229 |
-
pdf_files = gr.File(
|
| 230 |
-
file_types=[".pdf"],
|
| 231 |
-
label="Subir PDFs (puedes subir m煤ltiples archivos)",
|
| 232 |
-
file_count="multiple"
|
| 233 |
-
)
|
| 234 |
debug_output = gr.Textbox(label="Informaci贸n de Depuraci贸n", lines=10)
|
| 235 |
-
|
| 236 |
-
def
|
| 237 |
-
print(f"
|
| 238 |
# Asegurar que current_text tiene un valor
|
| 239 |
-
if not current_text.strip():
|
| 240 |
current_text = iterative_output.value
|
| 241 |
updated_text, debug_info = process_input(audio_filepath, pdfs, current_text)
|
| 242 |
-
|
|
|
|
|
|
|
| 243 |
|
| 244 |
-
#
|
| 245 |
audio_filepath.change(
|
| 246 |
-
fn=
|
| 247 |
-
inputs=[audio_filepath, pdf_files,
|
| 248 |
outputs=[iterative_output, debug_output]
|
| 249 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
pdf_files.change(
|
| 251 |
-
fn=
|
| 252 |
-
inputs=[audio_filepath, pdf_files,
|
| 253 |
outputs=[iterative_output, debug_output]
|
| 254 |
)
|
| 255 |
|
| 256 |
-
iface.launch(auth=[("her", "her")])
|
|
|
|
| 191 |
neutral_hue="neutral",
|
| 192 |
)
|
| 193 |
|
| 194 |
+
current_state = gr.State()
|
| 195 |
+
|
| 196 |
+
|
| 197 |
with gr.Blocks(theme=theme) as iface:
|
| 198 |
gr.Markdown("# Aplicaci贸n de Procesamiento de Audio y PDFs")
|
| 199 |
|
| 200 |
iterative_output = gr.Textbox(
|
| 201 |
label="Registro Cl铆nico Organizado",
|
| 202 |
value="""
|
| 203 |
+
MOTIVO DE CONSULTA:
|
| 204 |
+
|
| 205 |
+
ENFERMEDAD ACTUAL:
|
| 206 |
+
|
| 207 |
+
REVISI脫N POR SISTEMAS:
|
| 208 |
+
|
| 209 |
+
ANTECEDENTES:
|
| 210 |
+
**Patol贸gicos:
|
| 211 |
+
** Al茅rgicos:
|
| 212 |
+
** T贸xicos:
|
| 213 |
+
** Familiares:
|
| 214 |
+
** Transfusionales:
|
| 215 |
+
** Traum谩ticos:
|
| 216 |
+
** Ginecol贸gicos:
|
| 217 |
+
** Quir煤rgicos:
|
| 218 |
+
** Estado de vacunaci贸n:
|
| 219 |
+
** Hospitalizaciones previas:
|
| 220 |
+
** Medicamentos:
|
| 221 |
+
|
| 222 |
+
AYUDAS DIAGNOSTICAS:
|
| 223 |
+
""",
|
| 224 |
lines=20,
|
| 225 |
)
|
| 226 |
+
# Actualizamos el estado inicial
|
| 227 |
+
current_state.value = iterative_output.value
|
| 228 |
|
| 229 |
+
audio_filepath = gr.Audio(sources=["microphone"], type="filepath", label="Entrada de Audio")
|
| 230 |
+
pdf_files = gr.File(file_types=[".pdf"], label="Subir PDFs (puedes subir m煤ltiples archivos)", file_count="multiple")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
debug_output = gr.Textbox(label="Informaci贸n de Depuraci贸n", lines=10)
|
| 232 |
+
|
| 233 |
+
def on_audio_change(audio_filepath, pdfs, current_text):
|
| 234 |
+
print(f"on_audio_change: audio_filepath = {audio_filepath}")
|
| 235 |
# Asegurar que current_text tiene un valor
|
| 236 |
+
if not current_text or not current_text.strip():
|
| 237 |
current_text = iterative_output.value
|
| 238 |
updated_text, debug_info = process_input(audio_filepath, pdfs, current_text)
|
| 239 |
+
# Actualizar el estado con el nuevo texto
|
| 240 |
+
current_state.value = updated_text
|
| 241 |
+
return updated_text, debug_info
|
| 242 |
|
| 243 |
+
# Configurar el evento 'change' en el componente de audio
|
| 244 |
audio_filepath.change(
|
| 245 |
+
fn=on_audio_change,
|
| 246 |
+
inputs=[audio_filepath, pdf_files, current_state],
|
| 247 |
outputs=[iterative_output, debug_output]
|
| 248 |
)
|
| 249 |
+
|
| 250 |
+
# Opcional: Si deseas que el procesamiento tambi茅n ocurra cuando se suben PDFs
|
| 251 |
+
def on_pdfs_change(audio_filepath, pdfs, current_text):
|
| 252 |
+
print(f"on_pdfs_change: pdfs = {pdfs}")
|
| 253 |
+
if not current_text or not current_text.strip():
|
| 254 |
+
current_text = iterative_output.value
|
| 255 |
+
updated_text, debug_info = process_input(audio_filepath, pdfs, current_text)
|
| 256 |
+
current_state.value = updated_text
|
| 257 |
+
return updated_text, debug_info
|
| 258 |
+
|
| 259 |
pdf_files.change(
|
| 260 |
+
fn=on_pdfs_change,
|
| 261 |
+
inputs=[audio_filepath, pdf_files, current_state],
|
| 262 |
outputs=[iterative_output, debug_output]
|
| 263 |
)
|
| 264 |
|
| 265 |
+
iface.launch(auth=[("her", "her")])
|