File size: 1,392 Bytes
a206188
87179f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import requests
import gradio as gr

def interact_with_flowise_api(operation, input_data, flow_id=None):
    base_url = "http://dev.daisy.plus"
    app3_route = "/api/v1/chatflows"
    url = f"{base_url}{app3_route}"
    headers = {'Content-Type': 'application/json'}

    if operation == "POST":
        response = requests.post(url, json={"data": input_data}, headers=headers)
    elif operation == "GET":
        response = requests.get(f"{url}/{flow_id}", headers=headers)
    elif operation == "PUT":
        response = requests.put(f"{url}/{flow_id}", json={"data": input_data}, headers=headers)
    elif operation == "DELETE":
        response = requests.delete(f"{url}/{flow_id}", headers=headers)
    else:
        return {"error": "Unsupported operation"}

    try:
        return response.json()
    except ValueError:
        return {"error": "Invalid response or no data"}

iface = gr.Interface(
    fn=interact_with_flowise_api, 
    inputs=[
        gr.Dropdown(choices=["POST", "GET", "PUT", "DELETE"], label="Operation"),
        gr.Textbox(lines=2, placeholder="Input data", label="Input Data"),
        gr.Textbox(lines=1, placeholder="Flow ID (for GET, PUT, DELETE)", label="Flow ID")
    ], 
    outputs="json",
    title="Flowise API - Chatflows",
    description="Interact with Flowise chatflow API endpoints"
)

if __name__ == "__main__":
    iface.launch()