vaibhavpandeyvpz commited on
Commit
5549840
ยท
1 Parent(s): 458170a

Fix 3D generation

Browse files
Files changed (2) hide show
  1. README.md +6 -5
  2. app.py +22 -17
README.md CHANGED
@@ -26,9 +26,9 @@ This Hugging Face Space provides a complete workflow to generate 3D models from
26
  ## Features
27
 
28
  - ๐ŸŽจ **Text to Image**: Generate images using Stable Diffusion XL base model
 
29
  - โœ‚๏ธ **Automatic Background Removal**: Background removal is handled automatically by Stable Fast 3D
30
- - ๐ŸŽฎ **3D Generation**: Create textured 3D mesh models from images
31
- - ๐Ÿ”„ **Step-by-step Workflow**: Review and confirm at each step
32
  - โš™๏ธ **Customizable**: Adjust remeshing options, vertex count, and texture resolution
33
 
34
  ## How to Use
@@ -40,14 +40,15 @@ This Hugging Face Space provides a complete workflow to generate 3D models from
40
  - Click "Generate Image" and wait for the result
41
 
42
  2. **Step 2 - 3D Generation**:
43
- - Review the generated image
 
44
  - Adjust 3D generation settings:
45
  - **Remeshing Option**: Choose "none", "triangle", or "quad" remeshing
46
  - **Target Vertex Count**: Set to -1 for automatic, or specify a target count
47
  - **Texture Size**: Choose texture resolution (512-2048)
48
- - Click "Continue to 3D Generation" to create the 3D model
49
  - Background removal is handled automatically by Stable Fast 3D
50
- - Download your GLB file
51
 
52
  ## Tips
53
 
 
26
  ## Features
27
 
28
  - ๐ŸŽจ **Text to Image**: Generate images using Stable Diffusion XL base model
29
+ - ๐Ÿ“ค **Flexible Input**: Use generated images or upload your own images for 3D generation
30
  - โœ‚๏ธ **Automatic Background Removal**: Background removal is handled automatically by Stable Fast 3D
31
+ - ๐ŸŽฎ **3D Generation**: Create textured 3D mesh models from images with live preview
 
32
  - โš™๏ธ **Customizable**: Adjust remeshing options, vertex count, and texture resolution
33
 
34
  ## How to Use
 
40
  - Click "Generate Image" and wait for the result
41
 
42
  2. **Step 2 - 3D Generation**:
43
+ - The generated image from Step 1 is automatically filled in the input field
44
+ - **OR** upload your own image to skip Step 1 entirely
45
  - Adjust 3D generation settings:
46
  - **Remeshing Option**: Choose "none", "triangle", or "quad" remeshing
47
  - **Target Vertex Count**: Set to -1 for automatic, or specify a target count
48
  - **Texture Size**: Choose texture resolution (512-2048)
49
+ - Click "Generate 3D Model" to create the 3D model
50
  - Background removal is handled automatically by Stable Fast 3D
51
+ - View the 3D model preview and download your GLB file
52
 
53
  ## Tips
54
 
