Spaces:
Sleeping
Sleeping
File size: 1,863 Bytes
9385802 0faebff 9385802 0faebff 9385802 0faebff 13baac3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import gradio as gr
import requests
import json
API_URL = "https://cloud.flowiseai.com/"
TOKEN = "Bearer qHBaan1Rq3ey80fHiJp5qq-ql65wrDveH327sRjIRoQ"
def call_flowise_api(action, id_or_key, body):
headers = {"Authorization": TOKEN}
endpoint = f"{API_URL}/chatflows"
try:
if action == "list":
response = requests.get(endpoint, headers=headers)
elif action == "get":
response = requests.get(f"{endpoint}/{id_or_key}", headers=headers)
elif action == "create":
response = requests.post(endpoint, headers=headers, json=json.loads(body))
elif action == "update":
response = requests.put(f"{endpoint}/{id_or_key}", headers=headers, json=json.loads(body))
elif action == "delete":
response = requests.delete(f"{endpoint}/{id_or_key}", headers=headers)
elif action == "get_by_apikey":
response = requests.get(f"{endpoint}/apikey/{id_or_key}", headers=headers)
else:
return f"Unknown action: {action}", ""
return f"Status Code: {response.status_code}", response.text
except Exception as e:
return "Error", str(e)
with gr.Blocks() as demo:
gr.Markdown("## 🛠️ Flowise Chatflow API Debugger")
action = gr.Dropdown(
["list", "get", "create", "update", "delete", "get_by_apikey"],
label="Action"
)
id_or_key = gr.Textbox(label="Chatflow ID or API Key")
body = gr.Textbox(label="JSON Body", lines=10, placeholder='{"name": "Test Flow"}')
status_output = gr.Textbox(label="Status", interactive=False)
response_output = gr.Textbox(label="Response", lines=15, interactive=False)
run_button = gr.Button("Run")
run_button.click(fn=call_flowise_api, inputs=[action, id_or_key, body], outputs=[status_output, response_output])
gr.app(demo, mcp=True)
|