anvilinteractiv commited on
Commit
92f8d79
·
verified ·
1 Parent(s): 9548c9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -13,6 +13,7 @@ import subprocess
13
  import shutil
14
  import base64
15
  import logging
 
16
 
17
  # Set up logging
18
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -291,7 +292,6 @@ def get_random_seed(randomize_seed, seed):
291
  logger.error(f"Error in get_random_seed: {str(e)}")
292
  raise
293
 
294
-
295
  def download_image(url: str, save_path: str) -> str:
296
  """Download an image from a URL and save it locally."""
297
  try:
@@ -340,7 +340,7 @@ def run_segmentation(image):
340
  @spaces.GPU(duration=5)
341
  @torch.no_grad()
342
  def image_to_3d(
343
- image, # Changed to accept FileData dict or PIL Image
344
  seed: int,
345
  num_inference_steps: int,
346
  guidance_scale: float,
@@ -511,7 +511,7 @@ def run_full_api(image, seed: int = 0, num_inference_steps: int = 50, guidance_s
511
  image_seg, mesh_path, textured_glb_path = run_full(image_path, seed, num_inference_steps, guidance_scale, simplify, target_face_num, req)
512
  session_hash = os.path.basename(os.path.dirname(textured_glb_path))
513
  logger.info(f"Generated textured model at /files/{session_hash}/{os.path.basename(textured_glb_path)}")
514
- return {"file_url": f"/files/{session_hash}/{os.path.basename(textured_glb_path)}"}
515
  except Exception as e:
516
  logger.error(f"Error in run_full_api: {str(e)}")
517
  raise
@@ -544,9 +544,8 @@ HEADER = """
544
  ## 🚀 Launch Your Creation:
545
  1. **Upload an Image** (clear, single-object images shine brightest)
546
  2. **Choose a Style Filter** to infuse your unique vision
547
- 3. Click **Generate 3D Model** to sculpt your mesh
548
- 4. Click **Apply Texture** to bring your model to life
549
- 5. **Download GLB** to share your masterpiece
550
  <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>
551
  <style>
552
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
@@ -695,25 +694,21 @@ try:
695
  )
696
  gr.Markdown("Connect with creators in our <a href='https://www.anvilinteractive.com/community' style='color: #A78BFA; text-decoration: none;'>PolyGenixAI Cosmic Community</a>!")
697
  gen_button.click(
698
- run_segmentation,
699
- inputs=[image_prompts],
700
- outputs=[seg_image]
701
- ).then(
702
  get_random_seed,
703
  inputs=[randomize_seed, seed],
704
  outputs=[seed],
705
  ).then(
706
- image_to_3d,
707
  inputs=[
708
- seg_image,
709
  seed,
710
  num_inference_steps,
711
  guidance_scale,
712
  reduce_face,
713
  target_face_num
714
  ],
715
- outputs=[model_output]
716
- ).then(lambda: gr.Button(interactive=True), outputs=[gen_texture_button])
717
  gen_texture_button.click(
718
  run_texture,
719
  inputs=[image_prompts, model_output, seed],
 
13
  import shutil
14
  import base64
15
  import logging
16
+ import requests # Added for download_image
17
 
18
  # Set up logging
19
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
292
  logger.error(f"Error in get_random_seed: {str(e)}")
293
  raise
294
 
 
295
  def download_image(url: str, save_path: str) -> str:
296
  """Download an image from a URL and save it locally."""
297
  try:
 
340
  @spaces.GPU(duration=5)
341
  @torch.no_grad()
342
  def image_to_3d(
343
+ image,
344
  seed: int,
345
  num_inference_steps: int,
346
  guidance_scale: float,
 
511
  image_seg, mesh_path, textured_glb_path = run_full(image_path, seed, num_inference_steps, guidance_scale, simplify, target_face_num, req)
512
  session_hash = os.path.basename(os.path.dirname(textured_glb_path))
513
  logger.info(f"Generated textured model at /files/{session_hash}/{os.path.basename(textured_glb_path)}")
514
+ return {"file_url": f"/files/{session_hash}/{os.path.basename(textured_glb_path)}", "seg_image": image_seg, "mesh_path": mesh_path, "textured_glb_path": textured_glb_path}
515
  except Exception as e:
516
  logger.error(f"Error in run_full_api: {str(e)}")
517
  raise
 
544
  ## 🚀 Launch Your Creation:
545
  1. **Upload an Image** (clear, single-object images shine brightest)
546
  2. **Choose a Style Filter** to infuse your unique vision
547
+ 3. Click **Generate 3D Model** to sculpt your mesh and apply texture
548
+ 4. **Download GLB** to share your masterpiece
 
549
  <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>
550
  <style>
551
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
 
694
  )
695
  gr.Markdown("Connect with creators in our <a href='https://www.anvilinteractive.com/community' style='color: #A78BFA; text-decoration: none;'>PolyGenixAI Cosmic Community</a>!")
696
  gen_button.click(
 
 
 
 
697
  get_random_seed,
698
  inputs=[randomize_seed, seed],
699
  outputs=[seed],
700
  ).then(
701
+ run_full_api,
702
  inputs=[
703
+ image_prompts,
704
  seed,
705
  num_inference_steps,
706
  guidance_scale,
707
  reduce_face,
708
  target_face_num
709
  ],
710
+ outputs=[seg_image, model_output, textured_model_output]
711
+ ).then(lambda: gr.Button(interactive=False), outputs=[gen_texture_button])
712
  gen_texture_button.click(
713
  run_texture,
714
  inputs=[image_prompts, model_output, seed],