Spaces:
Running
on
Zero
Running
on
Zero
Add MCP compatibility
#2
by
multimodalart
HF Staff
- opened
app.py
CHANGED
|
@@ -62,6 +62,16 @@ model.load_state_dict(ckpt_dict, strict=True)
|
|
| 62 |
|
| 63 |
# get random seed
|
| 64 |
def get_random_seed(randomize_seed, seed):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
if randomize_seed:
|
| 66 |
seed = np.random.randint(0, MAX_SEED)
|
| 67 |
return seed
|
|
@@ -69,6 +79,15 @@ def get_random_seed(randomize_seed, seed):
|
|
| 69 |
# process image
|
| 70 |
@spaces.GPU(duration=10)
|
| 71 |
def process_image(image_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
|
| 73 |
if image.shape[-1] == 4:
|
| 74 |
image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
|
|
@@ -84,6 +103,21 @@ def process_image(image_path):
|
|
| 84 |
# process generation
|
| 85 |
@spaces.GPU(duration=90)
|
| 86 |
def process_3d(input_image, num_steps=50, cfg_scale=7, grid_res=384, seed=42, simplify_mesh=False, target_num_faces=100000):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# seed
|
| 89 |
kiui.seed_everything(seed)
|
|
@@ -216,4 +250,4 @@ with block:
|
|
| 216 |
process_3d, inputs=[seg_image, num_steps, cfg_scale, input_grid_res, seed, simplify_mesh, target_num_faces], outputs=[output_model]
|
| 217 |
)
|
| 218 |
|
| 219 |
-
block.launch(ssr_mode=False)
|
|
|
|
| 62 |
|
| 63 |
# get random seed
|
| 64 |
def get_random_seed(randomize_seed, seed):
|
| 65 |
+
"""
|
| 66 |
+
Generate or return a random seed based on user preferences.
|
| 67 |
+
|
| 68 |
+
Args:
|
| 69 |
+
randomize_seed (bool): Whether to generate a new random seed
|
| 70 |
+
seed (int): The current seed value
|
| 71 |
+
|
| 72 |
+
Returns:
|
| 73 |
+
int: New random seed if randomize_seed is True, otherwise returns the input seed
|
| 74 |
+
"""
|
| 75 |
if randomize_seed:
|
| 76 |
seed = np.random.randint(0, MAX_SEED)
|
| 77 |
return seed
|
|
|
|
| 79 |
# process image
|
| 80 |
@spaces.GPU(duration=10)
|
| 81 |
def process_image(image_path):
|
| 82 |
+
"""
|
| 83 |
+
Process input image by removing background, recentering, and resizing.
|
| 84 |
+
|
| 85 |
+
Args:
|
| 86 |
+
image_path (str): Path to the input image file
|
| 87 |
+
|
| 88 |
+
Returns:
|
| 89 |
+
numpy.ndarray: Processed RGBA image array of size (518, 518, 4)
|
| 90 |
+
"""
|
| 91 |
image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
|
| 92 |
if image.shape[-1] == 4:
|
| 93 |
image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
|
|
|
|
| 103 |
# process generation
|
| 104 |
@spaces.GPU(duration=90)
|
| 105 |
def process_3d(input_image, num_steps=50, cfg_scale=7, grid_res=384, seed=42, simplify_mesh=False, target_num_faces=100000):
|
| 106 |
+
"""
|
| 107 |
+
Generate 3D mesh from input image using PartPacker model.
|
| 108 |
+
|
| 109 |
+
Args:
|
| 110 |
+
input_image (numpy.ndarray): Processed RGBA input image
|
| 111 |
+
num_steps (int): Number of inference steps for generation
|
| 112 |
+
cfg_scale (float): Classifier-free guidance scale
|
| 113 |
+
grid_res (int): Grid resolution for mesh extraction
|
| 114 |
+
seed (int): Random seed for reproducibility
|
| 115 |
+
simplify_mesh (bool): Whether to simplify the output mesh
|
| 116 |
+
target_num_faces (int): Target number of faces if simplifying mesh
|
| 117 |
+
|
| 118 |
+
Returns:
|
| 119 |
+
str: Path to the generated GLB file containing the 3D mesh
|
| 120 |
+
"""
|
| 121 |
|
| 122 |
# seed
|
| 123 |
kiui.seed_everything(seed)
|
|
|
|
| 250 |
process_3d, inputs=[seg_image, num_steps, cfg_scale, input_grid_res, seed, simplify_mesh, target_num_faces], outputs=[output_model]
|
| 251 |
)
|
| 252 |
|
| 253 |
+
block.launch(ssr_mode=False, mcp_server=True)
|