Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -52,10 +52,9 @@ HEADER = """
|
|
52 |
## 🚀 Launch Your Creation:
|
53 |
1. **Upload an Image** (clear, single-object images shine brightest)
|
54 |
2. **Choose a Style Filter** to infuse your unique vision
|
55 |
-
3. **
|
56 |
-
4. Click **
|
57 |
-
5.
|
58 |
-
6. **Download** your creation in your chosen format
|
59 |
<p style="font-size: 0.9em; margin-top: 10px; color: #D1D5DB;">Powered by cutting-edge AI and multi-view technology from AnvilInteractive Solutions. Join our <a href="https://www.anvilinteractive.com/community" style="color: #A78BFA; text-decoration: none;">PolyGenixAI Community</a> to connect with creators and spark inspiration.</p>
|
60 |
<style>
|
61 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
|
@@ -193,7 +192,7 @@ def get_random_seed(randomize_seed, seed):
|
|
193 |
return seed
|
194 |
|
195 |
@spaces.GPU(duration=180)
|
196 |
-
def run_full(image: str,
|
197 |
seed = 0
|
198 |
num_inference_steps = 50
|
199 |
guidance_scale = 7.5
|
@@ -218,9 +217,8 @@ def run_full(image: str, output_format: str, req: gr.Request):
|
|
218 |
|
219 |
save_dir = os.path.join(TMP_DIR, "examples")
|
220 |
os.makedirs(save_dir, exist_ok=True)
|
221 |
-
|
222 |
-
|
223 |
-
mesh.export(mesh_path, file_type=file_extension)
|
224 |
print("save to ", mesh_path)
|
225 |
|
226 |
torch.cuda.empty_cache()
|
@@ -297,10 +295,10 @@ def run_full(image: str, output_format: str, req: gr.Request):
|
|
297 |
device=DEVICE,
|
298 |
)
|
299 |
|
300 |
-
|
301 |
mesh_path=mesh_path,
|
302 |
save_dir=save_dir,
|
303 |
-
save_name=f"polygenixai_texture_mesh_{get_random_hex()}.
|
304 |
uv_unwarp=True,
|
305 |
uv_size=4096,
|
306 |
rgb_path=mv_image_path,
|
@@ -308,7 +306,8 @@ def run_full(image: str, output_format: str, req: gr.Request):
|
|
308 |
camera_azimuth_deg=[x - 90 for x in [0, 90, 180, 270, 180, 180]],
|
309 |
)
|
310 |
|
311 |
-
return image_seg, mesh_path,
|
|
|
312 |
|
313 |
@spaces.GPU()
|
314 |
@torch.no_grad()
|
@@ -325,7 +324,6 @@ def image_to_3d(
|
|
325 |
guidance_scale: float,
|
326 |
simplify: bool,
|
327 |
target_face_num: int,
|
328 |
-
output_format: str,
|
329 |
req: gr.Request
|
330 |
):
|
331 |
outputs = triposg_pipe(
|
@@ -343,9 +341,8 @@ def image_to_3d(
|
|
343 |
mesh = simplify_mesh(mesh, target_face_num)
|
344 |
|
345 |
save_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
346 |
-
|
347 |
-
|
348 |
-
mesh.export(mesh_path, file_type=file_extension)
|
349 |
print("save to ", mesh_path)
|
350 |
|
351 |
torch.cuda.empty_cache()
|
@@ -354,7 +351,7 @@ def image_to_3d(
|
|
354 |
|
355 |
@spaces.GPU(duration=120)
|
356 |
@torch.no_grad()
|
357 |
-
def run_texture(image: Image, mesh_path: str, seed: int,
|
358 |
height, width = 768, 768
|
359 |
# Prepare cameras
|
360 |
cameras = get_orthogonal_camera(
|
@@ -428,10 +425,10 @@ def run_texture(image: Image, mesh_path: str, seed: int, output_format: str, req
|
|
428 |
device=DEVICE,
|
429 |
)
|
430 |
|
431 |
-
|
432 |
mesh_path=mesh_path,
|
433 |
save_dir=save_dir,
|
434 |
-
save_name=f"polygenixai_texture_mesh_{get_random_hex()}.
|
435 |
uv_unwarp=True,
|
436 |
uv_size=4096,
|
437 |
rgb_path=mv_image_path,
|
@@ -439,7 +436,7 @@ def run_texture(image: Image, mesh_path: str, seed: int, output_format: str, req
|
|
439 |
camera_azimuth_deg=[x - 90 for x in [0, 90, 180, 270, 180, 180]],
|
440 |
)
|
441 |
|
442 |
-
return
|
443 |
|
444 |
|
445 |
with gr.Blocks(title="PolyGenixAI", css="body { background-color: #1A1A1A; } .gr-panel { background-color: #2D2D2D; }") as demo:
|
@@ -459,13 +456,6 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #1A1A1A; } .gr
|
|
459 |
info="Select a style to inspire your 3D model (optional)",
|
460 |
elem_classes="gr-dropdown"
|
461 |
)
|
462 |
-
output_format = gr.Dropdown(
|
463 |
-
choices=["GLB", "OBJ"],
|
464 |
-
label="Output Format",
|
465 |
-
value="GLB",
|
466 |
-
info="Choose the format for your 3D model",
|
467 |
-
elem_classes="gr-dropdown"
|
468 |
-
)
|
469 |
seed = gr.Slider(
|
470 |
label="Seed",
|
471 |
minimum=0,
|
@@ -508,7 +498,7 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #1A1A1A; } .gr
|
|
508 |
with gr.Column(scale=1):
|
509 |
model_output = gr.Model3D(label="3D Model Preview", interactive=False, height=400, elem_classes="gr-panel")
|
510 |
textured_model_output = gr.Model3D(label="Textured 3D Model", interactive=False, height=400, elem_classes="gr-panel")
|
511 |
-
download_button = gr.Button("Download
|
512 |
|
513 |
with gr.Tab("Cosmic Gallery"):
|
514 |
gr.Markdown("### Discover Stellar Creations")
|
@@ -518,7 +508,7 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #1A1A1A; } .gr
|
|
518 |
for image in os.listdir(f"{TRIPOSG_CODE_DIR}/assets/example_data")
|
519 |
],
|
520 |
fn=run_full,
|
521 |
-
inputs=[image_prompts
|
522 |
outputs=[seg_image, model_output, textured_model_output],
|
523 |
cache_examples=True,
|
524 |
)
|
@@ -540,15 +530,14 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #1A1A1A; } .gr
|
|
540 |
num_inference_steps,
|
541 |
guidance_scale,
|
542 |
reduce_face,
|
543 |
-
target_face_num
|
544 |
-
output_format
|
545 |
],
|
546 |
outputs=[model_output]
|
547 |
).then(lambda: gr.Button(interactive=True), outputs=[gen_texture_button])
|
548 |
|
549 |
gen_texture_button.click(
|
550 |
run_texture,
|
551 |
-
inputs=[image_prompts, model_output, seed
|
552 |
outputs=[textured_model_output]
|
553 |
)
|
554 |
|
|
|
52 |
## 🚀 Launch Your Creation:
|
53 |
1. **Upload an Image** (clear, single-object images shine brightest)
|
54 |
2. **Choose a Style Filter** to infuse your unique vision
|
55 |
+
3. Click **Generate 3D Model** to sculpt your mesh
|
56 |
+
4. Click **Apply Texture** to bring your model to life
|
57 |
+
5. **Download GLB** to share your masterpiece
|
|
|
58 |
<p style="font-size: 0.9em; margin-top: 10px; color: #D1D5DB;">Powered by cutting-edge AI and multi-view technology from AnvilInteractive Solutions. Join our <a href="https://www.anvilinteractive.com/community" style="color: #A78BFA; text-decoration: none;">PolyGenixAI Community</a> to connect with creators and spark inspiration.</p>
|
59 |
<style>
|
60 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
|
|
|
192 |
return seed
|
193 |
|
194 |
@spaces.GPU(duration=180)
|
195 |
+
def run_full(image: str, req: gr.Request):
|
196 |
seed = 0
|
197 |
num_inference_steps = 50
|
198 |
guidance_scale = 7.5
|
|
|
217 |
|
218 |
save_dir = os.path.join(TMP_DIR, "examples")
|
219 |
os.makedirs(save_dir, exist_ok=True)
|
220 |
+
mesh_path = os.path.join(save_dir, f"polygenixai_{get_random_hex()}.glb")
|
221 |
+
mesh.export(mesh_path)
|
|
|
222 |
print("save to ", mesh_path)
|
223 |
|
224 |
torch.cuda.empty_cache()
|
|
|
295 |
device=DEVICE,
|
296 |
)
|
297 |
|
298 |
+
textured_glb_path = texture_pipe(
|
299 |
mesh_path=mesh_path,
|
300 |
save_dir=save_dir,
|
301 |
+
save_name=f"polygenixai_texture_mesh_{get_random_hex()}.glb",
|
302 |
uv_unwarp=True,
|
303 |
uv_size=4096,
|
304 |
rgb_path=mv_image_path,
|
|
|
306 |
camera_azimuth_deg=[x - 90 for x in [0, 90, 180, 270, 180, 180]],
|
307 |
)
|
308 |
|
309 |
+
return image_seg, mesh_path, textured_glb_path
|
310 |
+
|
311 |
|
312 |
@spaces.GPU()
|
313 |
@torch.no_grad()
|
|
|
324 |
guidance_scale: float,
|
325 |
simplify: bool,
|
326 |
target_face_num: int,
|
|
|
327 |
req: gr.Request
|
328 |
):
|
329 |
outputs = triposg_pipe(
|
|
|
341 |
mesh = simplify_mesh(mesh, target_face_num)
|
342 |
|
343 |
save_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
344 |
+
mesh_path = os.path.join(save_dir, f"polygenixai_{get_random_hex()}.glb")
|
345 |
+
mesh.export(mesh_path)
|
|
|
346 |
print("save to ", mesh_path)
|
347 |
|
348 |
torch.cuda.empty_cache()
|
|
|
351 |
|
352 |
@spaces.GPU(duration=120)
|
353 |
@torch.no_grad()
|
354 |
+
def run_texture(image: Image, mesh_path: str, seed: int, req: gr.Request):
|
355 |
height, width = 768, 768
|
356 |
# Prepare cameras
|
357 |
cameras = get_orthogonal_camera(
|
|
|
425 |
device=DEVICE,
|
426 |
)
|
427 |
|
428 |
+
textured_glb_path = texture_pipe(
|
429 |
mesh_path=mesh_path,
|
430 |
save_dir=save_dir,
|
431 |
+
save_name=f"polygenixai_texture_mesh_{get_random_hex()}.glb",
|
432 |
uv_unwarp=True,
|
433 |
uv_size=4096,
|
434 |
rgb_path=mv_image_path,
|
|
|
436 |
camera_azimuth_deg=[x - 90 for x in [0, 90, 180, 270, 180, 180]],
|
437 |
)
|
438 |
|
439 |
+
return textured_glb_path
|
440 |
|
441 |
|
442 |
with gr.Blocks(title="PolyGenixAI", css="body { background-color: #1A1A1A; } .gr-panel { background-color: #2D2D2D; }") as demo:
|
|
|
456 |
info="Select a style to inspire your 3D model (optional)",
|
457 |
elem_classes="gr-dropdown"
|
458 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
seed = gr.Slider(
|
460 |
label="Seed",
|
461 |
minimum=0,
|
|
|
498 |
with gr.Column(scale=1):
|
499 |
model_output = gr.Model3D(label="3D Model Preview", interactive=False, height=400, elem_classes="gr-panel")
|
500 |
textured_model_output = gr.Model3D(label="Textured 3D Model", interactive=False, height=400, elem_classes="gr-panel")
|
501 |
+
download_button = gr.Button("Download GLB", variant="secondary", elem_classes="gr-button-secondary")
|
502 |
|
503 |
with gr.Tab("Cosmic Gallery"):
|
504 |
gr.Markdown("### Discover Stellar Creations")
|
|
|
508 |
for image in os.listdir(f"{TRIPOSG_CODE_DIR}/assets/example_data")
|
509 |
],
|
510 |
fn=run_full,
|
511 |
+
inputs=[image_prompts],
|
512 |
outputs=[seg_image, model_output, textured_model_output],
|
513 |
cache_examples=True,
|
514 |
)
|
|
|
530 |
num_inference_steps,
|
531 |
guidance_scale,
|
532 |
reduce_face,
|
533 |
+
target_face_num
|
|
|
534 |
],
|
535 |
outputs=[model_output]
|
536 |
).then(lambda: gr.Button(interactive=True), outputs=[gen_texture_button])
|
537 |
|
538 |
gen_texture_button.click(
|
539 |
run_texture,
|
540 |
+
inputs=[image_prompts, model_output, seed],
|
541 |
outputs=[textured_model_output]
|
542 |
)
|
543 |
|