qchapp commited on
Commit
5e64694
·
verified ·
1 Parent(s): 9aa89dd

Sync from GitHub Actions (skip png)

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -353,16 +353,25 @@ with gr.Blocks() as demo:
353
  )
354
 
355
  # ---------------------------------------------------------------------------
356
- # MCP / API-only endpoints — thin wrappers that return the output file path
357
- # as a plain string so Gradio/MCP can serve it correctly.
358
  # ---------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
359
  def _mcp_align_stack_to_reference(
360
  stack_file: str,
361
  reference_index: int = 0,
362
  mode: str = "RIGID_BODY",
363
  external_reference_file: Optional[str] = None,
364
  external_reference_index: int = 0,
365
- ) -> str:
366
  """Align every frame in a TIFF stack to a chosen reference frame.
367
 
368
  Each frame in stack_file is registered to the selected reference frame
@@ -388,13 +397,13 @@ with gr.Blocks() as demo:
388
  stack_file, reference_index, mode,
389
  external_reference_file, external_reference_index,
390
  )
391
- return out
392
 
393
  def _mcp_align_stack_to_stack(
394
  reference_stack_file: str,
395
  moving_stack_file: str,
396
  mode: str = "RIGID_BODY",
397
- ) -> str:
398
  """Align every frame in a moving TIFF stack to the first frame of a reference stack.
399
 
400
  Args:
@@ -409,14 +418,14 @@ with gr.Blocks() as demo:
409
  The aligned output TIFF file.
410
  """
411
  out = align_stack_to_stack(reference_stack_file, moving_stack_file, mode)
412
- return out
413
 
414
  def _mcp_align_frame_to_frame(
415
  stack_file: str,
416
  reference_index: int,
417
  moving_index: int,
418
  mode: str = "RIGID_BODY",
419
- ) -> str:
420
  """Align a single moving frame to a reference frame within the same TIFF stack.
421
 
422
  Args:
@@ -431,7 +440,7 @@ with gr.Blocks() as demo:
431
  The aligned single-frame output TIFF file.
432
  """
433
  out = align_frame_to_frame(stack_file, reference_index, moving_index, mode)
434
- return out
435
 
436
  gr.api(fn=_mcp_align_stack_to_reference, api_name="align_stack_to_reference")
437
  gr.api(fn=_mcp_align_stack_to_stack, api_name="align_stack_to_stack")
 
353
  )
354
 
355
  # ---------------------------------------------------------------------------
356
+ # MCP / API-only endpoints — thin wrappers that return the output file
357
+ # as a Gradio FileData so Gradio/MCP can serve it correctly.
358
  # ---------------------------------------------------------------------------
359
+ def _as_mcp_file(path: str) -> gr.FileData:
360
+ """Wrap a generated local file so Gradio exposes it as a served file."""
361
+ return gr.FileData(
362
+ path=path,
363
+ orig_name=os.path.basename(path),
364
+ mime_type="image/tiff",
365
+ size=os.path.getsize(path),
366
+ )
367
+
368
  def _mcp_align_stack_to_reference(
369
  stack_file: str,
370
  reference_index: int = 0,
371
  mode: str = "RIGID_BODY",
372
  external_reference_file: Optional[str] = None,
373
  external_reference_index: int = 0,
374
+ ) -> gr.FileData:
375
  """Align every frame in a TIFF stack to a chosen reference frame.
376
 
377
  Each frame in stack_file is registered to the selected reference frame
 
397
  stack_file, reference_index, mode,
398
  external_reference_file, external_reference_index,
399
  )
400
+ return _as_mcp_file(out)
401
 
402
  def _mcp_align_stack_to_stack(
403
  reference_stack_file: str,
404
  moving_stack_file: str,
405
  mode: str = "RIGID_BODY",
406
+ ) -> gr.FileData:
407
  """Align every frame in a moving TIFF stack to the first frame of a reference stack.
408
 
409
  Args:
 
418
  The aligned output TIFF file.
419
  """
420
  out = align_stack_to_stack(reference_stack_file, moving_stack_file, mode)
421
+ return _as_mcp_file(out)
422
 
423
  def _mcp_align_frame_to_frame(
424
  stack_file: str,
425
  reference_index: int,
426
  moving_index: int,
427
  mode: str = "RIGID_BODY",
428
+ ) -> gr.FileData:
429
  """Align a single moving frame to a reference frame within the same TIFF stack.
430
 
431
  Args:
 
440
  The aligned single-frame output TIFF file.
441
  """
442
  out = align_frame_to_frame(stack_file, reference_index, moving_index, mode)
443
+ return _as_mcp_file(out)
444
 
445
  gr.api(fn=_mcp_align_stack_to_reference, api_name="align_stack_to_reference")
446
  gr.api(fn=_mcp_align_stack_to_stack, api_name="align_stack_to_stack")