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()