Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -141,19 +141,46 @@ def process_3d(input_image, num_steps=50, cfg_scale=7, grid_res=384, seed=42, si
|
|
| 141 |
|
| 142 |
# gradio UI
|
| 143 |
|
| 144 |
-
_TITLE = '''
|
| 145 |
|
| 146 |
_DESCRIPTION = '''
|
| 147 |
-
<div>
|
| 148 |
-
<
|
| 149 |
-
<a style="display:inline-block; margin-left: .5em" href="https://github.com/NVlabs/PartPacker"><img src='https://img.shields.io/github/stars/NVlabs/PartPacker?style=social'/></a>
|
| 150 |
</div>
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
'''
|
| 155 |
|
| 156 |
-
block = gr.Blocks(title=_TITLE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
with block:
|
| 158 |
with gr.Row():
|
| 159 |
with gr.Column():
|
|
@@ -164,32 +191,104 @@ with block:
|
|
| 164 |
with gr.Column(scale=1):
|
| 165 |
with gr.Row():
|
| 166 |
# input image
|
| 167 |
-
input_image = gr.Image(
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
# inference steps
|
| 171 |
-
num_steps = gr.Slider(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
# cfg scale
|
| 173 |
-
cfg_scale = gr.Slider(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
# grid resolution
|
| 175 |
-
input_grid_res = gr.Slider(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
# random seed
|
| 177 |
with gr.Row():
|
| 178 |
-
randomize_seed = gr.Checkbox(
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
# simplify mesh
|
| 181 |
with gr.Row():
|
| 182 |
-
simplify_mesh = gr.Checkbox(
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
with gr.Column(scale=1):
|
| 188 |
# glb file
|
| 189 |
-
output_model = gr.Model3D(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
|
| 192 |
with gr.Row():
|
|
|
|
| 193 |
gr.Examples(
|
| 194 |
examples=[
|
| 195 |
["examples/rabbit.png"],
|
|
@@ -202,11 +301,24 @@ with block:
|
|
| 202 |
["examples/swivelchair.png"],
|
| 203 |
["examples/warhammer.png"],
|
| 204 |
],
|
| 205 |
-
fn=process_image,
|
| 206 |
inputs=[input_image],
|
| 207 |
outputs=[seg_image],
|
| 208 |
cache_examples=False,
|
|
|
|
| 209 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
button_gen.click(
|
| 212 |
process_image, inputs=[input_image], outputs=[seg_image]
|
|
|
|
| 141 |
|
| 142 |
# gradio UI
|
| 143 |
|
| 144 |
+
_TITLE = '''π¨ Image to 3D Model - Bring Your Images to Life!'''
|
| 145 |
|
| 146 |
_DESCRIPTION = '''
|
| 147 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
| 148 |
+
<h3 style="color: #2e7d32;">β¨ Transform 2D Images into Stunning 3D Models with One Click β¨</h3>
|
|
|
|
| 149 |
</div>
|
| 150 |
|
| 151 |
+
### π Key Features:
|
| 152 |
+
- **Smart Recognition**: Automatically identifies objects in images and generates corresponding 3D models
|
| 153 |
+
- **Part Separation**: Generated 3D models are automatically decomposed into multiple parts, each displayed in different colors
|
| 154 |
+
- **Background Removal**: Automatically removes image backgrounds to ensure only the main object is modeled
|
| 155 |
+
- **Universal Format**: Outputs standard GLB format, compatible with various 3D software
|
| 156 |
+
|
| 157 |
+
### π How to Use:
|
| 158 |
+
1. **Upload Image**: Click the "Upload Image" area on the left to upload your picture (supports JPG, PNG, etc.)
|
| 159 |
+
2. **Adjust Settings** (Optional):
|
| 160 |
+
- Higher inference steps = better quality but slower (default 50 recommended)
|
| 161 |
+
- If unsatisfied with results, try different random seeds
|
| 162 |
+
3. **Click Generate**: Click the "Generate 3D Model" button and wait about 1-2 minutes
|
| 163 |
+
4. **View Results**: The 3D model will appear on the right, drag with mouse to rotate and view
|
| 164 |
+
|
| 165 |
+
### π‘ Tips for Best Results:
|
| 166 |
+
- Clear subjects with simple backgrounds work best
|
| 167 |
+
- Front-facing or 45-degree angle photos recommended
|
| 168 |
+
- If results aren't ideal, try adjusting the random seed and regenerating
|
| 169 |
+
- Check the example images below to see optimal input types
|
| 170 |
+
|
| 171 |
+
### π― Use Cases:
|
| 172 |
+
- **Product Display**: Convert product images to 3D models for e-commerce
|
| 173 |
+
- **Creative Design**: Quickly obtain 3D prototypes for design reference
|
| 174 |
+
- **Game Development**: Generate initial 3D models for game assets
|
| 175 |
+
- **Educational Demos**: Convert flat diagrams to 3D for better spatial understanding
|
| 176 |
'''
|
| 177 |
|
| 178 |
+
block = gr.Blocks(title=_TITLE, css="""
|
| 179 |
+
.container { max-width: 1200px; margin: auto; padding: 20px; }
|
| 180 |
+
h1 { text-align: center; color: #1976d2; }
|
| 181 |
+
.examples-gallery { margin-top: 30px; }
|
| 182 |
+
""").queue()
|
| 183 |
+
|
| 184 |
with block:
|
| 185 |
with gr.Row():
|
| 186 |
with gr.Column():
|
|
|
|
| 191 |
with gr.Column(scale=1):
|
| 192 |
with gr.Row():
|
| 193 |
# input image
|
| 194 |
+
input_image = gr.Image(
|
| 195 |
+
label="π· Upload Image",
|
| 196 |
+
type="filepath",
|
| 197 |
+
elem_classes="input-image"
|
| 198 |
+
)
|
| 199 |
+
seg_image = gr.Image(
|
| 200 |
+
label="π Processed Image",
|
| 201 |
+
type="numpy",
|
| 202 |
+
interactive=False,
|
| 203 |
+
image_mode="RGBA"
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
| 207 |
+
gr.Markdown("""
|
| 208 |
+
### Parameter Guide:
|
| 209 |
+
- **Inference Steps**: More steps = higher quality but longer processing time
|
| 210 |
+
- **CFG Scale**: Controls generation accuracy, higher values stay closer to original
|
| 211 |
+
- **Grid Resolution**: 3D model detail level, higher = more detailed
|
| 212 |
+
- **Random Seed**: Same seed produces same results, useful for reproducing effects
|
| 213 |
+
- **Simplify Mesh**: Reduces model face count for lightweight applications
|
| 214 |
+
""")
|
| 215 |
# inference steps
|
| 216 |
+
num_steps = gr.Slider(
|
| 217 |
+
label="Inference Steps",
|
| 218 |
+
minimum=1,
|
| 219 |
+
maximum=100,
|
| 220 |
+
step=1,
|
| 221 |
+
value=50,
|
| 222 |
+
info="Recommended: 30-70"
|
| 223 |
+
)
|
| 224 |
# cfg scale
|
| 225 |
+
cfg_scale = gr.Slider(
|
| 226 |
+
label="CFG Scale",
|
| 227 |
+
minimum=2,
|
| 228 |
+
maximum=10,
|
| 229 |
+
step=0.1,
|
| 230 |
+
value=7.0,
|
| 231 |
+
info="Recommended: 6-8"
|
| 232 |
+
)
|
| 233 |
# grid resolution
|
| 234 |
+
input_grid_res = gr.Slider(
|
| 235 |
+
label="Grid Resolution",
|
| 236 |
+
minimum=256,
|
| 237 |
+
maximum=512,
|
| 238 |
+
step=1,
|
| 239 |
+
value=384,
|
| 240 |
+
info="Recommended: 384"
|
| 241 |
+
)
|
| 242 |
# random seed
|
| 243 |
with gr.Row():
|
| 244 |
+
randomize_seed = gr.Checkbox(
|
| 245 |
+
label="Randomize Seed",
|
| 246 |
+
value=True,
|
| 247 |
+
info="Use different seed each time"
|
| 248 |
+
)
|
| 249 |
+
seed = gr.Slider(
|
| 250 |
+
label="Seed Value",
|
| 251 |
+
minimum=0,
|
| 252 |
+
maximum=MAX_SEED,
|
| 253 |
+
step=1,
|
| 254 |
+
value=0
|
| 255 |
+
)
|
| 256 |
# simplify mesh
|
| 257 |
with gr.Row():
|
| 258 |
+
simplify_mesh = gr.Checkbox(
|
| 259 |
+
label="Simplify Mesh",
|
| 260 |
+
value=False,
|
| 261 |
+
info="Reduce model complexity"
|
| 262 |
+
)
|
| 263 |
+
target_num_faces = gr.Slider(
|
| 264 |
+
label="Target Face Count",
|
| 265 |
+
minimum=10000,
|
| 266 |
+
maximum=1000000,
|
| 267 |
+
step=1000,
|
| 268 |
+
value=100000,
|
| 269 |
+
info="Lower count = simpler model"
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
# gen button
|
| 273 |
+
button_gen = gr.Button("π― Generate 3D Model", variant="primary", size="lg")
|
| 274 |
|
| 275 |
with gr.Column(scale=1):
|
| 276 |
# glb file
|
| 277 |
+
output_model = gr.Model3D(
|
| 278 |
+
label="π 3D Model Preview",
|
| 279 |
+
height=512,
|
| 280 |
+
elem_classes="model-viewer"
|
| 281 |
+
)
|
| 282 |
+
gr.Markdown("""
|
| 283 |
+
### π Controls:
|
| 284 |
+
- π±οΈ **Left Click & Drag**: Rotate model
|
| 285 |
+
- π±οΈ **Right Click & Drag**: Pan view
|
| 286 |
+
- π±οΈ **Scroll Wheel**: Zoom in/out
|
| 287 |
+
- π₯ Click top-right corner to download GLB file
|
| 288 |
+
""")
|
| 289 |
|
|
|
|
| 290 |
with gr.Row():
|
| 291 |
+
gr.Markdown("### πΌοΈ Example Images (Click to Try):")
|
| 292 |
gr.Examples(
|
| 293 |
examples=[
|
| 294 |
["examples/rabbit.png"],
|
|
|
|
| 301 |
["examples/swivelchair.png"],
|
| 302 |
["examples/warhammer.png"],
|
| 303 |
],
|
| 304 |
+
fn=process_image,
|
| 305 |
inputs=[input_image],
|
| 306 |
outputs=[seg_image],
|
| 307 |
cache_examples=False,
|
| 308 |
+
elem_classes="examples-gallery"
|
| 309 |
)
|
| 310 |
+
|
| 311 |
+
gr.Markdown("""
|
| 312 |
+
---
|
| 313 |
+
### β οΈ Important Notes:
|
| 314 |
+
- Generation takes 1-2 minutes, please be patient
|
| 315 |
+
- Best results with clear, prominent subjects
|
| 316 |
+
- Generated models may need further optimization in professional 3D software
|
| 317 |
+
- Each colored section represents an independent 3D part
|
| 318 |
+
|
| 319 |
+
### π€ Technical Support:
|
| 320 |
+
Powered by NVIDIA PartPacker technology. For issues, please refer to the [official documentation](https://research.nvidia.com/labs/dir/partpacker/)
|
| 321 |
+
""")
|
| 322 |
|
| 323 |
button_gen.click(
|
| 324 |
process_image, inputs=[input_image], outputs=[seg_image]
|