Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit b14fe3b

Browse files
authored
Merge pull request #9 from greenmagenta/client-handling
Update Client handling
2 parents 0a0a42b + eccb5eb commit b14fe3b

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

autosculptor/operators.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
from bpy.types import Operator
77
from .utils import ensure_gradio_installed, install_gradio
88

9+
# Clients API config
10+
client_config = {
11+
"shap_e": "hysts/Shap-E",
12+
"sdxl": "hysts/SDXL",
13+
"one_2_3_45": "https://one-2-3-45-one-2-3-45.hf.space/",
14+
"dreamgaussian": "https://jiawei011-dreamgaussian.hf.space/",
15+
"instantmesh": "TencentARC/InstantMesh",
16+
"triposr": "stabilityai/TripoSR"
17+
}
18+
919
class InstallDependenciesOperator(Operator):
1020
bl_idname = "wm.install_dependencies"
1121
bl_label = "Install Dependencies"
@@ -67,6 +77,9 @@ def run_pipeline(self, autosculptor_props):
6777
image_height = autosculptor_props.image_height
6878
api_key = autosculptor_props.api_key
6979

80+
if api_key == "":
81+
api_key = None
82+
7083
for _ in range(batch_count):
7184
# Get seed for generation
7285
seed = autosculptor_props.seed
@@ -140,7 +153,8 @@ def generate_model(self, prompt, seed, guidance_scale, num_inference_steps, mode
140153

141154
def generate_shape_e_model(self, api_key, prompt, seed, guidance_scale, num_inference_steps):
142155
from gradio_client import Client
143-
client = Client("hysts/Shap-E", hf_token=api_key)
156+
157+
client = Client(client_config["shap_e"], hf_token=api_key) if api_key else Client(client_config["shap_e"])
144158
result = client.predict(
145159
prompt=prompt,
146160
seed=seed,
@@ -152,7 +166,7 @@ def generate_shape_e_model(self, api_key, prompt, seed, guidance_scale, num_infe
152166

153167
def generate_sdxl_shape_e_model(self, api_key, prompt, seed, guidance_scale, num_inference_steps, image_width, image_height):
154168
from gradio_client import Client, handle_file
155-
client1 = Client("hysts/SDXL", hf_token=api_key)
169+
client1 = Client(client_config["sdxl"], hf_token=api_key) if api_key else Client(client_config["sdxl"])
156170
image = client1.predict(
157171
prompt=prompt,
158172
negative_prompt="",
@@ -167,13 +181,13 @@ def generate_sdxl_shape_e_model(self, api_key, prompt, seed, guidance_scale, num
167181
)
168182
image_path = image
169183

170-
client2 = Client("https://one-2-3-45-one-2-3-45.hf.space/", hf_token=api_key)
184+
client2 = Client(client_config["one_2_3_45"], hf_token=api_key) if api_key else Client(client_config["one_2_3_45"])
171185
segmented_img_filepath = client2.predict(
172186
image_path,
173187
api_name="/preprocess"
174-
)
188+
)
175189

176-
client3 = Client("hysts/Shap-E", hf_token=api_key)
190+
client3 = Client(client_config["shap_e"], hf_token=api_key) if api_key else Client(client_config["shap_e"])
177191
result = client3.predict(
178192
image=handle_file(segmented_img_filepath),
179193
seed=seed,
@@ -185,7 +199,7 @@ def generate_sdxl_shape_e_model(self, api_key, prompt, seed, guidance_scale, num
185199

186200
def generate_sdxl_dreamgaussian_model(self, api_key, prompt, seed, guidance_scale, num_inference_steps, image_width, image_height):
187201
from gradio_client import Client, handle_file
188-
client1 = Client("hysts/SDXL", hf_token=api_key)
202+
client1 = Client(client_config["sdxl"], hf_token=api_key) if api_key else Client(client_config["sdxl"])
189203
image = client1.predict(
190204
prompt=prompt,
191205
negative_prompt="",
@@ -200,17 +214,17 @@ def generate_sdxl_dreamgaussian_model(self, api_key, prompt, seed, guidance_scal
200214
)
201215
image_path = image
202216

203-
client2 = Client("https://one-2-3-45-one-2-3-45.hf.space/", hf_token=api_key)
217+
client2 = Client(client_config["one_2_3_45"], hf_token=api_key) if api_key else Client(client_config["one_2_3_45"])
204218
elevation_angle_deg = client2.predict(
205219
image_path,
206220
True,
207221
api_name="/estimate_elevation"
208-
)
222+
)
209223

210224
if elevation_angle_deg < -90 or elevation_angle_deg > 90:
211225
elevation_angle_deg = 0
212226

213-
client3 = Client("https://jiawei011-dreamgaussian.hf.space/", hf_token=api_key)
227+
client3 = Client(client_config["dreamgaussian"], hf_token=api_key) if api_key else Client(client_config["dreamgaussian"])
214228
result = client3.predict(
215229
image_path,
216230
True,
@@ -221,7 +235,7 @@ def generate_sdxl_dreamgaussian_model(self, api_key, prompt, seed, guidance_scal
221235

222236
def generate_sdxl_instantmesh_model(self, api_key, prompt, seed, guidance_scale, num_inference_steps, image_width, image_height):
223237
from gradio_client import Client, handle_file
224-
client1 = Client("hysts/SDXL", hf_token=api_key)
238+
client1 = Client(client_config["sdxl"], hf_token=api_key) if api_key else Client(client_config["sdxl"])
225239
image = client1.predict(
226240
prompt=prompt,
227241
negative_prompt="",
@@ -236,7 +250,7 @@ def generate_sdxl_instantmesh_model(self, api_key, prompt, seed, guidance_scale,
236250
)
237251
image_path = image
238252

239-
client2 = Client("TencentARC/InstantMesh", hf_token=api_key)
253+
client2 = Client(client_config["instantmesh"], hf_token=api_key) if api_key else Client(client_config["instantmesh"])
240254
processed_image = client2.predict(
241255
input_image=handle_file(image_path),
242256
do_remove_background=True,
@@ -257,7 +271,7 @@ def generate_sdxl_instantmesh_model(self, api_key, prompt, seed, guidance_scale,
257271

258272
def generate_sdxl_triposr_model(self, api_key, prompt, seed, guidance_scale, num_inference_steps, image_width, image_height):
259273
from gradio_client import Client, handle_file
260-
client1 = Client("hysts/SDXL", hf_token=api_key)
274+
client1 = Client(client_config["sdxl"], hf_token=api_key) if api_key else Client(client_config["sdxl"])
261275
image = client1.predict(
262276
prompt=prompt,
263277
negative_prompt="",
@@ -272,7 +286,7 @@ def generate_sdxl_triposr_model(self, api_key, prompt, seed, guidance_scale, num
272286
)
273287
image_path = image
274288

275-
client2 = Client("stabilityai/TripoSR", hf_token=api_key)
289+
client2 = Client(client_config["triposr"], hf_token=api_key) if api_key else Client(client_config["triposr"])
276290
processed_image = client2.predict(
277291
handle_file(image_path),
278292
True,

0 commit comments

Comments
 (0)