cobramv12 commited on
Commit
6f0f4ea
·
verified ·
1 Parent(s): ba81970

Fix: Switch to Native Gradio SDK for ZeroGPU stability

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -3,14 +3,20 @@ import os
3
  import gc
4
  import torch
5
 
6
- # --- PARCHES ---
7
  try:
8
  import gradio_client.utils as client_utils
 
 
 
9
  def patched_json_schema_to_python_type(schema, defs=None):
10
  if isinstance(schema, bool): return "Any"
11
- return client_utils._json_schema_to_python_type(schema, defs)
 
12
  client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
13
- except: pass
 
 
14
 
15
  import spaces
16
  import gradio as gr
@@ -63,21 +69,18 @@ def generate_t2i(prompt, neg, model_name, lora_id_custom, lora_scale, steps, cfg
63
 
64
  @spaces.GPU(duration=250)
65
  def generate_video(prompt, model_name, lora_name, lora_custom, lora_scale, steps, cfg):
66
- flush() # Limpiar todo antes de empezar
67
  from diffusers import LTXPipeline
68
  from diffusers.utils import export_to_video
69
 
70
  model_id = LTX_MODELS.get(model_name)
71
  lora_id = lora_custom if lora_custom else LTX_LORAS.get(lora_name)
72
 
73
- # CARGA OPTIMIZADA
74
  pipe = LTXPipeline.from_pretrained(
75
  model_id, torch_dtype=torch.bfloat16,
76
  low_cpu_mem_usage=True
77
  )
78
  pipe.to("cuda")
79
-
80
- # IMPORTANTE: Ahorro de memoria para video
81
  pipe.enable_vae_slicing()
82
 
83
  if lora_id:
@@ -85,7 +88,6 @@ def generate_video(prompt, model_name, lora_name, lora_custom, lora_scale, steps
85
  pipe.load_lora_weights(lora_id)
86
  except: pass
87
 
88
- # Generar video (Reducido a 33 frames para evitar timeout/OOM)
89
  output = pipe(
90
  prompt=prompt,
91
  negative_prompt="low quality, blurry, static, distorted",
@@ -106,7 +108,7 @@ def generate_video(prompt, model_name, lora_name, lora_custom, lora_scale, steps
106
 
107
  # --- INTERFAZ ---
108
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
109
- gr.HTML("<h1 style='text-align:center;'>🚀 Studio Privado v2.4 (Ultra-Stable)</h1>")
110
 
111
  with gr.Tabs():
112
  with gr.Tab("🖼 Imagen"):
 
3
  import gc
4
  import torch
5
 
6
+ # --- PARCHE CRÍTICO (FIX RECURSION ERROR) ---
7
  try:
8
  import gradio_client.utils as client_utils
9
+ if not hasattr(client_utils, "_old_json_schema_to_python_type"):
10
+ client_utils._old_json_schema_to_python_type = client_utils._json_schema_to_python_type
11
+
12
  def patched_json_schema_to_python_type(schema, defs=None):
13
  if isinstance(schema, bool): return "Any"
14
+ return client_utils._old_json_schema_to_python_type(schema, defs)
15
+
16
  client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
17
+ print("Gradio Patch v2.5 Applied (Recursion Safe)")
18
+ except Exception as e:
19
+ print(f"Patch Error: {e}")
20
 
21
  import spaces
22
  import gradio as gr
 
69
 
70
  @spaces.GPU(duration=250)
71
  def generate_video(prompt, model_name, lora_name, lora_custom, lora_scale, steps, cfg):
72
+ flush()
73
  from diffusers import LTXPipeline
74
  from diffusers.utils import export_to_video
75
 
76
  model_id = LTX_MODELS.get(model_name)
77
  lora_id = lora_custom if lora_custom else LTX_LORAS.get(lora_name)
78
 
 
79
  pipe = LTXPipeline.from_pretrained(
80
  model_id, torch_dtype=torch.bfloat16,
81
  low_cpu_mem_usage=True
82
  )
83
  pipe.to("cuda")
 
 
84
  pipe.enable_vae_slicing()
85
 
86
  if lora_id:
 
88
  pipe.load_lora_weights(lora_id)
89
  except: pass
90
 
 
91
  output = pipe(
92
  prompt=prompt,
93
  negative_prompt="low quality, blurry, static, distorted",
 
108
 
109
  # --- INTERFAZ ---
110
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
111
+ gr.HTML("<h1 style='text-align:center;'>🚀 Studio Privado v2.5 PRO</h1>")
112
 
113
  with gr.Tabs():
114
  with gr.Tab("🖼 Imagen"):