import sys import os # --- PARCHE DE COMPATIBILIDAD INVESTIGADO (CRÍTICO) --- # Este parche corrige el bug de 'bool' en gradio_client que afecta a Gradio 5 try: import gradio_client.utils as client_utils old_get_type = client_utils.get_type def new_get_type(schema): if isinstance(schema, bool): return "Any" return old_get_type(schema) client_utils.get_type = new_get_type old_json_to_python = client_utils._json_schema_to_python_type def new_json_to_python(schema, defs=None): if isinstance(schema, bool): return "Any" return old_json_to_python(schema, defs) client_utils._json_schema_to_python_type = new_json_to_python except Exception as e: print(f"Aviso: No se pudo aplicar el parche de gradio_client: {e}") # ------------------------------------------------------ import spaces import gradio as gr import torch import numpy as np from PIL import Image import tempfile # CONFIG BASE_MODEL = "cyberdelia/CyberRealisticPony" LTX_MODEL = "Lightricks/LTX-Video" LTX_NSFW_LORA = "Lora-Daddy/Ltx2.3-real-nudity-early-alpha-30k-steps" NEG_DEFAULT = "blurry, low quality, bad anatomy, deformed, ugly, watermark, text" def load_t2i(lora_id=None, lora_scale=1.0): from diffusers import StableDiffusionXLPipeline pipe = StableDiffusionXLPipeline.from_pretrained( BASE_MODEL, torch_dtype=torch.float16, use_safetensors=True, variant="fp16" ) if lora_id and len(lora_id.strip()) > 5: try: pipe.load_lora_weights(lora_id.strip()) pipe.fuse_lora(lora_scale=lora_scale) except: pass return pipe def load_video(): from diffusers import LTXPipeline pipe = LTXPipeline.from_pretrained(LTX_MODEL, torch_dtype=torch.bfloat16) try: pipe.load_lora_weights(LTX_NSFW_LORA) except: pass return pipe @spaces.GPU(duration=100) def generate_t2i(prompt, neg, lora_id, lora_scale, w, h): pipe = load_t2i(lora_id, lora_scale).to("cuda") img = pipe(prompt=prompt, negative_prompt=neg, num_inference_steps=30, guidance_scale=7.0, width=int(w), height=int(h), generator=torch.Generator("cuda").manual_seed(42)).images[0] return img @spaces.GPU(duration=200) def generate_video(prompt, init_image, lora_scale): from diffusers.utils import export_to_video pipe = load_video().to("cuda") kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49, "num_inference_steps": 30, "generator": torch.Generator("cuda").manual_seed(42)} if init_image is not None: kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512)) if lora_scale > 0: kwargs["cross_attention_kwargs"] = {"scale": lora_scale} output = pipe(**kwargs) tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) export_to_video(output.frames[0], tmp.name, fps=24) return tmp.name with gr.Blocks(title="Image Utility v2.1") as demo: gr.HTML("