Gabriel Ramos commited on
Commit
fef46a3
·
1 Parent(s): abe558e

fix: Corrigir bug Gradio 4.44.0 e adicionar error handling

Browse files
Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +27 -6
  3. implementation_plan.md +59 -0
  4. requirements.txt +1 -1
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 📄
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: "4.44.0"
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: "4.44.1"
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -483,9 +483,30 @@ if __name__ == "__main__":
483
  # Cria e lança a interface
484
  demo = create_interface()
485
 
486
- demo.queue().launch(
487
- server_name="0.0.0.0",
488
- server_port=7860,
489
- max_file_size=f"{config.MAX_FILE_SIZE_MB}mb",
490
- show_error=True,
491
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
  # Cria e lança a interface
484
  demo = create_interface()
485
 
486
+ # Detecta se está em ambiente containerizado (HF Spaces)
487
+ is_containerized = HAS_SPACES or os.environ.get("SPACE_ID") is not None
488
+
489
+ try:
490
+ demo.queue().launch(
491
+ server_name="0.0.0.0",
492
+ server_port=7860,
493
+ max_file_size=f"{config.MAX_FILE_SIZE_MB}mb",
494
+ show_error=True,
495
+ share=is_containerized, # Habilita link compartilhável em containers
496
+ )
497
+ except Exception as e:
498
+ logger.error(f"Erro ao iniciar aplicação: {e}")
499
+ logger.info("Tentando iniciar com configuração alternativa...")
500
+
501
+ # Fallback: tenta com share=True
502
+ try:
503
+ demo.queue().launch(
504
+ server_name="0.0.0.0",
505
+ server_port=7860,
506
+ max_file_size=f"{config.MAX_FILE_SIZE_MB}mb",
507
+ show_error=True,
508
+ share=True,
509
+ )
510
+ except Exception as fallback_error:
511
+ logger.critical(f"Falha crítica ao iniciar: {fallback_error}")
512
+ raise
implementation_plan.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Implementation Plan
2
+
3
+ [Overview]
4
+ Fix the Gradio JSON schema TypeError that prevents the Docling Document Processor from starting, caused by a bug in Gradio 4.44.0 when processing boolean schema values.
5
+
6
+ The application fails to launch due to a TypeError in Gradio's client utils module where the code attempts to iterate over a boolean value when processing JSON schema information. This is a known issue in Gradio 4.44.0 that occurs during API info generation. Additionally, the application encounters localhost accessibility issues in containerized environments.
7
+
8
+ [Types]
9
+ Update dependency versions and add error handling for schema processing.
10
+
11
+ The main type system changes involve updating Gradio from 4.44.0 to 4.44.1+ to resolve the JSON schema processing bug, and adding configuration options for shareable links to handle localhost accessibility issues in containerized environments.
12
+
13
+ [Files]
14
+ Update configuration files and main application entry point.
15
+
16
+ - **requirements.txt**: Update Gradio version from 4.44.0 to 4.44.1 or higher
17
+ - **app.py**: Add share=True parameter to demo.launch() and implement error handling for container environments
18
+ - **config.py**: Add new configuration constants for shareable links and localhost handling
19
+ - **README.md**: Update documentation with troubleshooting section for common runtime errors
20
+
21
+ [Functions]
22
+ Modify the application launch function and add error handling.
23
+
24
+ - **app.py process_documents()**: No changes needed - function is working correctly
25
+ - **app.py create_interface()**: No changes needed - interface creation is working
26
+ - **app.py main block**: Modify demo.launch() call to include share=True parameter and add try-catch for startup errors
27
+ - **New function handle_launch_error()**: Add error handling for containerized environments with fallback options
28
+
29
+ [Classes]
30
+ No class modifications required - the error is in the Gradio framework, not application classes.
31
+
32
+ The DoclingProcessor, JSONFormatter, and MarkdownFormatter classes are functioning correctly. The issue is external to the application logic.
33
+
34
+ [Dependencies]
35
+ Update Gradio framework version to resolve the JSON schema bug.
36
+
37
+ - **gradio**: Upgrade from 4.44.0 to 4.44.1+ (current latest is 4.44.1)
38
+ - **spaces**: No changes needed - current version is compatible
39
+ - **docling**: No changes needed - current version is working
40
+ - **Additional testing**: Verify all dependencies work with updated Gradio version
41
+
42
+ [Testing]
43
+ Verify the application starts successfully and handles edge cases.
44
+
45
+ - **Unit tests**: Run existing test suite to ensure no regressions
46
+ - **Integration tests**: Test file upload and processing functionality
47
+ - **Container tests**: Verify application launches in Docker/containerized environments
48
+ - **Error handling tests**: Test fallback scenarios when localhost is not accessible
49
+
50
+ [Implementation Order]
51
+ Execute fixes in sequence to resolve the startup error and ensure robust operation.
52
+
53
+ 1. Update requirements.txt to specify Gradio 4.44.1 or higher
54
+ 2. Modify app.py main block to add share=True parameter and error handling
55
+ 3. Add configuration options in config.py for shareable links
56
+ 4. Test the application startup locally
57
+ 5. Verify containerized deployment works correctly
58
+ 6. Run full test suite to ensure no regressions
59
+ 7. Update documentation with troubleshooting information
requirements.txt CHANGED
@@ -3,7 +3,7 @@
3
  # =============================================================================
4
 
5
  # Framework de interface web
6
- gradio>=4.44.0
7
 
8
  # Processamento de documentos
9
  docling>=2.31.0
 
3
  # =============================================================================
4
 
5
  # Framework de interface web
6
+ gradio>=4.44.1
7
 
8
  # Processamento de documentos
9
  docling>=2.31.0