Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,6 @@ import shutil
|
|
6 |
|
7 |
# Configuraci贸n inicial para ZeroGPU
|
8 |
os.environ['SPCONV_ALGO'] = 'native'
|
9 |
-
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
10 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = "0" # Asegura usar la GPU asignada por ZeroGPU
|
11 |
|
12 |
from typing import *
|
13 |
import torch
|
@@ -102,13 +100,11 @@ def text_to_3d(
|
|
102 |
"cfg_strength": slat_guidance_strength,
|
103 |
},
|
104 |
)
|
105 |
-
|
106 |
-
# Renderizado de video
|
107 |
video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
|
|
|
|
|
108 |
video_path = os.path.join(user_dir, 'sample.mp4')
|
109 |
imageio.mimsave(video_path, video, fps=15)
|
110 |
-
|
111 |
-
# Empaquetar estado y limpiar memoria
|
112 |
state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
|
113 |
torch.cuda.empty_cache()
|
114 |
return state, video_path
|
@@ -122,23 +118,15 @@ def extract_glb(
|
|
122 |
) -> Tuple[str, str]:
|
123 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
124 |
gs, mesh = unpack_state(state)
|
125 |
-
|
126 |
-
# Exportar GLB con simplificaci贸n de malla
|
127 |
-
glb = postprocessing_utils.to_glb(
|
128 |
-
gs,
|
129 |
-
mesh,
|
130 |
-
simplify=mesh_simplify,
|
131 |
-
texture_size=texture_size,
|
132 |
-
verbose=False
|
133 |
-
)
|
134 |
glb_path = os.path.join(user_dir, 'sample.glb')
|
135 |
glb.export(glb_path)
|
136 |
-
|
137 |
torch.cuda.empty_cache()
|
138 |
return glb_path, glb_path
|
|
|
139 |
|
140 |
# Interfaz Gradio
|
141 |
-
with gr.Blocks(
|
142 |
gr.Markdown("""
|
143 |
# UTPL - Conversi贸n de Texto a objetos 3D usando IA
|
144 |
### Tesis: *"Objetos tridimensionales creados por IA: Innovaci贸n en entornos virtuales"*
|
@@ -149,62 +137,35 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
149 |
|
150 |
with gr.Row():
|
151 |
with gr.Column():
|
152 |
-
|
153 |
-
with gr.Tab(label="Input Image"):
|
154 |
-
text_prompt = gr.Textbox(
|
155 |
-
label="Text Prompt",
|
156 |
-
lines=5
|
157 |
-
)
|
158 |
-
|
159 |
-
with gr.Accordion(".Generation Settings", open=False):
|
160 |
-
with gr.Column(variant="panel"):
|
161 |
-
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
|
162 |
-
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
163 |
-
|
164 |
-
with gr.Group():
|
165 |
-
gr.Markdown("#### Stage 1: Structure")
|
166 |
-
ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance", value=7.5, step=0.1)
|
167 |
-
ss_sampling_steps = gr.Slider(1, 50, label="Steps", value=12, step=1)
|
168 |
-
|
169 |
-
with gr.Group():
|
170 |
-
gr.Markdown("#### Stage 2: Detail")
|
171 |
-
slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance", value=3.0, step=0.1)
|
172 |
-
slat_sampling_steps = gr.Slider(1, 50, label="Steps", value=12, step=1)
|
173 |
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
-
with gr.Accordion("GLB
|
177 |
-
|
178 |
-
|
179 |
-
texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
|
180 |
|
181 |
-
|
|
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
video_output = gr.Video(
|
187 |
-
label="3D Preview",
|
188 |
-
autoplay=True,
|
189 |
-
loop=True,
|
190 |
-
height=300,
|
191 |
-
show_label=False
|
192 |
-
)
|
193 |
-
model_output = LitModel3D(
|
194 |
-
label="3D Model Viewer",
|
195 |
-
exposure=10.0,
|
196 |
-
height=400
|
197 |
-
)
|
198 |
|
199 |
with gr.Row():
|
200 |
-
download_glb = gr.DownloadButton(
|
201 |
-
|
202 |
-
|
203 |
-
variant="secondary",
|
204 |
-
size="lg"
|
205 |
-
)
|
206 |
-
|
207 |
-
output_buf = gr.State({})
|
208 |
|
209 |
# Eventos
|
210 |
demo.load(start_session)
|
|
|
6 |
|
7 |
# Configuraci贸n inicial para ZeroGPU
|
8 |
os.environ['SPCONV_ALGO'] = 'native'
|
|
|
|
|
9 |
|
10 |
from typing import *
|
11 |
import torch
|
|
|
100 |
"cfg_strength": slat_guidance_strength,
|
101 |
},
|
102 |
)
|
|
|
|
|
103 |
video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
|
104 |
+
video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
|
105 |
+
video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
|
106 |
video_path = os.path.join(user_dir, 'sample.mp4')
|
107 |
imageio.mimsave(video_path, video, fps=15)
|
|
|
|
|
108 |
state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
|
109 |
torch.cuda.empty_cache()
|
110 |
return state, video_path
|
|
|
118 |
) -> Tuple[str, str]:
|
119 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
120 |
gs, mesh = unpack_state(state)
|
121 |
+
glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
glb_path = os.path.join(user_dir, 'sample.glb')
|
123 |
glb.export(glb_path)
|
|
|
124 |
torch.cuda.empty_cache()
|
125 |
return glb_path, glb_path
|
126 |
+
|
127 |
|
128 |
# Interfaz Gradio
|
129 |
+
with gr.Blocks() as demo:
|
130 |
gr.Markdown("""
|
131 |
# UTPL - Conversi贸n de Texto a objetos 3D usando IA
|
132 |
### Tesis: *"Objetos tridimensionales creados por IA: Innovaci贸n en entornos virtuales"*
|
|
|
137 |
|
138 |
with gr.Row():
|
139 |
with gr.Column():
|
140 |
+
text_prompt = gr.Textbox(label="Text Prompt", lines=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
+
with gr.Accordion(label="Generation Settings", open=False):
|
143 |
+
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
|
144 |
+
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
145 |
+
with gr.Row():
|
146 |
+
ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
|
147 |
+
ss_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=25, step=1)
|
148 |
+
with gr.Row():
|
149 |
+
slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
|
150 |
+
slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=25, step=1)
|
151 |
+
|
152 |
+
generate_btn = gr.Button("Generate")
|
153 |
|
154 |
+
with gr.Accordion(label="GLB Extraction Settings", open=False):
|
155 |
+
mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
|
156 |
+
texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
|
|
|
157 |
|
158 |
+
with gr.Row():
|
159 |
+
extract_glb_btn = gr.Button("Extract GLB", interactive=False)
|
160 |
|
161 |
+
with gr.Column():
|
162 |
+
video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
|
163 |
+
model_output = LitModel3D(label="Extracted GLB/Gaussian", exposure=10.0, height=300)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
with gr.Row():
|
166 |
+
download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
|
167 |
+
|
168 |
+
output_buf = gr.State()
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
# Eventos
|
171 |
demo.load(start_session)
|