Spaces:
Paused
Paused
Add MCP server (#1)
Browse files- Add MCP server (dd522225a7ec0d969a4a9178ab8faf25f027883d)
Co-authored-by: Apolinário from multimodal AI art <[email protected]>
app.py
CHANGED
|
@@ -86,6 +86,15 @@ def first_image_from_dir(directory):
|
|
| 86 |
|
| 87 |
# Function to reset the UI and state
|
| 88 |
def reset_all():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return (
|
| 90 |
None, # crop_img
|
| 91 |
None, # normals_img
|
|
@@ -227,11 +236,11 @@ def step4_track(session_id):
|
|
| 227 |
# New: run all steps sequentially
|
| 228 |
@spaces.GPU(duration=120)
|
| 229 |
def generate_results_and_mesh(image, session_id=None):
|
| 230 |
-
|
| 231 |
"""
|
| 232 |
Process an input image through a 3D reconstruction pipeline and return the intermediate outputs and mesh file.
|
| 233 |
|
| 234 |
-
This function
|
|
|
|
| 235 |
1. **Preprocessing**: crops and masks the image for object isolation.
|
| 236 |
2. **Normals Estimation**: computes surface normal maps.
|
| 237 |
3. **UV Mapping**: generates UV coordinate maps for texturing.
|
|
@@ -240,7 +249,7 @@ def generate_results_and_mesh(image, session_id=None):
|
|
| 240 |
|
| 241 |
Args:
|
| 242 |
image (PIL.Image.Image or ndarray): Input image to reconstruct.
|
| 243 |
-
session_id (str): Unique identifier for this session
|
| 244 |
|
| 245 |
Returns:
|
| 246 |
tuple:
|
|
@@ -273,6 +282,16 @@ def generate_results_and_mesh(image, session_id=None):
|
|
| 273 |
|
| 274 |
# Cleanup on unload
|
| 275 |
def cleanup(request: gr.Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
sid = request.session_hash
|
| 277 |
if sid:
|
| 278 |
d1 = os.path.join(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], sid)
|
|
@@ -281,6 +300,19 @@ def cleanup(request: gr.Request):
|
|
| 281 |
shutil.rmtree(d2, ignore_errors=True)
|
| 282 |
|
| 283 |
def start_session(request: gr.Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
return request.session_hash
|
| 285 |
|
| 286 |
|
|
@@ -350,4 +382,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 350 |
|
| 351 |
demo.queue()
|
| 352 |
|
| 353 |
-
demo.launch(share=True)
|
|
|
|
| 86 |
|
| 87 |
# Function to reset the UI and state
|
| 88 |
def reset_all():
|
| 89 |
+
"""
|
| 90 |
+
Reset all UI components to their initial state when a new image is uploaded.
|
| 91 |
+
|
| 92 |
+
This function is triggered when the user uploads a new image to clear all previous
|
| 93 |
+
results and prepare the interface for a new reconstruction session.
|
| 94 |
+
|
| 95 |
+
Returns:
|
| 96 |
+
tuple: A tuple containing None values for all image components and reset UI states
|
| 97 |
+
"""
|
| 98 |
return (
|
| 99 |
None, # crop_img
|
| 100 |
None, # normals_img
|
|
|
|
| 236 |
# New: run all steps sequentially
|
| 237 |
@spaces.GPU(duration=120)
|
| 238 |
def generate_results_and_mesh(image, session_id=None):
|
|
|
|
| 239 |
"""
|
| 240 |
Process an input image through a 3D reconstruction pipeline and return the intermediate outputs and mesh file.
|
| 241 |
|
| 242 |
+
This function is triggered when the user clicks the "Reconstruct Face" button or selects an example.
|
| 243 |
+
It runs a multi‐step workflow to go from a raw input image to a reconstructed 3D mesh:
|
| 244 |
1. **Preprocessing**: crops and masks the image for object isolation.
|
| 245 |
2. **Normals Estimation**: computes surface normal maps.
|
| 246 |
3. **UV Mapping**: generates UV coordinate maps for texturing.
|
|
|
|
| 249 |
|
| 250 |
Args:
|
| 251 |
image (PIL.Image.Image or ndarray): Input image to reconstruct.
|
| 252 |
+
session_id (str): Unique identifier for this session's output directories.
|
| 253 |
|
| 254 |
Returns:
|
| 255 |
tuple:
|
|
|
|
| 282 |
|
| 283 |
# Cleanup on unload
|
| 284 |
def cleanup(request: gr.Request):
|
| 285 |
+
"""
|
| 286 |
+
Clean up session-specific directories and temporary files when the user session ends.
|
| 287 |
+
|
| 288 |
+
This function is triggered when the Gradio demo is unloaded (e.g., when the user
|
| 289 |
+
closes the browser tab or navigates away). It removes all temporary files and
|
| 290 |
+
directories created during the user's session to free up storage space.
|
| 291 |
+
|
| 292 |
+
Args:
|
| 293 |
+
request (gr.Request): Gradio request object containing session information
|
| 294 |
+
"""
|
| 295 |
sid = request.session_hash
|
| 296 |
if sid:
|
| 297 |
d1 = os.path.join(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], sid)
|
|
|
|
| 300 |
shutil.rmtree(d2, ignore_errors=True)
|
| 301 |
|
| 302 |
def start_session(request: gr.Request):
|
| 303 |
+
"""
|
| 304 |
+
Initialize a new user session and return the session identifier.
|
| 305 |
+
|
| 306 |
+
This function is triggered when the Gradio demo loads and creates a unique
|
| 307 |
+
session hash that will be used to organize outputs and temporary files
|
| 308 |
+
for this specific user session.
|
| 309 |
+
|
| 310 |
+
Args:
|
| 311 |
+
request (gr.Request): Gradio request object containing session information
|
| 312 |
+
|
| 313 |
+
Returns:
|
| 314 |
+
str: Unique session hash identifier
|
| 315 |
+
"""
|
| 316 |
return request.session_hash
|
| 317 |
|
| 318 |
|
|
|
|
| 382 |
|
| 383 |
demo.queue()
|
| 384 |
|
| 385 |
+
demo.launch(share=True, mcp_server=True)
|