cobramv12 commited on
Commit
6ae7c5d
verified
1 Parent(s): 3d43ee4

Fix: Runtime memory injection for gradio_client stability

Browse files
Files changed (1) hide show
  1. app.py +36 -19
app.py CHANGED
@@ -1,26 +1,42 @@
1
  import sys
2
  import os
3
 
4
- # --- PARCHE DE SEGURIDAD ABSOLUTA (HfFolder) ---
5
- try:
6
- import huggingface_hub
7
- # Si la pieza falta, la inyectamos manualmente ANTES de cargar Gradio
8
- if not hasattr(huggingface_hub, "HfFolder"):
9
- class MockHfFolder:
10
- @staticmethod
11
- def get_token(): return os.getenv("HF_TOKEN")
12
- @staticmethod
13
- def save_token(token): pass
14
- @staticmethod
15
- def delete_token(): pass
16
- huggingface_hub.HfFolder = MockHfFolder
17
- sys.modules["huggingface_hub.HfFolder"] = MockHfFolder
18
- except:
19
- pass
20
- # -----------------------------------------------
 
 
 
 
 
 
 
 
 
 
21
 
22
- import spaces
23
  import gradio as gr
 
 
 
 
 
 
 
24
  import torch
25
  import numpy as np
26
  from PIL import Image
@@ -102,4 +118,5 @@ with gr.Blocks(title="Image Utility v2.1") as demo:
102
  v_out = gr.Video(label="Sequence Output")
103
  v_btn.click(generate_video, [v_p, v_img, v_ls], v_out)
104
 
105
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
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
  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)