ObiJuanCodenobi commited on
Commit
87179f7
·
verified ·
1 Parent(s): 462bc80

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import requests
3
+ import gradio as gr
4
+
5
+ def interact_with_flowise_api(operation, input_data, flow_id=None):
6
+ base_url = "http://dev.daisy.plus"
7
+ app3_route = "/api/v1/chatflows"
8
+ url = f"{base_url}{app3_route}"
9
+ headers = {'Content-Type': 'application/json'}
10
+
11
+ if operation == "POST":
12
+ response = requests.post(url, json={"data": input_data}, headers=headers)
13
+ elif operation == "GET":
14
+ response = requests.get(f"{url}/{flow_id}", headers=headers)
15
+ elif operation == "PUT":
16
+ response = requests.put(f"{url}/{flow_id}", json={"data": input_data}, headers=headers)
17
+ elif operation == "DELETE":
18
+ response = requests.delete(f"{url}/{flow_id}", headers=headers)
19
+ else:
20
+ return {"error": "Unsupported operation"}
21
+
22
+ try:
23
+ return response.json()
24
+ except ValueError:
25
+ return {"error": "Invalid response or no data"}
26
+
27
+ iface = gr.Interface(
28
+ fn=interact_with_flowise_api,
29
+ inputs=[
30
+ gr.Dropdown(choices=["POST", "GET", "PUT", "DELETE"], label="Operation"),
31
+ gr.Textbox(lines=2, placeholder="Input data", label="Input Data"),
32
+ gr.Textbox(lines=1, placeholder="Flow ID (for GET, PUT, DELETE)", label="Flow ID")
33
+ ],
34
+ outputs="json",
35
+ title="Flowise API - Chatflows",
36
+ description="Interact with Flowise chatflow API endpoints"
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ iface.launch()