Desarrollo33 commited on
Commit
f2dac59
·
1 Parent(s): 2d0c334

fix: try valid caption for generation_all to avoid NameError

Browse files
Files changed (4) hide show
  1. api_endpoints.txt +0 -0
  2. api_info.txt +118 -0
  3. app.py +14 -16
  4. inspect_api.py +11 -0
api_endpoints.txt ADDED
Binary file (11.4 kB). View file
 
api_info.txt ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Loaded as API: https://tencent-hunyuan3d-2.hf.space
2
+ Client.predict() Usage Info
3
+ ---------------------------
4
+ Named API endpoints: 12
5
+
6
+ - predict(api_name="/lambda") ->
7
+ Parameters:
8
+ - None
9
+ Returns:
10
+ - None
11
+
12
+ - predict(api_name="/lambda_1") ->
13
+ Parameters:
14
+ - None
15
+ Returns:
16
+ - None
17
+
18
+ - predict(caption, image, mv_image_front, mv_image_back, mv_image_left, mv_image_right, steps, guidance_scale, seed, octree_resolution, check_box_rembg, num_chunks, randomize_seed, api_name="/shape_generation") -> (file, output, mesh_stats, seed)
19
+ Parameters:
20
+ - [Textbox] caption: str | None (not required, defaults to: None)
21
+ - [Image] image: filepath | None (not required, defaults to: None)
22
+ - [Image] mv_image_front: filepath | None (not required, defaults to: None)
23
+ - [Image] mv_image_back: filepath | None (not required, defaults to: None)
24
+ - [Image] mv_image_left: filepath | None (not required, defaults to: None)
25
+ - [Image] mv_image_right: filepath | None (not required, defaults to: None)
26
+ - [Slider] steps: float (not required, defaults to: 30) (numeric value between 1 and 100)
27
+ - [Number] guidance_scale: float (not required, defaults to: 5.0)
28
+ - [Slider] seed: float (not required, defaults to: 1234) (numeric value between 0 and 10000000.0)
29
+ - [Slider] octree_resolution: float (not required, defaults to: 256) (numeric value between 16 and 512)
30
+ - [Checkbox] check_box_rembg: bool (not required, defaults to: True)
31
+ - [Slider] num_chunks: float (not required, defaults to: 8000) (numeric value between 1000 and 5000000)
32
+ - [Checkbox] randomize_seed: bool (not required, defaults to: True)
33
+ Returns:
34
+ - [File] file: filepath
35
+ - [Html] output: str
36
+ - [Json] mesh_stats: Dict[Any, Any] (any valid json)
37
+ - [Slider] seed: float (numeric value between 0 and 10000000.0)
38
+
39
+ - predict(api_name="/lambda_2") -> (include_texture, simplify_mesh, download)
40
+ Parameters:
41
+ - None
42
+ Returns:
43
+ - [Checkbox] include_texture: bool
44
+ - [Checkbox] simplify_mesh: bool
45
+ - [Downloadbutton] download: filepath
46
+
47
+ - predict(api_name="/lambda_3") ->
48
+ Parameters:
49
+ - None
50
+ Returns:
51
+ - None
52
+
53
+ - predict(caption, image, mv_image_front, mv_image_back, mv_image_left, mv_image_right, steps, guidance_scale, seed, octree_resolution, check_box_rembg, num_chunks, randomize_seed, api_name="/generation_all") -> (file, file, output, mesh_stats, seed)
54
+ Parameters:
55
+ - [Textbox] caption: str | None (not required, defaults to: None)
56
+ - [Image] image: filepath | None (not required, defaults to: None)
57
+ - [Image] mv_image_front: filepath | None (not required, defaults to: None)
58
+ - [Image] mv_image_back: filepath | None (not required, defaults to: None)
59
+ - [Image] mv_image_left: filepath | None (not required, defaults to: None)
60
+ - [Image] mv_image_right: filepath | None (not required, defaults to: None)
61
+ - [Slider] steps: float (not required, defaults to: 30) (numeric value between 1 and 100)
62
+ - [Number] guidance_scale: float (not required, defaults to: 5.0)
63
+ - [Slider] seed: float (not required, defaults to: 1234) (numeric value between 0 and 10000000.0)
64
+ - [Slider] octree_resolution: float (not required, defaults to: 256) (numeric value between 16 and 512)
65
+ - [Checkbox] check_box_rembg: bool (not required, defaults to: True)
66
+ - [Slider] num_chunks: float (not required, defaults to: 8000) (numeric value between 1000 and 5000000)
67
+ - [Checkbox] randomize_seed: bool (not required, defaults to: True)
68
+ Returns:
69
+ - [File] file: filepath
70
+ - [File] file: filepath
71
+ - [Html] output: str
72
+ - [Json] mesh_stats: Dict[Any, Any] (any valid json)
73
+ - [Slider] seed: float (numeric value between 0 and 10000000.0)
74
+
75
+ - predict(api_name="/lambda_4") -> (include_texture, simplify_mesh, download)
76
+ Parameters:
77
+ - None
78
+ Returns:
79
+ - [Checkbox] include_texture: bool
80
+ - [Checkbox] simplify_mesh: bool
81
+ - [Downloadbutton] download: filepath
82
+
83
+ - predict(api_name="/lambda_5") ->
84
+ Parameters:
85
+ - None
86
+ Returns:
87
+ - None
88
+
89
+ - predict(value, api_name="/on_gen_mode_change") -> inference_steps
90
+ Parameters:
91
+ - [Radio] value: Literal['Turbo', 'Fast', 'Standard'] (not required, defaults to: Turbo)
92
+ Returns:
93
+ - [Slider] inference_steps: float (numeric value between 1 and 100)
94
+
95
+ - predict(value, api_name="/on_decode_mode_change") -> octree_resolution
96
+ Parameters:
97
+ - [Radio] value: Literal['Low', 'Standard', 'High'] (not required, defaults to: Standard)
98
+ Returns:
99
+ - [Slider] octree_resolution: float (numeric value between 16 and 512)
100
+
101
+ - predict(api_name="/lambda_6") ->
102
+ Parameters:
103
+ - None
104
+ Returns:
105
+ - None
106
+
107
+ - predict(file_out, file_out2, file_type, reduce_face, export_texture, target_face_num, api_name="/on_export_click") -> (output, download)
108
+ Parameters:
109
+ - [File] file_out: filepath (required)
110
+ - [File] file_out2: filepath (required)
111
+ - [Dropdown] file_type: Literal['glb', 'obj', 'ply', 'stl'] (not required, defaults to: glb)
112
+ - [Checkbox] reduce_face: bool (not required, defaults to: False)
113
+ - [Checkbox] export_texture: bool (not required, defaults to: False)
114
+ - [Slider] target_face_num: float (not required, defaults to: 10000) (numeric value between 100 and 1000000)
115
+ Returns:
116
+ - [Html] output: str
117
+ - [Downloadbutton] download: filepath
118
+
app.py CHANGED
@@ -92,10 +92,10 @@ def generate_3d_model(image: Image.Image, with_texture: bool = True) -> tuple[st
92
 
93
  if with_texture:
94
  try:
95
- debug_logs.append("Attempting /generation_all endpoint...")
96
- # Intentar /generation_all con parámetros exactos
97
  result = client.predict(
98
- caption="",
99
  image=handle_file(temp_path),
100
  mv_image_front=None,
101
  mv_image_back=None,
@@ -113,21 +113,20 @@ def generate_3d_model(image: Image.Image, with_texture: bool = True) -> tuple[st
113
 
114
  os.unlink(temp_path)
115
 
 
116
  debug_logs.append(f"Result type: {type(result)}")
 
117
  if isinstance(result, tuple):
118
- debug_logs.append(f"Result length: {len(result)}")
119
- for i, item in enumerate(result):
120
- debug_logs.append(f"Item {i}: {item}")
121
-
122
- # El segundo archivo suele ser el modelo con texturas (OBJ/GLB)
123
  if len(result) >= 2 and result[1]:
124
- debug_logs.append("Detailed model (texture) found in index 1.")
125
- final_model_path = result[1]
126
  else:
127
- debug_logs.append("Detailed model NOT found, using index 0.")
128
- final_model_path = result[0]
129
  else:
130
- debug_logs.append(f"Single result: {result}")
131
  final_model_path = result
132
 
133
  return final_model_path, final_model_path, "\n".join(debug_logs)
@@ -142,7 +141,7 @@ def generate_3d_model(image: Image.Image, with_texture: bool = True) -> tuple[st
142
  # Fallback a /shape_generation (solo geometría)
143
  debug_logs.append("Falling back to /shape_generation...")
144
  result = client.predict(
145
- caption=None,
146
  image=handle_file(temp_path),
147
  mv_image_front=None,
148
  mv_image_back=None,
@@ -160,13 +159,12 @@ def generate_3d_model(image: Image.Image, with_texture: bool = True) -> tuple[st
160
 
161
  os.unlink(temp_path)
162
 
163
- debug_logs.append(f"Fallback result type: {type(result)}")
164
  if isinstance(result, tuple):
165
- debug_logs.append(f"Fallback result length: {len(result)}")
166
  final_model_path = result[0]
167
  else:
168
  final_model_path = result
169
 
 
170
  return final_model_path, final_model_path, "\n".join(debug_logs)
171
 
172
  except Exception as e:
 
92
 
93
  if with_texture:
94
  try:
95
+ debug_logs.append("Attempting /generation_all with 'A 3D model of a vehicle' caption...")
96
+ # Intentar /generation_all con caption explícito
97
  result = client.predict(
98
+ caption="A 3D model of a vehicle", # Intentando evitar NameError por None/Empty
99
  image=handle_file(temp_path),
100
  mv_image_front=None,
101
  mv_image_back=None,
 
113
 
114
  os.unlink(temp_path)
115
 
116
+ debug_logs.append("API call successful!")
117
  debug_logs.append(f"Result type: {type(result)}")
118
+
119
  if isinstance(result, tuple):
120
+ debug_logs.append(f"Result items: {len(result)}")
121
+ # El return es (file, file, output, mesh_stats, seed)
122
+ # result[1] debería ser el textured file
 
 
123
  if len(result) >= 2 and result[1]:
124
+ debug_logs.append(f"Textured model found: {result[1]}")
125
+ final_model_path = result[1]
126
  else:
127
+ debug_logs.append(f"No textured model in pos 1. Pos 0: {result[0]}")
128
+ final_model_path = result[0]
129
  else:
 
130
  final_model_path = result
131
 
132
  return final_model_path, final_model_path, "\n".join(debug_logs)
 
141
  # Fallback a /shape_generation (solo geometría)
142
  debug_logs.append("Falling back to /shape_generation...")
143
  result = client.predict(
144
+ caption="A 3D model of a vehicle",
145
  image=handle_file(temp_path),
146
  mv_image_front=None,
147
  mv_image_back=None,
 
159
 
160
  os.unlink(temp_path)
161
 
 
162
  if isinstance(result, tuple):
 
163
  final_model_path = result[0]
164
  else:
165
  final_model_path = result
166
 
167
+ debug_logs.append(f"Fallback success: {final_model_path}")
168
  return final_model_path, final_model_path, "\n".join(debug_logs)
169
 
170
  except Exception as e:
inspect_api.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gradio_client import Client
2
+ import sys
3
+
4
+ # Redirect stdout to file
5
+ with open('api_info.txt', 'w', encoding='utf-8') as f:
6
+ sys.stdout = f
7
+ client = Client("tencent/Hunyuan3D-2")
8
+ client.view_api()
9
+ sys.stdout = sys.__stdout__
10
+
11
+ print("API info written to api_info.txt")