Spaces:
Sleeping
Sleeping
| """ | |
| Discover tab β free-text concept resolution. | |
| """ | |
| import gradio as gr | |
| from core import config, runner | |
| from core.formatter import format_result | |
| def create_discover_tab(session_keys): | |
| """Build the Discover tab.""" | |
| with gr.Tab("π Discover"): | |
| gr.Markdown( | |
| "## Concept Discovery\n" | |
| "Start with free text β BioMCP resolves concepts by type and suggests follow-up commands.\n" | |
| "Use this when you don't know which entity type to search." | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=3): | |
| query = gr.Textbox( | |
| label="Query", | |
| placeholder='e.g., "ERBB1", "chest pain", "diabetes", "Keytruda"', | |
| lines=1, | |
| ) | |
| with gr.Column(scale=1): | |
| no_cache = gr.Checkbox(label="Bypass cache", value=False) | |
| run_btn = gr.Button("π Discover", variant="primary") | |
| # Quick examples | |
| gr.Markdown("**Quick examples:**") | |
| with gr.Row(): | |
| ex1 = gr.Button("ERBB1", size="sm", variant="secondary") | |
| ex2 = gr.Button("chest pain", size="sm", variant="secondary") | |
| ex3 = gr.Button("diabetes", size="sm", variant="secondary") | |
| ex4 = gr.Button("Keytruda", size="sm", variant="secondary") | |
| ex5 = gr.Button("BRAF V600E", size="sm", variant="secondary") | |
| output_md = gr.Markdown(label="Results") | |
| with gr.Accordion("Raw JSON", open=False): | |
| output_json = gr.Code(language="json") | |
| def run_discover(q, skip_cache, keys): | |
| if not q.strip(): | |
| raise gr.Error("Please enter a query to discover.") | |
| args = ["discover", q.strip()] | |
| env = config.build_env_overrides(keys) | |
| result = runner.run(args, json_mode=True, no_cache=skip_cache, env_overrides=env) | |
| if not result["success"]: | |
| raise gr.Error(f"BioMCP error: {result['error']}") | |
| md, js = format_result(result) | |
| return md, js | |
| run_btn.click( | |
| fn=run_discover, | |
| inputs=[query, no_cache, session_keys], | |
| outputs=[output_md, output_json], | |
| ) | |
| # Wire example buttons | |
| for btn, text in [(ex1, "ERBB1"), (ex2, "chest pain"), (ex3, "diabetes"), | |
| (ex4, "Keytruda"), (ex5, "BRAF V600E")]: | |
| btn.click(fn=lambda t=text: t, outputs=[query]) | |