API_Checking / app.py
PradeepA61's picture
Upload app.py
49d34c6 verified
Raw
History Blame Contribute Delete
1.94 kB
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()