Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,57 +2,76 @@ import os
|
|
| 2 |
import shlex
|
| 3 |
import spaces
|
| 4 |
import subprocess
|
| 5 |
-
import uuid
|
| 6 |
-
import torch
|
| 7 |
-
import trimesh
|
| 8 |
import argparse
|
| 9 |
-
import
|
| 10 |
-
import gradio as gr
|
| 11 |
import random
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# --------------------------------------------------------------------------
|
| 14 |
-
# 1
|
|
|
|
| 15 |
# --------------------------------------------------------------------------
|
|
|
|
| 16 |
@spaces.GPU(duration=120)
|
| 17 |
def setup_environment():
|
| 18 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 19 |
print("--- INICIANDO CONFIGURACIÓN DEL ENTORNO ---")
|
|
|
|
|
|
|
| 20 |
if not os.path.exists("/usr/local/cuda"):
|
| 21 |
print("Instalando CUDA Toolkit...")
|
| 22 |
CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_550.54.14_linux.run"
|
| 23 |
CUDA_TOOLKIT_FILE = f"/tmp/{os.path.basename(CUDA_TOOLKIT_URL)}"
|
|
|
|
| 24 |
subprocess.run(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE], check=True)
|
| 25 |
subprocess.run(["chmod", "+x", CUDA_TOOLKIT_FILE], check=True)
|
| 26 |
subprocess.run([CUDA_TOOLKIT_FILE, "--silent", "--toolkit", "--override"], check=True)
|
|
|
|
| 27 |
else:
|
| 28 |
print("CUDA Toolkit ya está instalado.")
|
| 29 |
-
|
|
|
|
| 30 |
os.environ["CUDA_HOME"] = "/usr/local/cuda"
|
| 31 |
os.environ["PATH"] = f"{os.environ['CUDA_HOME']}/bin:{os.environ['PATH']}"
|
| 32 |
os.environ["LD_LIBRARY_PATH"] = f"{os.environ['CUDA_HOME']}/lib64:{os.environ.get('LD_LIBRARY_PATH', '')}"
|
| 33 |
os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
|
| 34 |
print("Variables de entorno de CUDA configuradas.")
|
|
|
|
|
|
|
|
|
|
| 35 |
os.system('nvcc -V')
|
| 36 |
|
|
|
|
| 37 |
print("Compilando extensión de renderizador diferenciable...")
|
| 38 |
try:
|
| 39 |
-
subprocess.run(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
except subprocess.CalledProcessError as e:
|
| 41 |
-
print(f"ERROR al compilar el renderizador diferenciable
|
| 42 |
raise RuntimeError("Fallo crítico en la compilación del renderizador.")
|
| 43 |
|
| 44 |
print("Instalando rasterizador personalizado...")
|
| 45 |
try:
|
| 46 |
subprocess.run(shlex.split("pip install custom_rasterizer-0.1-cp310-cp310-linux_x86_64.whl"), check=True)
|
|
|
|
| 47 |
except Exception as e:
|
| 48 |
print(f"ERROR al instalar el rasterizador personalizado: {e}")
|
| 49 |
raise RuntimeError("Fallo crítico en la instalación del rasterizador.")
|
|
|
|
| 50 |
print("--- CONFIGURACIÓN DEL ENTORNO FINALIZADA ---")
|
| 51 |
|
|
|
|
| 52 |
setup_environment()
|
| 53 |
|
| 54 |
# --------------------------------------------------------------------------
|
| 55 |
-
# 2
|
| 56 |
# --------------------------------------------------------------------------
|
| 57 |
import torch
|
| 58 |
import trimesh
|
|
@@ -60,15 +79,20 @@ import gradio as gr
|
|
| 60 |
from step1x3d_texture.pipelines.step1x_3d_texture_synthesis_pipeline import Step1X3DTexturePipeline
|
| 61 |
from step1x3d_geometry.models.pipelines.pipeline_utils import reduce_face, remove_degenerate_face
|
| 62 |
|
|
|
|
|
|
|
|
|
|
| 63 |
parser = argparse.ArgumentParser()
|
| 64 |
parser.add_argument("--texture_model", type=str, default="Step1X-3D-Texture")
|
| 65 |
parser.add_argument("--cache_dir", type=str, default="cache")
|
| 66 |
args = parser.parse_args()
|
| 67 |
|
| 68 |
-
|
|
|
|
| 69 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 70 |
MAX_SEED = np.iinfo(np.int32).max
|
| 71 |
|
|
|
|
| 72 |
if not torch.cuda.is_available():
|
| 73 |
raise RuntimeError("CUDA no está disponible para PyTorch. La aplicación no puede continuar.")
|
| 74 |
|
|
@@ -77,59 +101,82 @@ texture_model = Step1X3DTexturePipeline.from_pretrained("stepfun-ai/Step1X-3D",
|
|
| 77 |
print("Modelo de textura cargado y listo.")
|
| 78 |
|
| 79 |
# --------------------------------------------------------------------------
|
| 80 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
# --------------------------------------------------------------------------
|
| 82 |
|
| 83 |
def get_random_seed(randomize_seed, seed):
|
| 84 |
-
"""
|
| 85 |
if randomize_seed:
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
return new_seed
|
| 89 |
-
else:
|
| 90 |
-
print(f"Usando semilla fija: {int(seed)}")
|
| 91 |
-
return int(seed)
|
| 92 |
|
| 93 |
@spaces.GPU(duration=180)
|
| 94 |
-
def
|
| 95 |
input_image_path,
|
| 96 |
input_mesh_path,
|
| 97 |
guidance_scale,
|
| 98 |
inference_steps,
|
| 99 |
-
seed,
|
|
|
|
| 100 |
reference_conditioning_scale,
|
|
|
|
| 101 |
progress=gr.Progress(track_tqdm=True)
|
| 102 |
):
|
| 103 |
"""
|
| 104 |
-
Función principal que genera la textura
|
| 105 |
"""
|
| 106 |
if input_image_path is None:
|
| 107 |
raise gr.Error("Por favor, sube una imagen de referencia para empezar.")
|
| 108 |
if input_mesh_path is None:
|
| 109 |
raise gr.Error("Por favor, sube un modelo 3D (.glb o .obj) para texturizar.")
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
# Actualizar la configuración del pipeline
|
| 114 |
texture_model.config.guidance_scale = float(guidance_scale)
|
| 115 |
texture_model.config.num_inference_steps = int(inference_steps)
|
| 116 |
texture_model.config.reference_conditioning_scale = float(reference_conditioning_scale)
|
| 117 |
|
| 118 |
-
|
| 119 |
-
final_seed = int(seed)
|
| 120 |
-
print(f"Parámetros: Pasos={inference_steps}, Escala Guía={guidance_scale}, Semilla Final={final_seed}")
|
| 121 |
|
| 122 |
-
print(f"Cargando malla desde: {input_mesh_path}")
|
| 123 |
try:
|
| 124 |
user_mesh = trimesh.load(input_mesh_path, force='mesh')
|
| 125 |
except Exception as e:
|
| 126 |
raise gr.Error(f"No se pudo cargar el archivo del modelo 3D. Error: {e}")
|
| 127 |
|
| 128 |
-
print("Pre-procesando la malla...")
|
| 129 |
user_mesh = remove_degenerate_face(user_mesh)
|
| 130 |
user_mesh = reduce_face(user_mesh)
|
| 131 |
|
| 132 |
-
print("Ejecutando el pipeline de texturizado
|
| 133 |
textured_mesh = texture_model(
|
| 134 |
image=input_image_path,
|
| 135 |
mesh=user_mesh,
|
|
@@ -138,16 +185,16 @@ def generate_texture(
|
|
| 138 |
)
|
| 139 |
|
| 140 |
save_name = str(uuid.uuid4())
|
| 141 |
-
textured_save_path = f"{
|
| 142 |
textured_mesh.export(textured_save_path)
|
| 143 |
|
| 144 |
torch.cuda.empty_cache()
|
| 145 |
-
print(f"Malla texturizada guardada en: {textured_save_path}")
|
| 146 |
|
| 147 |
return textured_save_path
|
| 148 |
|
| 149 |
# --------------------------------------------------------------------------
|
| 150 |
-
#
|
| 151 |
# --------------------------------------------------------------------------
|
| 152 |
|
| 153 |
with gr.Blocks(title="Step1X-3D Texture Generator") as demo:
|
|
@@ -164,8 +211,8 @@ with gr.Blocks(title="Step1X-3D Texture Generator") as demo:
|
|
| 164 |
inference_steps = gr.Slider(label="Pasos de Inferencia (Calidad vs. Velocidad)", minimum=10, maximum=100, value=50, step=1)
|
| 165 |
reference_conditioning_scale = gr.Slider(label="Escala de Condicionamiento de Imagen", minimum=0.0, maximum=2.0, step=0.1, value=1.0)
|
| 166 |
with gr.Row():
|
| 167 |
-
|
| 168 |
-
|
| 169 |
|
| 170 |
btn_generate = gr.Button("✨ Generar Textura", variant="primary")
|
| 171 |
|
|
@@ -173,22 +220,25 @@ with gr.Blocks(title="Step1X-3D Texture Generator") as demo:
|
|
| 173 |
output_model = gr.Model3D(label="Resultado: Modelo Texturizado", height=600, clear_color=[0.0, 0.0, 0.0, 0.0])
|
| 174 |
|
| 175 |
# --- Lógica de la interfaz ---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
|
|
|
| 177 |
btn_generate.click(
|
| 178 |
-
fn=
|
| 179 |
-
inputs=[randomize_seed, seed],
|
| 180 |
-
outputs=[seed]
|
| 181 |
-
).then(
|
| 182 |
-
fn=generate_texture,
|
| 183 |
inputs=[
|
| 184 |
input_image,
|
| 185 |
input_mesh,
|
| 186 |
guidance_scale,
|
| 187 |
inference_steps,
|
| 188 |
-
|
|
|
|
| 189 |
reference_conditioning_scale,
|
| 190 |
],
|
| 191 |
outputs=[output_model]
|
| 192 |
)
|
| 193 |
|
|
|
|
| 194 |
demo.launch(ssr_mode=False)
|
|
|
|
| 2 |
import shlex
|
| 3 |
import spaces
|
| 4 |
import subprocess
|
|
|
|
|
|
|
|
|
|
| 5 |
import argparse
|
| 6 |
+
import uuid
|
|
|
|
| 7 |
import random
|
| 8 |
+
import numpy as np
|
| 9 |
+
import shutil
|
| 10 |
|
| 11 |
# --------------------------------------------------------------------------
|
| 12 |
+
# BLOQUE 1: INSTALACIÓN DEL ENTORNO Y DEPENDENCIAS
|
| 13 |
+
# Esta sección DEBE ejecutarse en su totalidad ANTES de importar torch o gradio.
|
| 14 |
# --------------------------------------------------------------------------
|
| 15 |
+
|
| 16 |
@spaces.GPU(duration=120)
|
| 17 |
def setup_environment():
|
| 18 |
+
"""
|
| 19 |
+
Prepara todo el entorno necesario, instalando CUDA y compilando las extensiones.
|
| 20 |
+
Esta función se ejecuta una vez al inicio del Space.
|
| 21 |
+
"""
|
| 22 |
print("--- INICIANDO CONFIGURACIÓN DEL ENTORNO ---")
|
| 23 |
+
|
| 24 |
+
# 1. Instalar CUDA Toolkit
|
| 25 |
if not os.path.exists("/usr/local/cuda"):
|
| 26 |
print("Instalando CUDA Toolkit...")
|
| 27 |
CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_550.54.14_linux.run"
|
| 28 |
CUDA_TOOLKIT_FILE = f"/tmp/{os.path.basename(CUDA_TOOLKIT_URL)}"
|
| 29 |
+
|
| 30 |
subprocess.run(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE], check=True)
|
| 31 |
subprocess.run(["chmod", "+x", CUDA_TOOLKIT_FILE], check=True)
|
| 32 |
subprocess.run([CUDA_TOOLKIT_FILE, "--silent", "--toolkit", "--override"], check=True)
|
| 33 |
+
print("CUDA Toolkit instalado.")
|
| 34 |
else:
|
| 35 |
print("CUDA Toolkit ya está instalado.")
|
| 36 |
+
|
| 37 |
+
# 2. Configurar variables de entorno
|
| 38 |
os.environ["CUDA_HOME"] = "/usr/local/cuda"
|
| 39 |
os.environ["PATH"] = f"{os.environ['CUDA_HOME']}/bin:{os.environ['PATH']}"
|
| 40 |
os.environ["LD_LIBRARY_PATH"] = f"{os.environ['CUDA_HOME']}/lib64:{os.environ.get('LD_LIBRARY_PATH', '')}"
|
| 41 |
os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
|
| 42 |
print("Variables de entorno de CUDA configuradas.")
|
| 43 |
+
|
| 44 |
+
# 3. Verificar NVCC
|
| 45 |
+
print("Verificando versión de NVCC:")
|
| 46 |
os.system('nvcc -V')
|
| 47 |
|
| 48 |
+
# 4. Compilar extensiones C++/CUDA
|
| 49 |
print("Compilando extensión de renderizador diferenciable...")
|
| 50 |
try:
|
| 51 |
+
subprocess.run(
|
| 52 |
+
"cd /home/user/app/step1x3d_texture/differentiable_renderer/ && python setup.py install",
|
| 53 |
+
shell=True, check=True, capture_output=True, text=True
|
| 54 |
+
)
|
| 55 |
+
print("Renderizador diferenciable compilado.")
|
| 56 |
except subprocess.CalledProcessError as e:
|
| 57 |
+
print(f"ERROR al compilar el renderizador diferenciable:\n{e.stderr}")
|
| 58 |
raise RuntimeError("Fallo crítico en la compilación del renderizador.")
|
| 59 |
|
| 60 |
print("Instalando rasterizador personalizado...")
|
| 61 |
try:
|
| 62 |
subprocess.run(shlex.split("pip install custom_rasterizer-0.1-cp310-cp310-linux_x86_64.whl"), check=True)
|
| 63 |
+
print("Rasterizador personalizado instalado.")
|
| 64 |
except Exception as e:
|
| 65 |
print(f"ERROR al instalar el rasterizador personalizado: {e}")
|
| 66 |
raise RuntimeError("Fallo crítico en la instalación del rasterizador.")
|
| 67 |
+
|
| 68 |
print("--- CONFIGURACIÓN DEL ENTORNO FINALIZADA ---")
|
| 69 |
|
| 70 |
+
# Ejecutar la configuración del entorno antes de cualquier otra cosa
|
| 71 |
setup_environment()
|
| 72 |
|
| 73 |
# --------------------------------------------------------------------------
|
| 74 |
+
# BLOQUE 2: IMPORTACIONES DE LA APLICACIÓN Y LÓGICA PRINCIPAL
|
| 75 |
# --------------------------------------------------------------------------
|
| 76 |
import torch
|
| 77 |
import trimesh
|
|
|
|
| 79 |
from step1x3d_texture.pipelines.step1x_3d_texture_synthesis_pipeline import Step1X3DTexturePipeline
|
| 80 |
from step1x3d_geometry.models.pipelines.pipeline_utils import reduce_face, remove_degenerate_face
|
| 81 |
|
| 82 |
+
# --------------------------------------------------------------------------
|
| 83 |
+
# 3. CONFIGURACIÓN Y CARGA DEL MODELO DE TEXTURA
|
| 84 |
+
# --------------------------------------------------------------------------
|
| 85 |
parser = argparse.ArgumentParser()
|
| 86 |
parser.add_argument("--texture_model", type=str, default="Step1X-3D-Texture")
|
| 87 |
parser.add_argument("--cache_dir", type=str, default="cache")
|
| 88 |
args = parser.parse_args()
|
| 89 |
|
| 90 |
+
TMP_DIR = args.cache_dir
|
| 91 |
+
os.makedirs(TMP_DIR, exist_ok=True)
|
| 92 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 93 |
MAX_SEED = np.iinfo(np.int32).max
|
| 94 |
|
| 95 |
+
print(f"Dispositivo detectado: {device}")
|
| 96 |
if not torch.cuda.is_available():
|
| 97 |
raise RuntimeError("CUDA no está disponible para PyTorch. La aplicación no puede continuar.")
|
| 98 |
|
|
|
|
| 101 |
print("Modelo de textura cargado y listo.")
|
| 102 |
|
| 103 |
# --------------------------------------------------------------------------
|
| 104 |
+
# 4. GESTIÓN DE SESIONES Y ARCHIVOS TEMPORALES
|
| 105 |
+
# --------------------------------------------------------------------------
|
| 106 |
+
|
| 107 |
+
def start_session(req: gr.Request):
|
| 108 |
+
"""Crea un directorio temporal único para la sesión del usuario."""
|
| 109 |
+
session_hash = str(req.session_hash)
|
| 110 |
+
user_dir = os.path.join(TMP_DIR, session_hash)
|
| 111 |
+
os.makedirs(user_dir, exist_ok=True)
|
| 112 |
+
print(f"Sesión iniciada: {session_hash}. Directorio temporal: {user_dir}")
|
| 113 |
+
|
| 114 |
+
def end_session(req: gr.Request):
|
| 115 |
+
"""Elimina el directorio temporal de la sesión para liberar espacio."""
|
| 116 |
+
session_hash = str(req.session_hash)
|
| 117 |
+
user_dir = os.path.join(TMP_DIR, session_hash)
|
| 118 |
+
if os.path.exists(user_dir):
|
| 119 |
+
try:
|
| 120 |
+
shutil.rmtree(user_dir)
|
| 121 |
+
print(f"Sesión finalizada: {session_hash}. Directorio temporal eliminado.")
|
| 122 |
+
except Exception as e:
|
| 123 |
+
print(f"Error al eliminar el directorio de la sesión {session_hash}: {e}")
|
| 124 |
+
|
| 125 |
+
# --------------------------------------------------------------------------
|
| 126 |
+
# 5. FUNCIÓN DE GENERACIÓN DE TEXTURA
|
| 127 |
# --------------------------------------------------------------------------
|
| 128 |
|
| 129 |
def get_random_seed(randomize_seed, seed):
|
| 130 |
+
"""Genera una semilla aleatoria si se solicita."""
|
| 131 |
if randomize_seed:
|
| 132 |
+
return random.randint(0, MAX_SEED)
|
| 133 |
+
return int(seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
@spaces.GPU(duration=180)
|
| 136 |
+
def generate_texture_for_user_mesh(
|
| 137 |
input_image_path,
|
| 138 |
input_mesh_path,
|
| 139 |
guidance_scale,
|
| 140 |
inference_steps,
|
| 141 |
+
seed,
|
| 142 |
+
randomize_seed,
|
| 143 |
reference_conditioning_scale,
|
| 144 |
+
req: gr.Request, # Se añade el objeto request para obtener el hash de la sesión
|
| 145 |
progress=gr.Progress(track_tqdm=True)
|
| 146 |
):
|
| 147 |
"""
|
| 148 |
+
Función principal que genera la textura para un modelo 3D proporcionado por el usuario.
|
| 149 |
"""
|
| 150 |
if input_image_path is None:
|
| 151 |
raise gr.Error("Por favor, sube una imagen de referencia para empezar.")
|
| 152 |
if input_mesh_path is None:
|
| 153 |
raise gr.Error("Por favor, sube un modelo 3D (.glb o .obj) para texturizar.")
|
| 154 |
|
| 155 |
+
session_hash = str(req.session_hash)
|
| 156 |
+
user_dir = os.path.join(TMP_DIR, session_hash)
|
| 157 |
+
print(f"[{session_hash}] Iniciando generación de textura...")
|
| 158 |
+
|
| 159 |
+
# Obtener semilla
|
| 160 |
+
final_seed = get_random_seed(randomize_seed, seed)
|
| 161 |
|
| 162 |
+
# Actualizar la configuración del pipeline
|
| 163 |
texture_model.config.guidance_scale = float(guidance_scale)
|
| 164 |
texture_model.config.num_inference_steps = int(inference_steps)
|
| 165 |
texture_model.config.reference_conditioning_scale = float(reference_conditioning_scale)
|
| 166 |
|
| 167 |
+
print(f"[{session_hash}] Parámetros: Pasos={inference_steps}, Escala Guía={guidance_scale}, Semilla={final_seed}")
|
|
|
|
|
|
|
| 168 |
|
| 169 |
+
print(f"[{session_hash}] Cargando malla desde: {input_mesh_path}")
|
| 170 |
try:
|
| 171 |
user_mesh = trimesh.load(input_mesh_path, force='mesh')
|
| 172 |
except Exception as e:
|
| 173 |
raise gr.Error(f"No se pudo cargar el archivo del modelo 3D. Error: {e}")
|
| 174 |
|
| 175 |
+
print(f"[{session_hash}] Pre-procesando la malla...")
|
| 176 |
user_mesh = remove_degenerate_face(user_mesh)
|
| 177 |
user_mesh = reduce_face(user_mesh)
|
| 178 |
|
| 179 |
+
print(f"[{session_hash}] Ejecutando el pipeline de texturizado...")
|
| 180 |
textured_mesh = texture_model(
|
| 181 |
image=input_image_path,
|
| 182 |
mesh=user_mesh,
|
|
|
|
| 185 |
)
|
| 186 |
|
| 187 |
save_name = str(uuid.uuid4())
|
| 188 |
+
textured_save_path = f"{user_dir}/{save_name}-textured.glb"
|
| 189 |
textured_mesh.export(textured_save_path)
|
| 190 |
|
| 191 |
torch.cuda.empty_cache()
|
| 192 |
+
print(f"[{session_hash}] Malla texturizada guardada en: {textured_save_path}")
|
| 193 |
|
| 194 |
return textured_save_path
|
| 195 |
|
| 196 |
# --------------------------------------------------------------------------
|
| 197 |
+
# 6. INTERFAZ DE USUARIO CON GRADIO
|
| 198 |
# --------------------------------------------------------------------------
|
| 199 |
|
| 200 |
with gr.Blocks(title="Step1X-3D Texture Generator") as demo:
|
|
|
|
| 211 |
inference_steps = gr.Slider(label="Pasos de Inferencia (Calidad vs. Velocidad)", minimum=10, maximum=100, value=50, step=1)
|
| 212 |
reference_conditioning_scale = gr.Slider(label="Escala de Condicionamiento de Imagen", minimum=0.0, maximum=2.0, step=0.1, value=1.0)
|
| 213 |
with gr.Row():
|
| 214 |
+
seed_input = gr.Slider(label="Semilla (Seed)", minimum=0, maximum=MAX_SEED, step=1, value=2024, interactive=True)
|
| 215 |
+
randomize_seed_checkbox = gr.Checkbox(label="Aleatoria", value=True)
|
| 216 |
|
| 217 |
btn_generate = gr.Button("✨ Generar Textura", variant="primary")
|
| 218 |
|
|
|
|
| 220 |
output_model = gr.Model3D(label="Resultado: Modelo Texturizado", height=600, clear_color=[0.0, 0.0, 0.0, 0.0])
|
| 221 |
|
| 222 |
# --- Lógica de la interfaz ---
|
| 223 |
+
|
| 224 |
+
# Conecta las funciones de sesión al ciclo de vida de la demo
|
| 225 |
+
demo.load(start_session)
|
| 226 |
+
demo.unload(end_session)
|
| 227 |
|
| 228 |
+
# Conecta el botón a la función de generación
|
| 229 |
btn_generate.click(
|
| 230 |
+
fn=generate_texture_for_user_mesh,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
inputs=[
|
| 232 |
input_image,
|
| 233 |
input_mesh,
|
| 234 |
guidance_scale,
|
| 235 |
inference_steps,
|
| 236 |
+
seed_input,
|
| 237 |
+
randomize_seed_checkbox,
|
| 238 |
reference_conditioning_scale,
|
| 239 |
],
|
| 240 |
outputs=[output_model]
|
| 241 |
)
|
| 242 |
|
| 243 |
+
# Lanza la aplicación
|
| 244 |
demo.launch(ssr_mode=False)
|