Spaces:
Sleeping
Sleeping
File size: 936 Bytes
f103ad7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """
Formatting helpers: convert biomcp output into Gradio-friendly display.
"""
import json
import re
def _strip_suggested_commands(md: str) -> str:
"""Remove the '## Suggested Commands' section from markdown output."""
return re.split(r"\n##\s+Suggested Commands", md, maxsplit=1)[0].rstrip()
def format_result(result: dict) -> tuple[str, str]:
"""
Format a runner result into (markdown_display, json_display).
Returns two strings suitable for gr.Markdown and gr.Code components.
"""
if not result["success"]:
error_md = f"⚠️ **Error:** {result['error']}"
return error_md, json.dumps({"error": result["error"]}, indent=2)
# Markdown display
md = _strip_suggested_commands(result["markdown"])
# JSON display
if result["data"] is not None:
json_str = json.dumps(result["data"], indent=2, default=str)
else:
json_str = ""
return md, json_str
|