ObiJuanCodenobi commited on
Commit
0faebff
·
1 Parent(s): 9385802

adds cloud api

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