Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -48,10 +48,8 @@ def end_session(req: gr.Request):
|
|
48 |
def preprocess_image(image: Image.Image) -> Tuple[str, Image.Image]:
|
49 |
"""
|
50 |
Preprocess the input image.
|
51 |
-
|
52 |
Args:
|
53 |
image (Image.Image): The input image.
|
54 |
-
|
55 |
Returns:
|
56 |
str: uuid of the trial.
|
57 |
Image.Image: The preprocessed image.
|
@@ -120,7 +118,6 @@ def image_to_3d(
|
|
120 |
) -> Tuple[dict, str]:
|
121 |
"""
|
122 |
Convert an image to a 3D model.
|
123 |
-
|
124 |
Args:
|
125 |
image (Image.Image): The input image.
|
126 |
seed (int): The random seed.
|
@@ -128,7 +125,6 @@ def image_to_3d(
|
|
128 |
ss_sampling_steps (int): The number of sampling steps for sparse structure generation.
|
129 |
slat_guidance_strength (float): The guidance strength for structured latent generation.
|
130 |
slat_sampling_steps (int): The number of sampling steps for structured latent generation.
|
131 |
-
|
132 |
Returns:
|
133 |
dict: The information of the generated 3D model.
|
134 |
str: The path to the video of the 3D model.
|
@@ -168,12 +164,10 @@ def extract_glb(
|
|
168 |
) -> Tuple[str, str]:
|
169 |
"""
|
170 |
Extract a GLB file from the 3D model.
|
171 |
-
|
172 |
Args:
|
173 |
state (dict): The state of the generated 3D model.
|
174 |
mesh_simplify (float): The mesh simplification factor.
|
175 |
texture_size (int): The texture resolution.
|
176 |
-
|
177 |
Returns:
|
178 |
str: The path to the extracted GLB file.
|
179 |
"""
|
@@ -187,37 +181,37 @@ def extract_glb(
|
|
187 |
|
188 |
|
189 |
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
190 |
-
gr.Markdown("""""")
|
191 |
-
|
192 |
with gr.Row():
|
193 |
with gr.Column():
|
194 |
-
image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
|
195 |
-
|
196 |
-
with gr.Accordion(label="Generation Settings", open=False):
|
197 |
-
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
|
198 |
-
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
199 |
-
gr.Markdown("Stage 1: Sparse Structure Generation")
|
200 |
with gr.Row():
|
201 |
ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
|
202 |
ss_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
203 |
-
gr.Markdown("Stage 2: Structured Latent Generation")
|
204 |
with gr.Row():
|
205 |
slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=3.0, step=0.1)
|
206 |
slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
207 |
|
208 |
-
generate_btn = gr.Button("Generate")
|
209 |
-
|
210 |
-
with gr.Accordion(label="GLB Extraction Settings", open=False):
|
211 |
mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
|
212 |
texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
|
213 |
-
|
214 |
-
extract_glb_btn = gr.Button("Extract GLB", interactive=False)
|
215 |
|
216 |
with gr.Column():
|
217 |
-
video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
|
218 |
-
model_output = LitModel3D(label="Extracted GLB", exposure=20.0, height=300)
|
219 |
-
download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
|
220 |
-
|
221 |
output_buf = gr.State()
|
222 |
|
223 |
# Example images at the bottom of the page
|
@@ -237,7 +231,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
237 |
# Handlers
|
238 |
demo.load(start_session)
|
239 |
demo.unload(end_session)
|
240 |
-
|
241 |
image_prompt.upload(
|
242 |
preprocess_image,
|
243 |
inputs=[image_prompt],
|
|
|
48 |
def preprocess_image(image: Image.Image) -> Tuple[str, Image.Image]:
|
49 |
"""
|
50 |
Preprocess the input image.
|
|
|
51 |
Args:
|
52 |
image (Image.Image): The input image.
|
|
|
53 |
Returns:
|
54 |
str: uuid of the trial.
|
55 |
Image.Image: The preprocessed image.
|
|
|
118 |
) -> Tuple[dict, str]:
|
119 |
"""
|
120 |
Convert an image to a 3D model.
|
|
|
121 |
Args:
|
122 |
image (Image.Image): The input image.
|
123 |
seed (int): The random seed.
|
|
|
125 |
ss_sampling_steps (int): The number of sampling steps for sparse structure generation.
|
126 |
slat_guidance_strength (float): The guidance strength for structured latent generation.
|
127 |
slat_sampling_steps (int): The number of sampling steps for structured latent generation.
|
|
|
128 |
Returns:
|
129 |
dict: The information of the generated 3D model.
|
130 |
str: The path to the video of the 3D model.
|
|
|
164 |
) -> Tuple[str, str]:
|
165 |
"""
|
166 |
Extract a GLB file from the 3D model.
|
|
|
167 |
Args:
|
168 |
state (dict): The state of the generated 3D model.
|
169 |
mesh_simplify (float): The mesh simplification factor.
|
170 |
texture_size (int): The texture resolution.
|
|
|
171 |
Returns:
|
172 |
str: The path to the extracted GLB file.
|
173 |
"""
|
|
|
181 |
|
182 |
|
183 |
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
184 |
+
gr.Markdown("""<h1 style='color: #4CAF50; text-align: center;'>Image to 3D Model Generator</h1>""")
|
185 |
+
|
186 |
with gr.Row():
|
187 |
with gr.Column():
|
188 |
+
image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300, container_style={"border": "2px solid #4CAF50", "border-radius": "10px", "background-color": "#F9F9F9"})
|
189 |
+
|
190 |
+
with gr.Accordion(label="Generation Settings", open=False, container_style={"border": "1px solid #2196F3", "border-radius": "8px"}):
|
191 |
+
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1, style={"color": "#2196F3"})
|
192 |
+
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True, style={"color": "#2196F3"})
|
193 |
+
gr.Markdown("<strong>Stage 1: Sparse Structure Generation</strong>", style={"color": "#2196F3"})
|
194 |
with gr.Row():
|
195 |
ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
|
196 |
ss_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
197 |
+
gr.Markdown("<strong>Stage 2: Structured Latent Generation</strong>", style={"color": "#2196F3"})
|
198 |
with gr.Row():
|
199 |
slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=3.0, step=0.1)
|
200 |
slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
201 |
|
202 |
+
generate_btn = gr.Button("Generate", style={"background-color": "#4CAF50", "color": "white", "border": "none", "border-radius": "8px"})
|
203 |
+
|
204 |
+
with gr.Accordion(label="GLB Extraction Settings", open=False, container_style={"border": "1px solid #2196F3", "border-radius": "8px"}):
|
205 |
mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
|
206 |
texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
|
207 |
+
|
208 |
+
extract_glb_btn = gr.Button("Extract GLB", interactive=False, style={"background-color": "#FF9800", "color": "white", "border-radius": "8px"})
|
209 |
|
210 |
with gr.Column():
|
211 |
+
video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300, style={"border": "2px solid #4CAF50", "border-radius": "10px"})
|
212 |
+
model_output = LitModel3D(label="Extracted GLB", exposure=20.0, height=300, style={"border": "2px solid #4CAF50", "border-radius": "10px"})
|
213 |
+
download_glb = gr.DownloadButton(label="Download GLB", interactive=False, style={"background-color": "#4CAF50", "color": "white", "border": "none", "border-radius": "8px"})
|
214 |
+
|
215 |
output_buf = gr.State()
|
216 |
|
217 |
# Example images at the bottom of the page
|
|
|
231 |
# Handlers
|
232 |
demo.load(start_session)
|
233 |
demo.unload(end_session)
|
234 |
+
|
235 |
image_prompt.upload(
|
236 |
preprocess_image,
|
237 |
inputs=[image_prompt],
|