Spaces:
Runtime error
Runtime error
Update to v2.2 Pro - All files
Browse files- Dockerfile +30 -0
- app.py +75 -98
- requirements.txt +3 -2
Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Usamos Python 3.10 que es el est谩ndar m谩s estable para IA
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Instalamos dependencias del sistema (FFMPEG para video y herramientas de compilaci贸n)
|
| 5 |
+
RUN apt-get update && apt-get install -y \
|
| 6 |
+
ffmpeg \
|
| 7 |
+
libsm6 \
|
| 8 |
+
libxext6 \
|
| 9 |
+
git \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Creamos un usuario para Hugging Face (requerido por seguridad)
|
| 13 |
+
RUN useradd -m -u 1000 user
|
| 14 |
+
USER user
|
| 15 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 16 |
+
|
| 17 |
+
WORKDIR /app
|
| 18 |
+
|
| 19 |
+
# Copiamos e instalamos requerimientos
|
| 20 |
+
COPY --chown=user requirements.txt .
|
| 21 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 22 |
+
|
| 23 |
+
# Copiamos el c贸digo de la aplicaci贸n
|
| 24 |
+
COPY --chown=user . .
|
| 25 |
+
|
| 26 |
+
# Exponemos el puerto de Gradio
|
| 27 |
+
EXPOSE 7860
|
| 28 |
+
|
| 29 |
+
# Comando para arrancar
|
| 30 |
+
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -1,136 +1,113 @@
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
# ---
|
| 5 |
try:
|
| 6 |
import gradio_client.utils as client_utils
|
| 7 |
-
# Parcheamos la funci贸n que causa el TypeError: argument of type 'bool' is not iterable
|
| 8 |
old_json_schema_to_python_type = client_utils._json_schema_to_python_type
|
| 9 |
def patched_json_schema_to_python_type(schema, defs=None):
|
| 10 |
-
if isinstance(schema, bool):
|
| 11 |
-
return "Any"
|
| 12 |
return old_json_schema_to_python_type(schema, defs)
|
| 13 |
client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
|
| 14 |
-
|
| 15 |
-
if hasattr(client_utils, "get_type"):
|
| 16 |
-
old_get_type = client_utils.get_type
|
| 17 |
-
def patched_get_type(schema):
|
| 18 |
-
if isinstance(schema, bool):
|
| 19 |
-
return "Any"
|
| 20 |
-
return old_get_type(schema)
|
| 21 |
-
client_utils.get_type = patched_get_type
|
| 22 |
-
print("Gradio Client 'bool' patch applied successfully.")
|
| 23 |
-
except Exception as e:
|
| 24 |
-
print(f"Failed to apply Gradio Client patch: {e}")
|
| 25 |
-
|
| 26 |
-
# --- PARCHES DE COMPATIBILIDAD (HfFolder + audioop) ---
|
| 27 |
-
try:
|
| 28 |
-
import huggingface_hub
|
| 29 |
-
class MockHfFolder:
|
| 30 |
-
@staticmethod
|
| 31 |
-
def get_token(): return os.getenv("HF_TOKEN")
|
| 32 |
-
@staticmethod
|
| 33 |
-
def save_token(token): pass
|
| 34 |
-
@staticmethod
|
| 35 |
-
def delete_token(): pass
|
| 36 |
-
huggingface_hub.HfFolder = MockHfFolder
|
| 37 |
-
sys.modules["huggingface_hub.HfFolder"] = MockHfFolder
|
| 38 |
except: pass
|
| 39 |
|
| 40 |
-
try:
|
| 41 |
-
import audioop_lts
|
| 42 |
-
sys.modules["audioop"] = audioop_lts
|
| 43 |
-
except:
|
| 44 |
-
from unittest.mock import MagicMock
|
| 45 |
-
sys.modules["audioop"] = MagicMock()
|
| 46 |
-
# -----------------------------------------------------------------
|
| 47 |
-
|
| 48 |
import spaces
|
| 49 |
import gradio as gr
|
| 50 |
import torch
|
| 51 |
-
import numpy as np
|
| 52 |
from PIL import Image
|
| 53 |
import tempfile
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
def load_t2i(is_img2img=False):
|
| 62 |
from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
|
| 63 |
cls = StableDiffusionXLImg2ImgPipeline if is_img2img else StableDiffusionXLPipeline
|
| 64 |
pipe = cls.from_pretrained(
|
| 65 |
-
|
|
|
|
| 66 |
)
|
| 67 |
return pipe
|
| 68 |
|
| 69 |
-
def load_video():
|
| 70 |
-
from diffusers import LTXPipeline
|
| 71 |
-
pipe = LTXPipeline.from_pretrained(LTX_MODEL, torch_dtype=torch.bfloat16)
|
| 72 |
-
try:
|
| 73 |
-
pipe.load_lora_weights(LTX_NSFW_LORA)
|
| 74 |
-
except: pass
|
| 75 |
-
return pipe
|
| 76 |
-
|
| 77 |
@spaces.GPU(duration=100)
|
| 78 |
-
def generate_t2i(prompt, neg,
|
|
|
|
|
|
|
|
|
|
| 79 |
is_img2img = init_img is not None
|
| 80 |
-
pipe = load_t2i(is_img2img).to("cuda")
|
| 81 |
-
|
|
|
|
| 82 |
try:
|
| 83 |
-
pipe.load_lora_weights(lora_id
|
| 84 |
pipe.fuse_lora(lora_scale=lora_scale)
|
| 85 |
-
except
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
if is_img2img:
|
| 88 |
kwargs["image"] = Image.fromarray(init_img).convert("RGB").resize((int(w), int(h)))
|
|
|
|
| 89 |
kwargs["strength"] = 0.6
|
| 90 |
-
|
| 91 |
-
kwargs["width"], kwargs["height"] = int(w), int(h)
|
| 92 |
return pipe(**kwargs).images[0]
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
kwargs = {"prompt": prompt, "negative_prompt": NEG_DEFAULT, "num_frames": 49, "num_inference_steps": 30}
|
| 99 |
-
if init_image is not None:
|
| 100 |
-
kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512))
|
| 101 |
-
if lora_scale > 0:
|
| 102 |
-
kwargs["cross_attention_kwargs"] = {"scale": lora_scale}
|
| 103 |
-
output = pipe(**kwargs)
|
| 104 |
-
tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
|
| 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("
|
| 112 |
with gr.Row():
|
| 113 |
-
with gr.Column():
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
t2i_lora = gr.Textbox(label="Extension ID")
|
| 118 |
-
t2i_ls = gr.Slider(0, 1.5, 0.8, label="Extension Weight")
|
| 119 |
with gr.Row():
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
# server_name 0.0.0.0 es clave para evitar el error de localhost en HF
|
| 136 |
demo.queue().launch(show_api=False, server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# --- PARCHES CR脥TICOS ---
|
| 5 |
try:
|
| 6 |
import gradio_client.utils as client_utils
|
|
|
|
| 7 |
old_json_schema_to_python_type = client_utils._json_schema_to_python_type
|
| 8 |
def patched_json_schema_to_python_type(schema, defs=None):
|
| 9 |
+
if isinstance(schema, bool): return "Any"
|
|
|
|
| 10 |
return old_json_schema_to_python_type(schema, defs)
|
| 11 |
client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
|
| 12 |
+
print("Gradio Patch Applied")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
except: pass
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import spaces
|
| 16 |
import gradio as gr
|
| 17 |
import torch
|
|
|
|
| 18 |
from PIL import Image
|
| 19 |
import tempfile
|
| 20 |
|
| 21 |
+
# MODELOS PREDEFINIDOS
|
| 22 |
+
MODELS = {
|
| 23 |
+
"CyberRealistic Pony (Recomendado)": "cyberdelia/CyberRealisticPony",
|
| 24 |
+
"RealVisXL V4.0": "SG161222/RealVisXL_V4.0",
|
| 25 |
+
"Juggernaut XL V9": "RunDiffusion/Juggernaut-XL-v9",
|
| 26 |
+
"SDXL Base 1.0": "stabilityai/stable-diffusion-xl-base-1.0"
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# LORAS PREDEFINIDOS
|
| 30 |
+
LORAS = {
|
| 31 |
+
"Ninguno": "",
|
| 32 |
+
"Detalle Extremo (XL)": "h94/IP-Adapter",
|
| 33 |
+
"Realismo Fotogr谩fico": "latent-consistency/lcm-lora-sdxl",
|
| 34 |
+
"Estilo Pixel Art": "nerijs/pixel-art-xl"
|
| 35 |
+
}
|
| 36 |
|
| 37 |
+
def load_t2i(model_id, is_img2img=False):
|
| 38 |
from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
|
| 39 |
cls = StableDiffusionXLImg2ImgPipeline if is_img2img else StableDiffusionXLPipeline
|
| 40 |
pipe = cls.from_pretrained(
|
| 41 |
+
model_id, torch_dtype=torch.float16, use_safetensors=True, variant="fp16",
|
| 42 |
+
low_cpu_mem_usage=True
|
| 43 |
)
|
| 44 |
return pipe
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
@spaces.GPU(duration=100)
|
| 47 |
+
def generate_t2i(prompt, neg, model_name, custom_model, lora_name, custom_lora, lora_scale, steps, cfg, w, h, init_img):
|
| 48 |
+
model_id = custom_model if custom_model else MODELS.get(model_name)
|
| 49 |
+
lora_id = custom_lora if custom_lora else LORAS.get(lora_name)
|
| 50 |
+
|
| 51 |
is_img2img = init_img is not None
|
| 52 |
+
pipe = load_t2i(model_id, is_img2img).to("cuda")
|
| 53 |
+
|
| 54 |
+
if lora_id:
|
| 55 |
try:
|
| 56 |
+
pipe.load_lora_weights(lora_id)
|
| 57 |
pipe.fuse_lora(lora_scale=lora_scale)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print(f"LoRA Error: {e}")
|
| 60 |
+
|
| 61 |
+
kwargs = {
|
| 62 |
+
"prompt": prompt,
|
| 63 |
+
"negative_prompt": neg,
|
| 64 |
+
"num_inference_steps": int(steps),
|
| 65 |
+
"guidance_scale": cfg,
|
| 66 |
+
"width": int(w),
|
| 67 |
+
"height": int(h)
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
if is_img2img:
|
| 71 |
kwargs["image"] = Image.fromarray(init_img).convert("RGB").resize((int(w), int(h)))
|
| 72 |
+
kwargs.pop("width"); kwargs.pop("height")
|
| 73 |
kwargs["strength"] = 0.6
|
| 74 |
+
|
|
|
|
| 75 |
return pipe(**kwargs).images[0]
|
| 76 |
|
| 77 |
+
# UI DESIGN
|
| 78 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo:
|
| 79 |
+
gr.HTML("<h1 style='text-align:center;'>馃帹 Studio Privado v2.2 PRO</h1>")
|
| 80 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
with gr.Tabs():
|
| 82 |
+
with gr.Tab("馃柤 Generador de Im谩genes"):
|
| 83 |
with gr.Row():
|
| 84 |
+
with gr.Column(scale=1):
|
| 85 |
+
prompt = gr.Textbox(label="Prompt (Descripci贸n)", placeholder="Una mujer cyberpunk en neon city...", lines=3)
|
| 86 |
+
neg = gr.Textbox(label="Prompt Negativo", value="blurry, ugly, low quality, deformed")
|
| 87 |
+
|
|
|
|
|
|
|
| 88 |
with gr.Row():
|
| 89 |
+
model_sel = gr.Dropdown(choices=list(MODELS.keys()), value="CyberRealistic Pony (Recomendado)", label="Seleccionar Modelo")
|
| 90 |
+
custom_model = gr.Textbox(label="O usar ID de HF (opcional)", placeholder="usuario/modelo")
|
| 91 |
+
|
| 92 |
+
with gr.Row():
|
| 93 |
+
lora_sel = gr.Dropdown(choices=list(LORAS.keys()), value="Ninguno", label="Seleccionar Extensi贸n (LoRA)")
|
| 94 |
+
custom_lora = gr.Textbox(label="O ID de LoRA personalizado", placeholder="usuario/lora")
|
| 95 |
+
|
| 96 |
+
lora_scale = gr.Slider(0, 1.5, 0.8, label="Peso de la Extensi贸n")
|
| 97 |
+
|
| 98 |
+
with gr.Accordion("Configuraci贸n Avanzada", open=False):
|
| 99 |
+
steps = gr.Slider(10, 50, 30, step=1, label="Pasos")
|
| 100 |
+
cfg = gr.Slider(1, 15, 7, label="Guidance Scale")
|
| 101 |
+
with gr.Row():
|
| 102 |
+
w = gr.Slider(512, 1024, 1024, step=64, label="Ancho")
|
| 103 |
+
h = gr.Slider(512, 1024, 1024, step=64, label="Alto")
|
| 104 |
+
|
| 105 |
+
init_img = gr.Image(label="Imagen de Referencia (Img2Img)", type="numpy")
|
| 106 |
+
btn = gr.Button("GENERAR IMAGEN", variant="primary")
|
| 107 |
+
|
| 108 |
+
with gr.Column(scale=1):
|
| 109 |
+
output = gr.Image(label="Resultado")
|
| 110 |
+
|
| 111 |
+
btn.click(generate_t2i, [prompt, neg, model_sel, custom_model, lora_sel, custom_lora, lora_scale, steps, cfg, w, h, init_img], output)
|
| 112 |
|
|
|
|
| 113 |
demo.queue().launch(show_api=False, server_name="0.0.0.0", server_port=7860)
|
requirements.txt
CHANGED
|
@@ -4,9 +4,10 @@ fastapi==0.112.2
|
|
| 4 |
starlette==0.38.2
|
| 5 |
huggingface-hub==0.24.2
|
| 6 |
audioop-lts
|
| 7 |
-
diffusers>=0.
|
| 8 |
-
transformers>=4.
|
| 9 |
accelerate>=0.33.0
|
|
|
|
| 10 |
torch
|
| 11 |
sentencepiece
|
| 12 |
imageio[ffmpeg]
|
|
|
|
| 4 |
starlette==0.38.2
|
| 5 |
huggingface-hub==0.24.2
|
| 6 |
audioop-lts
|
| 7 |
+
diffusers>=0.31.0
|
| 8 |
+
transformers>=4.44.0
|
| 9 |
accelerate>=0.33.0
|
| 10 |
+
peft
|
| 11 |
torch
|
| 12 |
sentencepiece
|
| 13 |
imageio[ffmpeg]
|