Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,7 @@ 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)
|
@@ -67,7 +66,6 @@ def setup_environment():
|
|
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 |
# --------------------------------------------------------------------------
|
@@ -127,10 +125,11 @@ def end_session(req: gr.Request):
|
|
127 |
# --------------------------------------------------------------------------
|
128 |
|
129 |
def get_random_seed(randomize_seed, seed):
|
130 |
-
"""
|
131 |
if randomize_seed:
|
132 |
-
|
133 |
-
|
|
|
134 |
|
135 |
@spaces.GPU(duration=180)
|
136 |
def generate_texture_for_user_mesh(
|
@@ -138,10 +137,9 @@ def generate_texture_for_user_mesh(
|
|
138 |
input_mesh_path,
|
139 |
guidance_scale,
|
140 |
inference_steps,
|
141 |
-
seed,
|
142 |
-
randomize_seed,
|
143 |
reference_conditioning_scale,
|
144 |
-
req: gr.Request,
|
145 |
progress=gr.Progress(track_tqdm=True)
|
146 |
):
|
147 |
"""
|
@@ -156,8 +154,7 @@ def generate_texture_for_user_mesh(
|
|
156 |
user_dir = os.path.join(TMP_DIR, session_hash)
|
157 |
print(f"[{session_hash}] Iniciando generaci贸n de textura...")
|
158 |
|
159 |
-
|
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)
|
@@ -193,6 +190,7 @@ def generate_texture_for_user_mesh(
|
|
193 |
|
194 |
return textured_save_path
|
195 |
|
|
|
196 |
# --------------------------------------------------------------------------
|
197 |
# 6. INTERFAZ DE USUARIO CON GRADIO
|
198 |
# --------------------------------------------------------------------------
|
@@ -221,20 +219,21 @@ with gr.Blocks(title="Step1X-3D Texture Generator") as demo:
|
|
221 |
|
222 |
# --- L贸gica de la interfaz ---
|
223 |
|
224 |
-
|
225 |
-
demo.
|
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]
|
|
|
9 |
import shutil
|
10 |
|
11 |
# --------------------------------------------------------------------------
|
12 |
+
# BLOQUE 1: INSTALACI脫N DEL ENTORNO Y DEPENDENCIAS (Sin cambios)
|
|
|
13 |
# --------------------------------------------------------------------------
|
14 |
|
15 |
@spaces.GPU(duration=120)
|
|
|
66 |
|
67 |
print("--- CONFIGURACI脫N DEL ENTORNO FINALIZADA ---")
|
68 |
|
|
|
69 |
setup_environment()
|
70 |
|
71 |
# --------------------------------------------------------------------------
|
|
|
125 |
# --------------------------------------------------------------------------
|
126 |
|
127 |
def get_random_seed(randomize_seed, seed):
|
128 |
+
"""Funci贸n auxiliar para determinar la semilla a usar."""
|
129 |
if randomize_seed:
|
130 |
+
seed = random.randint(0, MAX_SEED)
|
131 |
+
print(f"Usando semilla: {seed}")
|
132 |
+
return seed
|
133 |
|
134 |
@spaces.GPU(duration=180)
|
135 |
def generate_texture_for_user_mesh(
|
|
|
137 |
input_mesh_path,
|
138 |
guidance_scale,
|
139 |
inference_steps,
|
140 |
+
seed, # <-- Ahora recibe la semilla final, no el checkbox
|
|
|
141 |
reference_conditioning_scale,
|
142 |
+
req: gr.Request,
|
143 |
progress=gr.Progress(track_tqdm=True)
|
144 |
):
|
145 |
"""
|
|
|
154 |
user_dir = os.path.join(TMP_DIR, session_hash)
|
155 |
print(f"[{session_hash}] Iniciando generaci贸n de textura...")
|
156 |
|
157 |
+
final_seed = int(seed)
|
|
|
158 |
|
159 |
# Actualizar la configuraci贸n del pipeline
|
160 |
texture_model.config.guidance_scale = float(guidance_scale)
|
|
|
190 |
|
191 |
return textured_save_path
|
192 |
|
193 |
+
|
194 |
# --------------------------------------------------------------------------
|
195 |
# 6. INTERFAZ DE USUARIO CON GRADIO
|
196 |
# --------------------------------------------------------------------------
|
|
|
219 |
|
220 |
# --- L贸gica de la interfaz ---
|
221 |
|
222 |
+
demo.load(fn=start_session)
|
223 |
+
demo.unload(fn=end_session)
|
|
|
224 |
|
|
|
225 |
btn_generate.click(
|
226 |
+
fn=get_random_seed,
|
227 |
+
inputs=[randomize_seed_checkbox, seed_input],
|
228 |
+
outputs=[seed_input]
|
229 |
+
).then(
|
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 |
reference_conditioning_scale,
|
238 |
],
|
239 |
outputs=[output_model]
|