Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import json | |
| # π₯ ONLY YOU SET THIS (your n8n production webhook) | |
| N8N_WEBHOOK_URL = "https://jarvis-4.app.n8n.cloud/webhook/api-debug" | |
| def run_agent(api_key, payload_text): | |
| try: | |
| # Parse JSON input from judge | |
| try: | |
| payload = json.loads(payload_text) if payload_text else {} | |
| except: | |
| return "β Invalid JSON format in input payload." | |
| # Inject API key into payload (IMPORTANT) | |
| payload["api_key"] = api_key | |
| headers = { | |
| "Content-Type": "application/json" | |
| } | |
| # Call your n8n agent | |
| response = requests.post( | |
| N8N_WEBHOOK_URL, | |
| json=payload, | |
| headers=headers, | |
| timeout=40 | |
| ) | |
| # Try parsing response from n8n | |
| try: | |
| result = response.json() | |
| except: | |
| result = response.text | |
| # π₯ IMPORTANT: we DO NOT decide success/failure here | |
| # We simply show whatever your agent returns | |
| return json.dumps(result, indent=2) if isinstance(result, dict) else result | |
| except requests.exceptions.RequestException as e: | |
| return f"β Request failed:\n{str(e)}" | |
| # UI (what judges see) | |
| with gr.Blocks(title="AI Agent Judge Interface") as demo: | |
| gr.Markdown("# π€ AI Agent Evaluation Portal") | |
| gr.Markdown("Enter API key and input data. The backend n8n agent will validate and respond.") | |
| api_key = gr.Textbox(label="π API Key", type="password") | |
| payload = gr.Textbox( | |
| label="π¦ Input JSON", | |
| placeholder='{"url":"https://api.github.com/users/octocat","method":"GET"}', | |
| lines=6 | |
| ) | |
| btn = gr.Button("π Run Agent") | |
| output = gr.Textbox(label="π Agent Response", lines=18) | |
| btn.click(run_agent, inputs=[api_key, payload], outputs=output) | |
| demo.launch() |