| import gradio as gr | |
| import requests | |
| import json | |
| import server | |
| API_URL = "http://localhost:8000" | |
| def optimize_rag_tool(payload: str) -> str: | |
| """Run RAGMint full optimization workflow. | |
| Args: | |
| payload: JSON string containing OptimizeRequest parameters. | |
| Returns: | |
| JSON result with best config and leaderboard stats. | |
| """ | |
| r = requests.post(f"{API_URL}/optimize_rag", json=json.loads(payload)) | |
| return json.dumps(r.json(), indent=2) | |
| def autotune_tool(payload: str) -> str: | |
| """Run AutoRAG tuner to recommend best configs and optimize. | |
| Args: | |
| payload: JSON string for AutotuneRequest | |
| Returns: | |
| JSON result for tuning and full optimization. | |
| """ | |
| r = requests.post(f"{API_URL}/autotune_rag", json=json.loads(payload)) | |
| return json.dumps(r.json(), indent=2) | |
| def generate_qa_tool(payload: str) -> str: | |
| """Generate validation QA set automatically with Gemini or Anthropic. | |
| Args: | |
| payload: JSON string for QARequest | |
| Returns: | |
| JSON preview of generated dataset | |
| """ | |
| r = requests.post(f"{API_URL}/generate_validation_qa", json=json.loads(payload)) | |
| return json.dumps(r.json(), indent=2) | |
| demo = gr.Interface( | |
| fn=optimize_rag_tool, | |
| inputs=gr.Textbox(lines=12, label="OptimizeRequest JSON"), | |
| outputs=gr.Textbox(label="Response") | |
| ) | |
| demo.launch(mcp_server=True) | |