Spaces:
Running
on
Zero
Running
on
Zero
feat: Enable MCP
Browse filesHello! This is an automated PR adding MCP compatibility to your AI App 🤖.
This PR introduces two improvements:
1. Adds docstrings to the functions in the app file that are directly connected to the Gradio UI, for the downstream LLM to use.
2. Enables the Model-Compute-Platform by adding `mcp_server=True` to the `.launch()` call.
No other logic has been changed. Please review and merge if it looks good!Learn more about MCP compatibility in Spaces here: https://huggingface.co/changelog/add-compatible-spaces-to-your-mcp-tools
app.py
CHANGED
@@ -214,7 +214,30 @@ def run_triposg(image_path: str,
|
|
214 |
progress=gr.Progress(track_tqdm=True),):
|
215 |
|
216 |
"""
|
217 |
-
Generate 3D part meshes from an input image.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
"""
|
219 |
|
220 |
max_num_expanded_coords = 1e9
|
@@ -282,6 +305,18 @@ def run_triposg(image_path: str,
|
|
282 |
return merged_path, split_preview_path, export_dir, zip_path
|
283 |
|
284 |
def cleanup(request: gr.Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
|
286 |
sid = request.session_hash
|
287 |
if sid:
|
@@ -289,6 +324,18 @@ def cleanup(request: gr.Request):
|
|
289 |
shutil.rmtree(d1, ignore_errors=True)
|
290 |
|
291 |
def start_session(request: gr.Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
293 |
return request.session_hash
|
294 |
|
@@ -322,7 +369,7 @@ def build_demo():
|
|
322 |
with gr.Column(scale=1):
|
323 |
gr.Markdown(
|
324 |
"""
|
325 |
-
• HF Space by :
|
326 |
)
|
327 |
input_image = gr.Image(type="filepath", label="Input Image", height=256)
|
328 |
num_parts = gr.Slider(1, MAX_NUM_PARTS, value=4, step=1, label="Number of Parts")
|
@@ -384,4 +431,4 @@ if __name__ == "__main__":
|
|
384 |
demo = build_demo()
|
385 |
demo.unload(cleanup)
|
386 |
demo.queue()
|
387 |
-
demo.launch()
|
|
|
214 |
progress=gr.Progress(track_tqdm=True),):
|
215 |
|
216 |
"""
|
217 |
+
Generate 3D part meshes from an input image using the PartCrafter pipeline.
|
218 |
+
|
219 |
+
This function takes an input image and generates multiple 3D mesh parts that compose
|
220 |
+
the object in the image. It uses a diffusion-based model to create structured 3D
|
221 |
+
representations with separate parts that can be individually manipulated.
|
222 |
+
|
223 |
+
Args:
|
224 |
+
image_path: Path to the input image file
|
225 |
+
num_parts: Number of parts to generate for the 3D object (1-16)
|
226 |
+
seed: Random seed for reproducible generation
|
227 |
+
num_tokens: Number of tokens to use in the generation process (256-2048)
|
228 |
+
num_inference_steps: Number of denoising steps for the diffusion process
|
229 |
+
guidance_scale: Guidance scale for classifier-free guidance
|
230 |
+
use_flash_decoder: Whether to use flash attention decoder for faster inference
|
231 |
+
rmbg: Whether to remove background from input image using RMBG model
|
232 |
+
session_id: Unique session identifier for tracking generation process
|
233 |
+
progress: Gradio progress tracker for UI updates
|
234 |
+
|
235 |
+
Returns:
|
236 |
+
tuple: Contains:
|
237 |
+
- merged_path: Path to the merged 3D object GLB file
|
238 |
+
- split_preview_path: Path to the exploded view GLB file
|
239 |
+
- export_dir: Directory containing all exported files
|
240 |
+
- zip_path: Path to ZIP file containing all individual parts
|
241 |
"""
|
242 |
|
243 |
max_num_expanded_coords = 1e9
|
|
|
305 |
return merged_path, split_preview_path, export_dir, zip_path
|
306 |
|
307 |
def cleanup(request: gr.Request):
|
308 |
+
"""
|
309 |
+
Clean up temporary files and directories for a user session.
|
310 |
+
|
311 |
+
This function is called when the Gradio interface is unloaded to remove
|
312 |
+
any temporary files created during the session to prevent disk space issues.
|
313 |
+
|
314 |
+
Args:
|
315 |
+
request: Gradio request object containing session information
|
316 |
+
|
317 |
+
Returns:
|
318 |
+
None
|
319 |
+
"""
|
320 |
|
321 |
sid = request.session_hash
|
322 |
if sid:
|
|
|
324 |
shutil.rmtree(d1, ignore_errors=True)
|
325 |
|
326 |
def start_session(request: gr.Request):
|
327 |
+
"""
|
328 |
+
Initialize a new user session and return the session hash.
|
329 |
+
|
330 |
+
This function is called when the Gradio interface loads to create a unique
|
331 |
+
session identifier for tracking the user's generation process and temporary files.
|
332 |
+
|
333 |
+
Args:
|
334 |
+
request: Gradio request object containing session information
|
335 |
+
|
336 |
+
Returns:
|
337 |
+
str: Session hash identifier for the current user session
|
338 |
+
"""
|
339 |
|
340 |
return request.session_hash
|
341 |
|
|
|
369 |
with gr.Column(scale=1):
|
370 |
gr.Markdown(
|
371 |
"""
|
372 |
+
• HF Space by : [@alexandernasa](https://twitter.com/alexandernasa/) """
|
373 |
)
|
374 |
input_image = gr.Image(type="filepath", label="Input Image", height=256)
|
375 |
num_parts = gr.Slider(1, MAX_NUM_PARTS, value=4, step=1, label="Number of Parts")
|
|
|
431 |
demo = build_demo()
|
432 |
demo.unload(cleanup)
|
433 |
demo.queue()
|
434 |
+
demo.launch(mcp_server=True)
|