Spaces:
Sleeping
Sleeping
| """ | |
| 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 | |