Spaces:
Runtime error
Runtime error
Fix: System-level monkeypatch for Gradio stability
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
# ---
|
| 5 |
-
# 1. Parche
|
| 6 |
try:
|
| 7 |
import audioop
|
| 8 |
except ImportError:
|
|
@@ -12,15 +12,14 @@ except ImportError:
|
|
| 12 |
except ImportError:
|
| 13 |
pass
|
| 14 |
|
| 15 |
-
# 2. Parche para
|
| 16 |
-
import
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
huggingface_hub.HfFolder = MockHfFolder
|
| 24 |
# ------------------------------------------
|
| 25 |
|
| 26 |
import spaces
|
|
@@ -36,6 +35,9 @@ LTX_MODEL = "Lightricks/LTX-Video"
|
|
| 36 |
LTX_NSFW_LORA = "Lora-Daddy/Ltx2.3-real-nudity-early-alpha-30k-steps"
|
| 37 |
NEG_DEFAULT = "blurry, low quality, bad anatomy, deformed, ugly, watermark, text"
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
def load_t2i(lora_id=None, lora_scale=1.0):
|
| 40 |
from diffusers import StableDiffusionXLPipeline
|
| 41 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
@@ -56,11 +58,12 @@ def load_video():
|
|
| 56 |
except: pass
|
| 57 |
return pipe
|
| 58 |
|
| 59 |
-
@spaces.GPU(duration=
|
| 60 |
def generate_t2i(prompt, neg, lora_id, lora_scale, w, h):
|
| 61 |
pipe = load_t2i(lora_id, lora_scale).to("cuda")
|
| 62 |
img = pipe(prompt=prompt, negative_prompt=neg, num_inference_steps=30,
|
| 63 |
-
guidance_scale=7.0, width=int(w), height=int(h)
|
|
|
|
| 64 |
return img
|
| 65 |
|
| 66 |
@spaces.GPU(duration=200)
|
|
@@ -68,7 +71,7 @@ def generate_video(prompt, init_image, lora_scale):
|
|
| 68 |
from diffusers.utils import export_to_video
|
| 69 |
pipe = load_video().to("cuda")
|
| 70 |
kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49,
|
| 71 |
-
"num_inference_steps": 30}
|
| 72 |
if init_image is not None:
|
| 73 |
kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512))
|
| 74 |
if lora_scale > 0:
|
|
@@ -78,6 +81,7 @@ def generate_video(prompt, init_image, lora_scale):
|
|
| 78 |
export_to_video(output.frames[0], tmp.name, fps=24)
|
| 79 |
return tmp.name
|
| 80 |
|
|
|
|
| 81 |
with gr.Blocks(title="Image Utility v2.1") as demo:
|
| 82 |
gr.HTML("<h1 style='text-align:center;'>🛠 Image Processing Utility v2.1.4</h1>")
|
| 83 |
with gr.Tabs():
|
|
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# --- PARCHE QUIRÚRGICO DE NIVEL SISTEMA ---
|
| 5 |
+
# 1. Parche de audioop para Python 3.13
|
| 6 |
try:
|
| 7 |
import audioop
|
| 8 |
except ImportError:
|
|
|
|
| 12 |
except ImportError:
|
| 13 |
pass
|
| 14 |
|
| 15 |
+
# 2. Parche para el bug de Gradio (TypeError: argument of type 'bool' is not iterable)
|
| 16 |
+
import gradio_client.utils as client_utils
|
| 17 |
+
original_get_type = client_utils.get_type
|
| 18 |
+
def patched_get_type(schema):
|
| 19 |
+
if isinstance(schema, bool):
|
| 20 |
+
return "str" # Evita el colapso si schema es un booleano
|
| 21 |
+
return original_get_type(schema)
|
| 22 |
+
client_utils.get_type = patched_get_type
|
|
|
|
| 23 |
# ------------------------------------------
|
| 24 |
|
| 25 |
import spaces
|
|
|
|
| 35 |
LTX_NSFW_LORA = "Lora-Daddy/Ltx2.3-real-nudity-early-alpha-30k-steps"
|
| 36 |
NEG_DEFAULT = "blurry, low quality, bad anatomy, deformed, ugly, watermark, text"
|
| 37 |
|
| 38 |
+
pipe_t2i = None
|
| 39 |
+
pipe_video = None
|
| 40 |
+
|
| 41 |
def load_t2i(lora_id=None, lora_scale=1.0):
|
| 42 |
from diffusers import StableDiffusionXLPipeline
|
| 43 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
|
|
| 58 |
except: pass
|
| 59 |
return pipe
|
| 60 |
|
| 61 |
+
@spaces.GPU(duration=100)
|
| 62 |
def generate_t2i(prompt, neg, lora_id, lora_scale, w, h):
|
| 63 |
pipe = load_t2i(lora_id, lora_scale).to("cuda")
|
| 64 |
img = pipe(prompt=prompt, negative_prompt=neg, num_inference_steps=30,
|
| 65 |
+
guidance_scale=7.0, width=int(w), height=int(h),
|
| 66 |
+
generator=torch.Generator("cuda").manual_seed(42)).images[0]
|
| 67 |
return img
|
| 68 |
|
| 69 |
@spaces.GPU(duration=200)
|
|
|
|
| 71 |
from diffusers.utils import export_to_video
|
| 72 |
pipe = load_video().to("cuda")
|
| 73 |
kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49,
|
| 74 |
+
"num_inference_steps": 30, "generator": torch.Generator("cuda").manual_seed(42)}
|
| 75 |
if init_image is not None:
|
| 76 |
kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512))
|
| 77 |
if lora_scale > 0:
|
|
|
|
| 81 |
export_to_video(output.frames[0], tmp.name, fps=24)
|
| 82 |
return tmp.name
|
| 83 |
|
| 84 |
+
# UI
|
| 85 |
with gr.Blocks(title="Image Utility v2.1") as demo:
|
| 86 |
gr.HTML("<h1 style='text-align:center;'>🛠 Image Processing Utility v2.1.4</h1>")
|
| 87 |
with gr.Tabs():
|