Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -484,6 +484,37 @@ def run_texture(image: Image, mesh_path: str, seed: int, req: gr.Request):
|
|
484 |
logger.error(f"Error in run_texture: {str(e)}")
|
485 |
raise
|
486 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
487 |
# Define Gradio API endpoint
|
488 |
try:
|
489 |
logger.info("Initializing Gradio API interface")
|
|
|
484 |
logger.error(f"Error in run_texture: {str(e)}")
|
485 |
raise
|
486 |
|
487 |
+
@spaces.GPU(duration=5)
|
488 |
+
@torch.no_grad()
|
489 |
+
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):
|
490 |
+
try:
|
491 |
+
logger.info("Running run_full_api")
|
492 |
+
# Handle FileData dict or URL
|
493 |
+
if isinstance(image, dict):
|
494 |
+
image_path = image.get("path") or image.get("url")
|
495 |
+
if not image_path:
|
496 |
+
logger.error("Invalid image input: no path or URL provided")
|
497 |
+
raise ValueError("Invalid image input: no path or URL provided")
|
498 |
+
if image_path.startswith("http"):
|
499 |
+
temp_image_path = os.path.join(TMP_DIR, f"input_{get_random_hex()}.png")
|
500 |
+
image_path = download_image(image_path, temp_image_path)
|
501 |
+
elif isinstance(image, str) and image.startswith("http"):
|
502 |
+
temp_image_path = os.path.join(TMP_DIR, f"input_{get_random_hex()}.png")
|
503 |
+
image_path = download_image(image, temp_image_path)
|
504 |
+
else:
|
505 |
+
image_path = image
|
506 |
+
if not isinstance(image, str) or not os.path.exists(image_path):
|
507 |
+
logger.error(f"Invalid image path: {image_path}")
|
508 |
+
raise ValueError(f"Invalid image path: {image_path}")
|
509 |
+
|
510 |
+
image_seg, mesh_path, textured_glb_path = run_full(image_path, seed, num_inference_steps, guidance_scale, simplify, target_face_num, req)
|
511 |
+
session_hash = os.path.basename(os.path.dirname(textured_glb_path))
|
512 |
+
logger.info(f"Generated textured model at /files/{session_hash}/{os.path.basename(textured_glb_path)}")
|
513 |
+
return {"file_url": f"/files/{session_hash}/{os.path.basename(textured_glb_path)}"}
|
514 |
+
except Exception as e:
|
515 |
+
logger.error(f"Error in run_full_api: {str(e)}")
|
516 |
+
raise
|
517 |
+
|
518 |
# Define Gradio API endpoint
|
519 |
try:
|
520 |
logger.info("Initializing Gradio API interface")
|