Spaces:
Runtime error
Runtime error
Fix: Interactive image upload and API sync for Gradio 5.5
Browse files
app.py
CHANGED
|
@@ -4,24 +4,10 @@ try:
|
|
| 4 |
import audioop_lts
|
| 5 |
sys.modules["audioop"] = audioop_lts
|
| 6 |
except ImportError:
|
| 7 |
-
# Si no est谩, creamos un mock para que Gradio no colapse
|
| 8 |
from unittest.mock import MagicMock
|
| 9 |
sys.modules["audioop"] = MagicMock()
|
| 10 |
# ------------------------------------------------
|
| 11 |
|
| 12 |
-
# --- PARCHE DE GRADIO_CLIENT (BOOL BUG) ---
|
| 13 |
-
try:
|
| 14 |
-
import gradio_client.utils as client_utils
|
| 15 |
-
def new_get_type(schema):
|
| 16 |
-
if isinstance(schema, bool): return "Any"
|
| 17 |
-
try: return old_get_type(schema)
|
| 18 |
-
except: return "Any"
|
| 19 |
-
if hasattr(client_utils, "get_type"):
|
| 20 |
-
old_get_type = client_utils.get_type
|
| 21 |
-
client_utils.get_type = new_get_type
|
| 22 |
-
except: pass
|
| 23 |
-
# ------------------------------------------
|
| 24 |
-
|
| 25 |
import spaces
|
| 26 |
import gradio as gr
|
| 27 |
import torch
|
|
@@ -70,6 +56,9 @@ def generate_video(prompt, init_image, lora_scale):
|
|
| 70 |
kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49,
|
| 71 |
"num_inference_steps": 30, "generator": torch.Generator("cuda").manual_seed(42)}
|
| 72 |
if init_image is not None:
|
|
|
|
|
|
|
|
|
|
| 73 |
kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512))
|
| 74 |
if lora_scale > 0:
|
| 75 |
kwargs["cross_attention_kwargs"] = {"scale": lora_scale}
|
|
@@ -78,6 +67,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():
|
|
@@ -91,7 +81,7 @@ with gr.Blocks(title="Image Utility v2.1") as demo:
|
|
| 91 |
with gr.Row():
|
| 92 |
t2i_w = gr.Slider(512, 1024, 1024, step=64, label="X-Axis")
|
| 93 |
t2i_h = gr.Slider(512, 1024, 1024, step=64, label="Y-Axis")
|
| 94 |
-
t2i_btn = gr.Button("Execute Process")
|
| 95 |
t2i_out = gr.Image(label="Output Preview")
|
| 96 |
t2i_btn.click(generate_t2i, [t2i_p, t2i_n, t2i_lora, t2i_ls, t2i_w, t2i_h], t2i_out)
|
| 97 |
|
|
@@ -99,10 +89,12 @@ with gr.Blocks(title="Image Utility v2.1") as demo:
|
|
| 99 |
with gr.Row():
|
| 100 |
with gr.Column():
|
| 101 |
v_p = gr.Textbox(label="Motion Vector String", lines=3)
|
| 102 |
-
|
|
|
|
| 103 |
v_ls = gr.Slider(0, 1.5, 0.8, label="Motion Weight")
|
| 104 |
-
v_btn = gr.Button("Process Sequence")
|
| 105 |
v_out = gr.Video(label="Sequence Output")
|
| 106 |
v_btn.click(generate_video, [v_p, v_img, v_ls], v_out)
|
| 107 |
|
| 108 |
-
|
|
|
|
|
|
| 4 |
import audioop_lts
|
| 5 |
sys.modules["audioop"] = audioop_lts
|
| 6 |
except ImportError:
|
|
|
|
| 7 |
from unittest.mock import MagicMock
|
| 8 |
sys.modules["audioop"] = MagicMock()
|
| 9 |
# ------------------------------------------------
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
import spaces
|
| 12 |
import gradio as gr
|
| 13 |
import torch
|
|
|
|
| 56 |
kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49,
|
| 57 |
"num_inference_steps": 30, "generator": torch.Generator("cuda").manual_seed(42)}
|
| 58 |
if init_image is not None:
|
| 59 |
+
# Conversi贸n segura de imagen para Gradio 5
|
| 60 |
+
if isinstance(init_image, dict):
|
| 61 |
+
init_image = init_image["composite"] if "composite" in init_image else init_image["background"]
|
| 62 |
kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512))
|
| 63 |
if lora_scale > 0:
|
| 64 |
kwargs["cross_attention_kwargs"] = {"scale": lora_scale}
|
|
|
|
| 67 |
export_to_video(output.frames[0], tmp.name, fps=24)
|
| 68 |
return tmp.name
|
| 69 |
|
| 70 |
+
# INTERFAZ
|
| 71 |
with gr.Blocks(title="Image Utility v2.1") as demo:
|
| 72 |
gr.HTML("<h1 style='text-align:center;'>馃洜 Image Processing Utility v2.1.4</h1>")
|
| 73 |
with gr.Tabs():
|
|
|
|
| 81 |
with gr.Row():
|
| 82 |
t2i_w = gr.Slider(512, 1024, 1024, step=64, label="X-Axis")
|
| 83 |
t2i_h = gr.Slider(512, 1024, 1024, step=64, label="Y-Axis")
|
| 84 |
+
t2i_btn = gr.Button("Execute Process", variant="primary")
|
| 85 |
t2i_out = gr.Image(label="Output Preview")
|
| 86 |
t2i_btn.click(generate_t2i, [t2i_p, t2i_n, t2i_lora, t2i_ls, t2i_w, t2i_h], t2i_out)
|
| 87 |
|
|
|
|
| 89 |
with gr.Row():
|
| 90 |
with gr.Column():
|
| 91 |
v_p = gr.Textbox(label="Motion Vector String", lines=3)
|
| 92 |
+
# Mejora en el componente de imagen para permitir carga directa
|
| 93 |
+
v_img = gr.Image(label="Source Buffer", type="numpy", sources=["upload", "clipboard"])
|
| 94 |
v_ls = gr.Slider(0, 1.5, 0.8, label="Motion Weight")
|
| 95 |
+
v_btn = gr.Button("Process Sequence", variant="primary")
|
| 96 |
v_out = gr.Video(label="Sequence Output")
|
| 97 |
v_btn.click(generate_video, [v_p, v_img, v_ls], v_out)
|
| 98 |
|
| 99 |
+
# Habilitar cola para ZeroGPU y activar API para sincronizaci贸n de frontend
|
| 100 |
+
demo.queue(api_open=True).launch(show_api=True)
|