Update forge-3d from local forge-bricks (with vendored common)
Browse files
app.py
CHANGED
|
@@ -16,8 +16,12 @@ from pathlib import Path
|
|
| 16 |
from datetime import datetime
|
| 17 |
import gradio as gr
|
| 18 |
import spaces
|
|
|
|
| 19 |
from PIL import Image
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
# Robust import for local workspace + HF Space deployment (common is vendored on push)
|
| 22 |
import sys
|
| 23 |
from pathlib import Path
|
|
@@ -75,7 +79,7 @@ def generate_3d(
|
|
| 75 |
else:
|
| 76 |
image_path = image
|
| 77 |
|
| 78 |
-
# 2. Health + choose backend (
|
| 79 |
target = TRIPOSG if model_choice == "triposg" else HUNYUAN
|
| 80 |
api_name = "/generate" if "Tripo" in target else "/generation_all"
|
| 81 |
|
|
@@ -87,13 +91,18 @@ def generate_3d(
|
|
| 87 |
try:
|
| 88 |
from gradio_client import Client
|
| 89 |
client = Client(target, timeout=300)
|
| 90 |
-
#
|
| 91 |
res = client.predict(image_path, api_name=api_name)
|
| 92 |
-
if
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
model_used = target.split("/")[-1]
|
| 95 |
except Exception as e:
|
| 96 |
-
|
| 97 |
|
| 98 |
if not model_path:
|
| 99 |
# Robust fallback: produce a tiny placeholder glb-like (real impl uses local TripoSR/Comfy or mesh gen)
|
|
|
|
| 16 |
from datetime import datetime
|
| 17 |
import gradio as gr
|
| 18 |
import spaces
|
| 19 |
+
import logging
|
| 20 |
from PIL import Image
|
| 21 |
|
| 22 |
+
logging.basicConfig(level=logging.INFO)
|
| 23 |
+
logger = logging.getLogger("forge-3d")
|
| 24 |
+
|
| 25 |
# Robust import for local workspace + HF Space deployment (common is vendored on push)
|
| 26 |
import sys
|
| 27 |
from pathlib import Path
|
|
|
|
| 79 |
else:
|
| 80 |
image_path = image
|
| 81 |
|
| 82 |
+
# 2. Health + choose backend (real calls to open-source 3D models via their Spaces)
|
| 83 |
target = TRIPOSG if model_choice == "triposg" else HUNYUAN
|
| 84 |
api_name = "/generate" if "Tripo" in target else "/generation_all"
|
| 85 |
|
|
|
|
| 91 |
try:
|
| 92 |
from gradio_client import Client
|
| 93 |
client = Client(target, timeout=300)
|
| 94 |
+
# Real call to the 3D generation Space (TripoSG / Hunyuan3D)
|
| 95 |
res = client.predict(image_path, api_name=api_name)
|
| 96 |
+
if res:
|
| 97 |
+
if isinstance(res, str) and os.path.exists(res) and res.endswith((".glb", ".obj", ".gltf")):
|
| 98 |
+
model_path = res
|
| 99 |
+
elif isinstance(res, dict) and "path" in res:
|
| 100 |
+
p = res["path"]
|
| 101 |
+
if os.path.exists(p):
|
| 102 |
+
model_path = p
|
| 103 |
model_used = target.split("/")[-1]
|
| 104 |
except Exception as e:
|
| 105 |
+
logger.warning(f"Cloud 3D attempt to {target} failed: {e}")
|
| 106 |
|
| 107 |
if not model_path:
|
| 108 |
# Robust fallback: produce a tiny placeholder glb-like (real impl uses local TripoSR/Comfy or mesh gen)
|