cobramv12 commited on
Commit
b552fde
verified
1 Parent(s): a6c4f3a

Fix: Certified Gradio 5 setup for ZeroGPU compatibility

Browse files
Files changed (1) hide show
  1. app.py +21 -36
app.py CHANGED
@@ -1,42 +1,27 @@
1
  import sys
2
  import os
3
 
4
- # --- PARCHE DE EMERGENCIA DE NIVEL 3 (INYECCI脫N DE MEMORIA) ---
5
- import gradio_client.utils as client_utils
6
-
7
- # Guardamos la funci贸n original por si acaso
8
- original_get_type = client_utils.get_type
9
-
10
- def patched_get_type(schema):
11
- # Si el esquema es un booleano (el error detectado), devolvemos "Any" y evitamos el colapso
12
- if isinstance(schema, bool):
13
- return "Any"
14
- return original_get_type(schema)
15
-
16
- # Inyectamos nuestro parche directamente en la librer铆a cargada
17
- client_utils.get_type = patched_get_type
18
-
19
- # Tambi茅n parcheamos la funci贸n recursiva para mayor seguridad
20
- original_json_to_python = client_utils.json_schema_to_python_type
21
- def patched_json_to_python(schema, defs=None):
22
- if isinstance(schema, bool):
23
- return "Any"
24
- try:
25
- return original_json_to_python(schema, defs)
26
- except:
27
- return "Any"
28
-
29
- client_utils.json_schema_to_python_type = patched_json_to_python
30
- client_utils._json_schema_to_python_type = patched_json_to_python
31
-
32
- import gradio as gr
33
- # Anulamos la generaci贸n de API en el objeto Blocks
34
- def fake_get_api_info(self):
35
- return {"components": {}, "endpoints": {}}
36
- gr.Blocks.get_api_info = fake_get_api_info
37
- # -----------------------------------------------------------
38
 
39
  import spaces
 
40
  import torch
41
  import numpy as np
42
  from PIL import Image
@@ -118,5 +103,5 @@ with gr.Blocks(title="Image Utility v2.1") as demo:
118
  v_out = gr.Video(label="Sequence Output")
119
  v_btn.click(generate_video, [v_p, v_img, v_ls], v_out)
120
 
121
- # Lanzamiento forzado para evitar el error de localhost
122
- demo.queue().launch(server_name="0.0.0.0", server_port=7860, show_api=False, share=False)
 
1
  import sys
2
  import os
3
 
4
+ # --- PARCHE DE COMPATIBILIDAD INVESTIGADO (CR脥TICO) ---
5
+ # Este parche corrige el bug de 'bool' en gradio_client que afecta a Gradio 5
6
+ try:
7
+ import gradio_client.utils as client_utils
8
+ old_get_type = client_utils.get_type
9
+ def new_get_type(schema):
10
+ if isinstance(schema, bool): return "Any"
11
+ return old_get_type(schema)
12
+ client_utils.get_type = new_get_type
13
+
14
+ old_json_to_python = client_utils._json_schema_to_python_type
15
+ def new_json_to_python(schema, defs=None):
16
+ if isinstance(schema, bool): return "Any"
17
+ return old_json_to_python(schema, defs)
18
+ client_utils._json_schema_to_python_type = new_json_to_python
19
+ except Exception as e:
20
+ print(f"Aviso: No se pudo aplicar el parche de gradio_client: {e}")
21
+ # ------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  import spaces
24
+ import gradio as gr
25
  import torch
26
  import numpy as np
27
  from PIL import Image
 
103
  v_out = gr.Video(label="Sequence Output")
104
  v_btn.click(generate_video, [v_p, v_img, v_ls], v_out)
105
 
106
+ # Al usar SDK nativo, no definimos server_name ni port. HuggingFace lo inyecta solo.
107
+ demo.launch(show_api=False)