app.py CHANGED
@@ -265,23 +265,26 @@ def generate_3d_from_image(
265
  def step1_generate_image(prompt, negative_prompt, num_steps):
266
  """Step 1: Generate image from text."""
267
  if not prompt:
268
- return None, gr.update(visible=False), "Please enter a prompt"
269
 
270
  try:
271
  image = generate_text_to_image(prompt, negative_prompt, num_steps)
272
  return (
273
  image,
274
- gr.update(visible=True, value="Continue to 3D Generation"),
275
- "Image generated successfully! Review and continue to generate 3D model.",
276
  )
277
  except Exception as e:
278
- return None, gr.update(visible=False), f"Error generating image: {str(e)}"
279
 
280
 
281
  def step2_generate_3d(image, remesh_option, vertex_count, texture_size):
282
  """Step 2: Generate 3D model from image (with built-in background removal)."""
283
  if image is None:
284
- return gr.update(value=None, visible=False), "Please generate an image first"
 
 
 
285
 
286
  try:
287
  glb_file = generate_3d_from_image(
@@ -290,7 +293,7 @@ def step2_generate_3d(image, remesh_option, vertex_count, texture_size):
290
 
291
  return (
292
  gr.update(value=glb_file, visible=True),
293
- "3D model generated successfully! Background removal was handled automatically. You can download the model below.",
294
  )
295
  except Exception as e:
296
  return (
@@ -340,20 +343,22 @@ with gr.Blocks(title="Text to Image to 3D") as demo:
340
  )
341
  generate_btn = gr.Button("Generate Image", variant="primary")
342
  step1_status = gr.Textbox(label="Status", interactive=False)
343
- step1_continue_btn = gr.Button(
344
- "Continue to 3D Generation",
345
- visible=False,
346
- variant="secondary",
347
- )
348
 
349
  with gr.Column(scale=1):
350
  step1_image = gr.Image(label="Generated Image", type="pil")
351
 
352
  # Step 2: 3D Generation
353
  gr.Markdown("## Step 2: 3D Generation")
354
- gr.Markdown("*Background removal is handled automatically*")
 
 
355
  with gr.Row():
356
  with gr.Column(scale=1):
 
 
 
 
 
357
  remesh_option = gr.Radio(
358
  choices=["none", "triangle", "quad"],
359
  label="Remeshing Option",
@@ -378,8 +383,8 @@ with gr.Blocks(title="Text to Image to 3D") as demo:
378
 
379
  with gr.Column(scale=1):
380
  step2_output = LitModel3D(
381
- label="3D Model",
382
- visible=False,
383
  clear_color=[0.0, 0.0, 0.0, 0.0],
384
  )
385
 
@@ -387,12 +392,12 @@ with gr.Blocks(title="Text to Image to 3D") as demo:
387
  generate_btn.click(
388
  fn=step1_generate_image,
389
  inputs=[prompt, negative_prompt, num_steps],
390
- outputs=[step1_image, step1_continue_btn, step1_status],
391
  )
392
 
393
- step1_continue_btn.click(
394
  fn=step2_generate_3d,
395
- inputs=[step1_image, remesh_option, vertex_count, texture_size],
396
  outputs=[step2_output, step2_status],
397
  )
398
 
 
265
  def step1_generate_image(prompt, negative_prompt, num_steps):
266
  """Step 1: Generate image from text."""
267
  if not prompt:
268
+ return None, None, "Please enter a prompt"
269
 
270
  try:
271
  image = generate_text_to_image(prompt, negative_prompt, num_steps)
272
  return (
273
  image,
274
+ image, # Auto-fill Step 2 image input
275
+ "Image generated successfully! The image has been automatically filled in Step 2. You can also upload your own image in Step 2.",
276
  )
277
  except Exception as e:
278
+ return None, None, f"Error generating image: {str(e)}"
279
 
280
 
281
  def step2_generate_3d(image, remesh_option, vertex_count, texture_size):
282
  """Step 2: Generate 3D model from image (with built-in background removal)."""
283
  if image is None:
284
+ return (
285
+ gr.update(value=None, visible=False),
286
+ "Please provide an image (generate one in Step 1 or upload your own)",
287
+ )
288
 
289
  try:
290
  glb_file = generate_3d_from_image(
 
293
 
294
  return (
295
  gr.update(value=glb_file, visible=True),
296
+ "3D model generated successfully! Background removal was handled automatically. You can view and download the model below.",
297
  )
298
  except Exception as e:
299
  return (
 
343
  )
344
  generate_btn = gr.Button("Generate Image", variant="primary")
345
  step1_status = gr.Textbox(label="Status", interactive=False)
 
 
 
 
 
346
 
347
  with gr.Column(scale=1):
348
  step1_image = gr.Image(label="Generated Image", type="pil")
349
 
350
  # Step 2: 3D Generation
351
  gr.Markdown("## Step 2: 3D Generation")
352
+ gr.Markdown(
353
+ "*Background removal is handled automatically. You can use the image from Step 1 or upload your own image.*"
354
+ )
355
  with gr.Row():
356
  with gr.Column(scale=1):
357
+ step2_image_input = gr.Image(
358
+ label="Input Image",
359
+ type="pil",
360
+ sources=["upload", "clipboard"],
361
+ )
362
  remesh_option = gr.Radio(
363
  choices=["none", "triangle", "quad"],
364
  label="Remeshing Option",
 
383
 
384
  with gr.Column(scale=1):
385
  step2_output = LitModel3D(
386
+ label="3D Model Preview",
387
+ visible=True,
388
  clear_color=[0.0, 0.0, 0.0, 0.0],
389
  )
390
 
 
392
  generate_btn.click(
393
  fn=step1_generate_image,
394
  inputs=[prompt, negative_prompt, num_steps],
395
+ outputs=[step1_image, step2_image_input, step1_status],
396
  )
397
 
398
+ step2_generate_btn.click(
399
  fn=step2_generate_3d,
400
+ inputs=[step2_image_input, remesh_option, vertex_count, texture_size],
401
  outputs=[step2_output, step2_status],
402
  )
403