anvilinteractiv commited on
Commit
4d67a8e
·
verified ·
1 Parent(s): 6417969

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -13,7 +13,6 @@ import subprocess
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,6 +291,7 @@ def get_random_seed(randomize_seed, seed):
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,7 +340,7 @@ def run_segmentation(image):
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,
@@ -485,7 +485,7 @@ def run_texture(image: Image, mesh_path: str, seed: int, req: gr.Request):
485
  logger.error(f"Error in run_texture: {str(e)}")
486
  raise
487
 
488
- @spaces.GPU(duration=10)
489
  @torch.no_grad()
490
  def run_full_api(image, seed: int = 0, num_inference_steps: int = 50, guidance_scale: float = 7.5, simplify: bool = True, target_face_num: int = DEFAULT_FACE_NUMBER, req: gr.Request = None):
491
  try:
@@ -509,8 +509,9 @@ def run_full_api(image, seed: int = 0, num_inference_steps: int = 50, guidance_s
509
  raise ValueError(f"Invalid image path: {image_path}")
510
 
511
  image_seg, mesh_path, textured_glb_path = run_full(image_path, seed, num_inference_steps, guidance_scale, simplify, target_face_num, req)
512
- logger.info(f"Generated textured model at /files/{os.path.basename(os.path.dirname(textured_glb_path))}/{os.path.basename(textured_glb_path)}")
513
- return image_seg, mesh_path, textured_glb_path # Return tuple instead of dictionary
 
514
  except Exception as e:
515
  logger.error(f"Error in run_full_api: {str(e)}")
516
  raise
@@ -543,8 +544,9 @@ HEADER = """
543
  ## 🚀 Launch Your Creation:
544
  1. **Upload an Image** (clear, single-object images shine brightest)
545
  2. **Choose a Style Filter** to infuse your unique vision
546
- 3. Click **Generate 3D Model** to sculpt your mesh and apply texture
547
- 4. **Download GLB** to share your masterpiece
 
548
  <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>
549
  <style>
550
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
@@ -693,21 +695,25 @@ try:
693
  )
694
  gr.Markdown("Connect with creators in our <a href='https://www.anvilinteractive.com/community' style='color: #A78BFA; text-decoration: none;'>PolyGenixAI Cosmic Community</a>!")
695
  gen_button.click(
 
 
 
 
696
  get_random_seed,
697
  inputs=[randomize_seed, seed],
698
  outputs=[seed],
699
  ).then(
700
- run_full_api,
701
  inputs=[
702
- image_prompts,
703
  seed,
704
  num_inference_steps,
705
  guidance_scale,
706
  reduce_face,
707
  target_face_num
708
  ],
709
- outputs=[seg_image, model_output, textured_model_output]
710
- ).then(lambda: gr.Button(interactive=False), outputs=[gen_texture_button])
711
  gen_texture_button.click(
712
  run_texture,
713
  inputs=[image_prompts, model_output, seed],
 
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
  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
  @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,
 
485
  logger.error(f"Error in run_texture: {str(e)}")
486
  raise
487
 
488
+ @spaces.GPU(duration=5)
489
  @torch.no_grad()
490
  def run_full_api(image, seed: int = 0, num_inference_steps: int = 50, guidance_scale: float = 7.5, simplify: bool = True, target_face_num: int = DEFAULT_FACE_NUMBER, req: gr.Request = None):
491
  try:
 
509
  raise ValueError(f"Invalid image path: {image_path}")
510
 
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
  ## 🚀 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
  )
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],