Spaces:
Runtime error
Runtime error
Fix: Disable SSR and remove API silencer for stable ZeroGPU connection
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
# --- INYECCIÓN ATÓMICA REFORZADA ---
|
| 5 |
try:
|
| 6 |
import huggingface_hub
|
| 7 |
class MockHfFolder:
|
|
@@ -22,17 +22,10 @@ try:
|
|
| 22 |
except:
|
| 23 |
from unittest.mock import MagicMock
|
| 24 |
sys.modules["audioop"] = MagicMock()
|
| 25 |
-
# ---------------------------------------------
|
| 26 |
-
|
| 27 |
-
import gradio as gr
|
| 28 |
-
|
| 29 |
-
# --- SILENCIADOR DE API ---
|
| 30 |
-
def fake_get_api_info(self, *args, **kwargs):
|
| 31 |
-
return {"components": [], "endpoints": []}
|
| 32 |
-
gr.Blocks.get_api_info = fake_get_api_info
|
| 33 |
-
# ----------------------------------------------------
|
| 34 |
|
| 35 |
import spaces
|
|
|
|
| 36 |
import torch
|
| 37 |
import numpy as np
|
| 38 |
from PIL import Image
|
|
@@ -64,36 +57,26 @@ def load_video():
|
|
| 64 |
def generate_t2i(prompt, neg, lora_id, lora_scale, w, h, init_img):
|
| 65 |
is_img2img = init_img is not None
|
| 66 |
pipe = load_t2i(is_img2img).to("cuda")
|
| 67 |
-
|
| 68 |
if lora_id and len(lora_id.strip()) > 5:
|
| 69 |
try:
|
| 70 |
pipe.load_lora_weights(lora_id.strip())
|
| 71 |
pipe.fuse_lora(lora_scale=lora_scale)
|
| 72 |
except: pass
|
| 73 |
-
|
| 74 |
-
kwargs = {
|
| 75 |
-
"prompt": prompt, "negative_prompt": neg, "num_inference_steps": 30,
|
| 76 |
-
"guidance_scale": 7.0, "generator": torch.Generator("cuda").manual_seed(42)
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
if is_img2img:
|
| 80 |
if isinstance(init_img, dict):
|
| 81 |
-
init_img = init_img["composite"] if "composite" in
|
| 82 |
kwargs["image"] = Image.fromarray(init_img).convert("RGB").resize((int(w), int(h)))
|
| 83 |
-
kwargs["strength"] = 0.6
|
| 84 |
else:
|
| 85 |
-
kwargs["width"] = int(w)
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
img = pipe(**kwargs).images[0]
|
| 89 |
-
return img
|
| 90 |
|
| 91 |
@spaces.GPU(duration=200)
|
| 92 |
def generate_video(prompt, init_image, lora_scale):
|
| 93 |
from diffusers.utils import export_to_video
|
| 94 |
pipe = load_video().to("cuda")
|
| 95 |
-
kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49,
|
| 96 |
-
"num_inference_steps": 30, "generator": torch.Generator("cuda").manual_seed(42)}
|
| 97 |
if init_image is not None:
|
| 98 |
if isinstance(init_image, dict):
|
| 99 |
init_image = init_image["composite"] if "composite" in init_image else init_image["background"]
|
|
@@ -105,7 +88,7 @@ def generate_video(prompt, init_image, lora_scale):
|
|
| 105 |
export_to_video(output.frames[0], tmp.name, fps=24)
|
| 106 |
return tmp.name
|
| 107 |
|
| 108 |
-
with gr.Blocks(title="Image Utility v2.1") as demo:
|
| 109 |
gr.HTML("<h1 style='text-align:center;'>🛠 Image Processing Utility v2.1.4</h1>")
|
| 110 |
with gr.Tabs():
|
| 111 |
with gr.Tab("D-Processor (Image/T2I)"):
|
|
@@ -122,7 +105,6 @@ with gr.Blocks(title="Image Utility v2.1") as demo:
|
|
| 122 |
t2i_btn = gr.Button("Execute Process", variant="primary")
|
| 123 |
t2i_out = gr.Image(label="Output Preview")
|
| 124 |
t2i_btn.click(generate_t2i, [t2i_p, t2i_n, t2i_lora, t2i_ls, t2i_w, t2i_h, t2i_img], t2i_out)
|
| 125 |
-
|
| 126 |
with gr.Tab("M-Sequence (Video)"):
|
| 127 |
with gr.Row():
|
| 128 |
with gr.Column():
|
|
@@ -133,4 +115,4 @@ with gr.Blocks(title="Image Utility v2.1") as demo:
|
|
| 133 |
v_out = gr.Video(label="Sequence Output")
|
| 134 |
v_btn.click(generate_video, [v_p, v_img, v_ls], v_out)
|
| 135 |
|
| 136 |
-
demo.queue().launch(show_api=
|
|
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# --- INYECCIÓN ATÓMICA REFORZADA (HfFolder + audioop) ---
|
| 5 |
try:
|
| 6 |
import huggingface_hub
|
| 7 |
class MockHfFolder:
|
|
|
|
| 22 |
except:
|
| 23 |
from unittest.mock import MagicMock
|
| 24 |
sys.modules["audioop"] = MagicMock()
|
| 25 |
+
# -------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
import spaces
|
| 28 |
+
import gradio as gr
|
| 29 |
import torch
|
| 30 |
import numpy as np
|
| 31 |
from PIL import Image
|
|
|
|
| 57 |
def generate_t2i(prompt, neg, lora_id, lora_scale, w, h, init_img):
|
| 58 |
is_img2img = init_img is not None
|
| 59 |
pipe = load_t2i(is_img2img).to("cuda")
|
|
|
|
| 60 |
if lora_id and len(lora_id.strip()) > 5:
|
| 61 |
try:
|
| 62 |
pipe.load_lora_weights(lora_id.strip())
|
| 63 |
pipe.fuse_lora(lora_scale=lora_scale)
|
| 64 |
except: pass
|
| 65 |
+
kwargs = {"prompt": prompt, "negative_prompt": neg, "num_inference_steps": 30, "guidance_scale": 7.0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
if is_img2img:
|
| 67 |
if isinstance(init_img, dict):
|
| 68 |
+
init_img = init_img["composite"] if "composite" in init_img else init_img["background"]
|
| 69 |
kwargs["image"] = Image.fromarray(init_img).convert("RGB").resize((int(w), int(h)))
|
| 70 |
+
kwargs["strength"] = 0.6
|
| 71 |
else:
|
| 72 |
+
kwargs["width"], kwargs["height"] = int(w), int(h)
|
| 73 |
+
return pipe(**kwargs).images[0]
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
@spaces.GPU(duration=200)
|
| 76 |
def generate_video(prompt, init_image, lora_scale):
|
| 77 |
from diffusers.utils import export_to_video
|
| 78 |
pipe = load_video().to("cuda")
|
| 79 |
+
kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49, "num_inference_steps": 30}
|
|
|
|
| 80 |
if init_image is not None:
|
| 81 |
if isinstance(init_image, dict):
|
| 82 |
init_image = init_image["composite"] if "composite" in init_image else init_image["background"]
|
|
|
|
| 88 |
export_to_video(output.frames[0], tmp.name, fps=24)
|
| 89 |
return tmp.name
|
| 90 |
|
| 91 |
+
with gr.Blocks(title="Image Utility v2.1", ssr=False) as demo:
|
| 92 |
gr.HTML("<h1 style='text-align:center;'>🛠 Image Processing Utility v2.1.4</h1>")
|
| 93 |
with gr.Tabs():
|
| 94 |
with gr.Tab("D-Processor (Image/T2I)"):
|
|
|
|
| 105 |
t2i_btn = gr.Button("Execute Process", variant="primary")
|
| 106 |
t2i_out = gr.Image(label="Output Preview")
|
| 107 |
t2i_btn.click(generate_t2i, [t2i_p, t2i_n, t2i_lora, t2i_ls, t2i_w, t2i_h, t2i_img], t2i_out)
|
|
|
|
| 108 |
with gr.Tab("M-Sequence (Video)"):
|
| 109 |
with gr.Row():
|
| 110 |
with gr.Column():
|
|
|
|
| 115 |
v_out = gr.Video(label="Sequence Output")
|
| 116 |
v_btn.click(generate_video, [v_p, v_img, v_ls], v_out)
|
| 117 |
|
| 118 |
+
demo.queue().launch(show_api=True)
|