Xernive commited on
Commit
aa27972
·
1 Parent(s): 0b304c9

fix: correct Hunyuan3D API call (remove invalid output_type parameter)

Browse files

- Removed invalid output_type='mesh' parameter
- Updated response parsing to handle 4-element tuple correctly
- Added robust error handling for each tuple element
- Added detailed logging for debugging
- Verified against Hunyuan3D-2.1 API documentation

core/__pycache__/__init__.cpython-313.pyc ADDED
Binary file (528 Bytes). View file
 
core/__pycache__/config.cpython-313.pyc ADDED
Binary file (2.05 kB). View file
 
core/__pycache__/pipeline.cpython-313.pyc ADDED
Binary file (6.86 kB). View file
 
core/__pycache__/types.cpython-313.pyc ADDED
Binary file (1.34 kB). View file
 
generators/hunyuan.py CHANGED
@@ -58,7 +58,7 @@ class HunyuanGenerator:
58
  )
59
  print(f"[Hunyuan3D] Connected successfully")
60
 
61
- # Call API with correct output_type
62
  print(f"[Hunyuan3D] Calling API with parameters...")
63
  result = self._call_api(
64
  client,
@@ -74,44 +74,82 @@ class HunyuanGenerator:
74
  check_box_rembg=True,
75
  num_chunks=preset.num_chunks,
76
  randomize_seed=True,
77
- output_type="mesh", # CRITICAL: Specify mesh output to get GLB file
78
  api_name="/shape_generation"
79
  )
80
  print(f"[Hunyuan3D] API call completed")
81
 
82
- # Extract GLB path with robust error handling
 
83
  print(f"[Hunyuan3D] Raw result type: {type(result)}")
84
- print(f"[Hunyuan3D] Raw result: {result}")
85
 
86
- # Handle different result formats
87
- if isinstance(result, tuple):
88
- if len(result) == 0:
89
- raise ValueError("Empty result tuple from Hunyuan3D API")
90
- file_data = result[0]
91
- else:
92
- file_data = result
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  # Extract path from file_data
 
 
 
 
 
 
 
 
 
 
 
 
95
  if isinstance(file_data, dict):
96
- if 'value' in file_data:
97
- glb_path = file_data['value']
98
- elif 'path' in file_data:
99
  glb_path = file_data['path']
 
 
100
  elif 'name' in file_data:
101
  glb_path = file_data['name']
102
  else:
103
- # Try to convert entire dict to string
104
- glb_path = str(file_data)
105
- print(f"[Hunyuan3D] WARNING: Unexpected dict format, using str(): {glb_path}")
 
106
  elif isinstance(file_data, str):
107
  glb_path = file_data
108
  else:
109
- glb_path = str(file_data)
110
- print(f"[Hunyuan3D] WARNING: Unexpected type {type(file_data)}, using str(): {glb_path}")
 
 
 
 
111
 
112
  # Validate path exists
113
- if not glb_path or not Path(glb_path).exists():
114
- raise ValueError(f"GLB file not found at path: {glb_path}")
 
 
 
 
 
 
 
 
 
115
 
116
  print(f"[Hunyuan3D] Model generated: {glb_path}")
117
 
 
58
  )
59
  print(f"[Hunyuan3D] Connected successfully")
60
 
61
+ # Call API (returns tuple: file, output, mesh_stats, seed)
62
  print(f"[Hunyuan3D] Calling API with parameters...")
63
  result = self._call_api(
64
  client,
 
74
  check_box_rembg=True,
75
  num_chunks=preset.num_chunks,
76
  randomize_seed=True,
 
77
  api_name="/shape_generation"
78
  )
79
  print(f"[Hunyuan3D] API call completed")
80
 
81
+ # Extract GLB path from tuple response
82
+ # API returns: (file, output, mesh_stats, seed)
83
  print(f"[Hunyuan3D] Raw result type: {type(result)}")
84
+ print(f"[Hunyuan3D] Raw result length: {len(result) if isinstance(result, (tuple, list)) else 'N/A'}")
85
 
86
+ if not isinstance(result, tuple):
87
+ raise ValueError(
88
+ f"Unexpected result type from Hunyuan3D API: {type(result)}. "
89
+ f"Expected tuple of (file, output, mesh_stats, seed)."
90
+ )
91
+
92
+ if len(result) != 4:
93
+ raise ValueError(
94
+ f"Unexpected result length from Hunyuan3D API: {len(result)}. "
95
+ f"Expected 4 elements (file, output, mesh_stats, seed), got {len(result)}."
96
+ )
97
+
98
+ # Extract GLB file path (first element)
99
+ file_data, html_output, mesh_stats, used_seed = result
100
+
101
+ print(f"[Hunyuan3D] file_data type: {type(file_data)}")
102
+ print(f"[Hunyuan3D] mesh_stats: {mesh_stats}")
103
+ print(f"[Hunyuan3D] used_seed: {used_seed}")
104
 
105
  # Extract path from file_data
106
+ if file_data is None:
107
+ raise ValueError(
108
+ "Hunyuan3D API returned None for file. "
109
+ "This usually means the generation failed on the server side. "
110
+ "Possible causes:\n"
111
+ " - Invalid image input\n"
112
+ " - API timeout\n"
113
+ " - Server overload\n"
114
+ "Try again with a different image or quality setting."
115
+ )
116
+
117
+ # Handle different file_data formats
118
  if isinstance(file_data, dict):
119
+ print(f"[Hunyuan3D] file_data is dict with keys: {file_data.keys()}")
120
+ if 'path' in file_data:
 
121
  glb_path = file_data['path']
122
+ elif 'value' in file_data:
123
+ glb_path = file_data['value']
124
  elif 'name' in file_data:
125
  glb_path = file_data['name']
126
  else:
127
+ raise ValueError(
128
+ f"Unexpected dict format from Hunyuan3D API. "
129
+ f"Keys: {list(file_data.keys())}"
130
+ )
131
  elif isinstance(file_data, str):
132
  glb_path = file_data
133
  else:
134
+ raise ValueError(
135
+ f"Unexpected file_data type: {type(file_data)}. "
136
+ f"Expected dict or str."
137
+ )
138
+
139
+ print(f"[Hunyuan3D] Extracted GLB path: {glb_path}")
140
 
141
  # Validate path exists
142
+ if not glb_path or glb_path == "None":
143
+ raise ValueError(
144
+ "Hunyuan3D API returned invalid path. "
145
+ "The generation may have failed on the server side."
146
+ )
147
+
148
+ if not Path(glb_path).exists():
149
+ raise ValueError(
150
+ f"GLB file not found at path: {glb_path}. "
151
+ f"The file may not have been generated or saved correctly."
152
+ )
153
 
154
  print(f"[Hunyuan3D] Model generated: {glb_path}")
155