Spaces:
cpuai
/
Running on Zero

cpuai commited on
Commit
2fbebcf
Β·
verified Β·
1 Parent(s): 098a71e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +134 -22
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 = '''PartPacker: Efficient Part-level 3D Object Generation via Dual Volume Packing'''
145
 
146
  _DESCRIPTION = '''
147
- <div>
148
- <a style="display:inline-block" href="https://research.nvidia.com/labs/dir/partpacker/"><img src='https://img.shields.io/badge/public_website-8A2BE2'></a>
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
- * Each part is visualized with a random color, and can be separated in the GLB file.
153
- * If the output is not satisfactory, please try different random seeds!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  '''
155
 
156
- block = gr.Blocks(title=_TITLE).queue()
 
 
 
 
 
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(label="Input Image", type="filepath") # use file_path and load manually
168
- seg_image = gr.Image(label="Segmentation Result", type="numpy", interactive=False, image_mode="RGBA")
169
- with gr.Accordion("Settings", open=True):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  # inference steps
171
- num_steps = gr.Slider(label="Inference steps", minimum=1, maximum=100, step=1, value=50)
 
 
 
 
 
 
 
172
  # cfg scale
173
- cfg_scale = gr.Slider(label="CFG scale", minimum=2, maximum=10, step=0.1, value=7.0)
 
 
 
 
 
 
 
174
  # grid resolution
175
- input_grid_res = gr.Slider(label="Grid resolution", minimum=256, maximum=512, step=1, value=384)
 
 
 
 
 
 
 
176
  # random seed
177
  with gr.Row():
178
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
179
- seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
 
 
 
 
 
 
 
 
 
 
180
  # simplify mesh
181
  with gr.Row():
182
- simplify_mesh = gr.Checkbox(label="Simplify mesh", value=False)
183
- target_num_faces = gr.Slider(label="Face number", minimum=10000, maximum=1000000, step=1000, value=100000)
184
- # gen button
185
- button_gen = gr.Button("Generate")
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
  with gr.Column(scale=1):
188
  # glb file
189
- output_model = gr.Model3D(label="Geometry", height=512)
 
 
 
 
 
 
 
 
 
 
 
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, # still need to click button_gen to get the 3d
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]