Maximofn commited on
Commit
6cfec6e
·
1 Parent(s): 76611bf

Refactoriza la interfaz de usuario en `app.py` al eliminar el uso de `gr.Blocks` y simplificar la estructura del código. Se actualiza la función de lanzamiento para utilizar `chat.launch()` en lugar de `demo.launch()`, manteniendo la funcionalidad de la aplicación. Esta modificación mejora la claridad y la gestión de la interfaz de usuario.

Browse files
Files changed (1) hide show
  1. app.py +20 -51
app.py CHANGED
@@ -344,59 +344,28 @@ def respond(message, history: list[tuple[str, str]]):
344
  _flush_langsmith()
345
 
346
 
347
- with gr.Blocks(theme=gr.themes.Monochrome(), css=style) as demo:
348
- gr.ChatInterface(
349
- fn=respond,
350
- # default type keeps string message, keeps compatibility across versions
351
- title="Gmail & Outlook API Helper",
352
- description="Chat para guiar en la creación de API Keys.",
353
- textbox=gr.MultimodalTextbox(
354
- file_types=["image", ".png", ".jpg", ".jpeg", ".webp", ".gif"],
355
- placeholder="Escribe o pega (⌘/Ctrl+V) una imagen o arrástrala aquí",
356
- file_count="multiple",
357
- ),
358
- multimodal=True,
359
- fill_height=True,
360
- examples=[
361
- "¿Cómo creo una API Key de Gmail?",
362
- "Guíame para obtener credenciales de OneDrive",
363
- ],
364
- )
365
-
366
-
367
- # Front-end helper to keep the input focused after responses
368
- AUTOFOCUS_JS = """
369
- () => {
370
- const container = document.querySelector('.gradio-container');
371
- if (!container) return;
372
- const focusInput = () => {
373
- const ta = container.querySelector('textarea');
374
- if (ta) ta.focus();
375
- };
376
- // Focus on initial load
377
- focusInput();
378
- // Re-focus on DOM updates (e.g., after new assistant messages)
379
- const observer = new MutationObserver((mutations) => {
380
- for (const m of mutations) {
381
- if (m.addedNodes && m.addedNodes.length > 0) {
382
- focusInput();
383
- break;
384
- }
385
- }
386
- });
387
- observer.observe(container, { childList: true, subtree: true });
388
- }
389
- """
390
-
391
- # Run once on load to attach the observer and ensure focus
392
- try:
393
- demo.load(None, None, None, js=AUTOFOCUS_JS)
394
- except Exception:
395
- # Best-effort: if load hook signature differs by version, ignore
396
- pass
397
 
398
 
399
  if __name__ == "__main__":
400
- demo.launch()
401
 
402
 
 
344
  _flush_langsmith()
345
 
346
 
347
+ chat = gr.ChatInterface(
348
+ fn=respond,
349
+ # default type keeps string message, keeps compatibility across versions
350
+ title="Gmail & Outlook API Helper",
351
+ description="Chat para guiar en la creación de API Keys.",
352
+ textbox=gr.MultimodalTextbox(
353
+ file_types=["image", ".png", ".jpg", ".jpeg", ".webp", ".gif"],
354
+ placeholder="Escribe o pega (⌘/Ctrl+V) una imagen o arrástrala aquí",
355
+ file_count="multiple",
356
+ ),
357
+ multimodal=True,
358
+ fill_height=True,
359
+ examples=[
360
+ "¿Cómo creo una API Key de Gmail?",
361
+ "Guíame para obtener credenciales de OneDrive",
362
+ ],
363
+ theme=gr.themes.Monochrome(),
364
+ css=style,
365
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
 
367
 
368
  if __name__ == "__main__":
369
+ chat.launch()
370
 
371