jkorstad commited on
Commit
4bd82b7
·
verified ·
1 Parent(s): bdc12c1

Update forge-3d from local forge-bricks (with vendored common)

Browse files
Files changed (1) hide show
  1. app.py +14 -5
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 (scaffold: always attempt client to known; real will add local adapter)
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
- # Many of these Spaces take (image, ...) simplified call for scaffold
91
  res = client.predict(image_path, api_name=api_name)
92
- if isinstance(res, str) and res.endswith((".glb", ".obj", ".gltf")) and os.path.exists(res):
93
- model_path = res
 
 
 
 
 
94
  model_used = target.split("/")[-1]
95
  except Exception as e:
96
- print("Cloud 3D attempt failed (health/fallback):", e)
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)