Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,38 +46,84 @@ sys.path.append(MV_ADAPTER_CODE_DIR)
|
|
| 46 |
sys.path.append(os.path.join(MV_ADAPTER_CODE_DIR, "scripts"))
|
| 47 |
|
| 48 |
HEADER = """
|
| 49 |
-
#
|
| 50 |
-
## Unleash
|
| 51 |
-
<p style="font-size: 1.1em;">By <a href="https://www.anvilinteractive.com/" style="color: #
|
| 52 |
-
## 🚀
|
| 53 |
-
1. **Upload an Image** (clear, single-object images
|
| 54 |
-
2. **
|
| 55 |
-
3. Click **Generate 3D Model** to
|
| 56 |
-
4. Click **Apply Texture** to
|
| 57 |
-
5. **Download GLB** to
|
| 58 |
-
<p style="font-size: 0.9em; margin-top: 10px;">Powered by
|
| 59 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
.gr-button-primary {
|
| 61 |
-
background
|
| 62 |
color: white !important;
|
|
|
|
| 63 |
border-radius: 8px !important;
|
| 64 |
-
padding:
|
| 65 |
font-weight: 600 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
}
|
| 67 |
.gr-button-secondary {
|
| 68 |
-
background-color: #
|
| 69 |
-
color: #
|
|
|
|
| 70 |
border-radius: 8px !important;
|
| 71 |
padding: 10px 20px !important;
|
|
|
|
| 72 |
}
|
| 73 |
-
.gr-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
padding: 20px !important;
|
| 77 |
}
|
| 78 |
.gr-accordion {
|
| 79 |
-
background-color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
border-radius: 8px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
}
|
| 82 |
</style>
|
| 83 |
"""
|
|
@@ -393,28 +439,30 @@ def run_texture(image: Image, mesh_path: str, seed: int, req: gr.Request):
|
|
| 393 |
return textured_glb_path
|
| 394 |
|
| 395 |
|
| 396 |
-
with gr.Blocks(title="PolyGenixAI", css="body { background-color: #
|
| 397 |
gr.Markdown(HEADER)
|
| 398 |
|
| 399 |
-
with gr.Tabs():
|
| 400 |
with gr.Tab("Create 3D Model"):
|
| 401 |
with gr.Row():
|
| 402 |
with gr.Column(scale=1):
|
| 403 |
-
image_prompts = gr.Image(label="Upload Image", type="filepath", height=300)
|
| 404 |
-
seg_image = gr.Image(label="Preview Segmentation", type="pil", format="png", interactive=False, height=300)
|
| 405 |
-
with gr.Accordion("Style & Settings", open=True):
|
| 406 |
style_filter = gr.Dropdown(
|
| 407 |
-
choices=["None", "Realistic", "Fantasy", "Cartoon", "Sci-Fi", "Vintage"],
|
| 408 |
label="Style Filter",
|
| 409 |
value="None",
|
| 410 |
-
info="Select a style to
|
|
|
|
| 411 |
)
|
| 412 |
seed = gr.Slider(
|
| 413 |
label="Seed",
|
| 414 |
minimum=0,
|
| 415 |
maximum=MAX_SEED,
|
| 416 |
step=1,
|
| 417 |
-
value=0
|
|
|
|
| 418 |
)
|
| 419 |
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 420 |
num_inference_steps = gr.Slider(
|
|
@@ -423,7 +471,8 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #F3F4F6; } .gr
|
|
| 423 |
maximum=50,
|
| 424 |
step=1,
|
| 425 |
value=50,
|
| 426 |
-
info="Higher steps
|
|
|
|
| 427 |
)
|
| 428 |
guidance_scale = gr.Slider(
|
| 429 |
label="Guidance Scale",
|
|
@@ -431,7 +480,8 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #F3F4F6; } .gr
|
|
| 431 |
maximum=20.0,
|
| 432 |
step=0.1,
|
| 433 |
value=7.0,
|
| 434 |
-
info="Controls
|
|
|
|
| 435 |
)
|
| 436 |
reduce_face = gr.Checkbox(label="Simplify Mesh", value=True)
|
| 437 |
target_face_num = gr.Slider(
|
|
@@ -439,18 +489,19 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #F3F4F6; } .gr
|
|
| 439 |
minimum=10000,
|
| 440 |
value=DEFAULT_FACE_NUMBER,
|
| 441 |
label="Target Face Number",
|
| 442 |
-
info="Adjust mesh complexity"
|
|
|
|
| 443 |
)
|
| 444 |
-
gen_button = gr.Button("Generate 3D Model", variant="primary")
|
| 445 |
-
gen_texture_button = gr.Button("Apply Texture", variant="secondary", interactive=False)
|
| 446 |
|
| 447 |
with gr.Column(scale=1):
|
| 448 |
-
model_output = gr.Model3D(label="3D Model Preview", interactive=False, height=400)
|
| 449 |
-
textured_model_output = gr.Model3D(label="Textured 3D Model", interactive=False, height=400)
|
| 450 |
-
download_button = gr.Button("Download GLB", variant="secondary")
|
| 451 |
|
| 452 |
-
with gr.Tab("Gallery
|
| 453 |
-
gr.Markdown("###
|
| 454 |
gr.Examples(
|
| 455 |
examples=[
|
| 456 |
f"{TRIPOSG_CODE_DIR}/assets/example_data/{image}"
|
|
@@ -461,7 +512,7 @@ with gr.Blocks(title="PolyGenixAI", css="body { background-color: #F3F4F6; } .gr
|
|
| 461 |
outputs=[seg_image, model_output, textured_model_output],
|
| 462 |
cache_examples=True,
|
| 463 |
)
|
| 464 |
-
gr.Markdown("
|
| 465 |
|
| 466 |
gen_button.click(
|
| 467 |
run_segmentation,
|
|
|
|
| 46 |
sys.path.append(os.path.join(MV_ADAPTER_CODE_DIR, "scripts"))
|
| 47 |
|
| 48 |
HEADER = """
|
| 49 |
+
# 🌌 PolyGenixAI: Craft 3D Worlds with Cosmic Precision
|
| 50 |
+
## Unleash Infinite Creativity with AI-Powered 3D Generation by AnvilInteractive Solutions
|
| 51 |
+
<p style="font-size: 1.1em; color: #A78BFA;">By <a href="https://www.anvilinteractive.com/" style="color: #A78BFA; text-decoration: none; font-weight: bold;">AnvilInteractive Solutions</a></p>
|
| 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');
|
| 61 |
+
body {
|
| 62 |
+
background-color: #1A1A1A !important;
|
| 63 |
+
font-family: 'Inter', sans-serif !important;
|
| 64 |
+
color: #D1D5DB !important;
|
| 65 |
+
}
|
| 66 |
+
.gr-panel {
|
| 67 |
+
background-color: #2D2D2D !important;
|
| 68 |
+
border: 1px solid #7C3AED !important;
|
| 69 |
+
border-radius: 12px !important;
|
| 70 |
+
padding: 20px !important;
|
| 71 |
+
box-shadow: 0 4px 10px rgba(124, 58, 237, 0.2) !important;
|
| 72 |
+
}
|
| 73 |
.gr-button-primary {
|
| 74 |
+
background: linear-gradient(45deg, #7C3AED, #A78BFA) !important;
|
| 75 |
color: white !important;
|
| 76 |
+
border: none !important;
|
| 77 |
border-radius: 8px !important;
|
| 78 |
+
padding: 12px 24px !important;
|
| 79 |
font-weight: 600 !important;
|
| 80 |
+
transition: transform 0.2s, box-shadow 0.2s !important;
|
| 81 |
+
}
|
| 82 |
+
.gr-button-primary:hover {
|
| 83 |
+
transform: translateY(-2px) !important;
|
| 84 |
+
box-shadow: 0 4px 12px rgba(124, 58, 237, 0.5) !important;
|
| 85 |
}
|
| 86 |
.gr-button-secondary {
|
| 87 |
+
background-color: #4B4B4B !important;
|
| 88 |
+
color: #D1D5DB !important;
|
| 89 |
+
border: 1px solid #A78BFA !important;
|
| 90 |
border-radius: 8px !important;
|
| 91 |
padding: 10px 20px !important;
|
| 92 |
+
transition: transform 0.2s !important;
|
| 93 |
}
|
| 94 |
+
.gr-button-secondary:hover {
|
| 95 |
+
transform: translateY(-1px) !important;
|
| 96 |
+
background-color: #6B6B6B !important;
|
|
|
|
| 97 |
}
|
| 98 |
.gr-accordion {
|
| 99 |
+
background-color: #2D2D2D !important;
|
| 100 |
+
border-radius: 8px !important;
|
| 101 |
+
border: 1px solid #7C3AED !important;
|
| 102 |
+
}
|
| 103 |
+
.gr-tab {
|
| 104 |
+
background-color: #2D2D2D !important;
|
| 105 |
+
color: #A78BFA !important;
|
| 106 |
+
border: 1px solid #7C3AED !important;
|
| 107 |
border-radius: 8px !important;
|
| 108 |
+
margin: 5px !important;
|
| 109 |
+
}
|
| 110 |
+
.gr-tab:hover, .gr-tab-selected {
|
| 111 |
+
background: linear-gradient(45deg, #7C3AED, #A78BFA) !important;
|
| 112 |
+
color: white !important;
|
| 113 |
+
}
|
| 114 |
+
.gr-slider input[type=range]::-webkit-slider-thumb {
|
| 115 |
+
background-color: #7C3AED !important;
|
| 116 |
+
border: 2px solid #A78BFA !important;
|
| 117 |
+
}
|
| 118 |
+
.gr-dropdown {
|
| 119 |
+
background-color: #2D2D2D !important;
|
| 120 |
+
color: #D1D5DB !important;
|
| 121 |
+
border: 1px solid #A78BFA !important;
|
| 122 |
+
border-radius: 8px !important;
|
| 123 |
+
}
|
| 124 |
+
h1, h3 {
|
| 125 |
+
color: #A78BFA !important;
|
| 126 |
+
text-shadow: 0 0 10px rgba(124, 58, 237, 0.5) !important;
|
| 127 |
}
|
| 128 |
</style>
|
| 129 |
"""
|
|
|
|
| 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:
|
| 443 |
gr.Markdown(HEADER)
|
| 444 |
|
| 445 |
+
with gr.Tabs(elem_classes="gr-tab"):
|
| 446 |
with gr.Tab("Create 3D Model"):
|
| 447 |
with gr.Row():
|
| 448 |
with gr.Column(scale=1):
|
| 449 |
+
image_prompts = gr.Image(label="Upload Image", type="filepath", height=300, elem_classes="gr-panel")
|
| 450 |
+
seg_image = gr.Image(label="Preview Segmentation", type="pil", format="png", interactive=False, height=300, elem_classes="gr-panel")
|
| 451 |
+
with gr.Accordion("Style & Settings", open=True, elem_classes="gr-accordion"):
|
| 452 |
style_filter = gr.Dropdown(
|
| 453 |
+
choices=["None", "Realistic", "Fantasy", "Cartoon", "Sci-Fi", "Vintage", "Cosmic", "Neon"],
|
| 454 |
label="Style Filter",
|
| 455 |
value="None",
|
| 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,
|
| 462 |
maximum=MAX_SEED,
|
| 463 |
step=1,
|
| 464 |
+
value=0,
|
| 465 |
+
elem_classes="gr-slider"
|
| 466 |
)
|
| 467 |
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 468 |
num_inference_steps = gr.Slider(
|
|
|
|
| 471 |
maximum=50,
|
| 472 |
step=1,
|
| 473 |
value=50,
|
| 474 |
+
info="Higher steps enhance detail but increase processing time",
|
| 475 |
+
elem_classes="gr-slider"
|
| 476 |
)
|
| 477 |
guidance_scale = gr.Slider(
|
| 478 |
label="Guidance Scale",
|
|
|
|
| 480 |
maximum=20.0,
|
| 481 |
step=0.1,
|
| 482 |
value=7.0,
|
| 483 |
+
info="Controls adherence to input image",
|
| 484 |
+
elem_classes="gr-slider"
|
| 485 |
)
|
| 486 |
reduce_face = gr.Checkbox(label="Simplify Mesh", value=True)
|
| 487 |
target_face_num = gr.Slider(
|
|
|
|
| 489 |
minimum=10000,
|
| 490 |
value=DEFAULT_FACE_NUMBER,
|
| 491 |
label="Target Face Number",
|
| 492 |
+
info="Adjust mesh complexity for performance",
|
| 493 |
+
elem_classes="gr-slider"
|
| 494 |
)
|
| 495 |
+
gen_button = gr.Button("Generate 3D Model", variant="primary", elem_classes="gr-button-primary")
|
| 496 |
+
gen_texture_button = gr.Button("Apply Texture", variant="secondary", interactive=False, elem_classes="gr-button-secondary")
|
| 497 |
|
| 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")
|
| 505 |
gr.Examples(
|
| 506 |
examples=[
|
| 507 |
f"{TRIPOSG_CODE_DIR}/assets/example_data/{image}"
|
|
|
|
| 512 |
outputs=[seg_image, model_output, textured_model_output],
|
| 513 |
cache_examples=True,
|
| 514 |
)
|
| 515 |
+
gr.Markdown("Connect with creators in our <a href='https://www.anvilinteractive.com/community' style='color: #A78BFA; text-decoration: none;'>PolyGenixAI Cosmic Community</a>!")
|
| 516 |
|
| 517 |
gen_button.click(
|
| 518 |
run_segmentation,
|