Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def register_tool(tool_data):
|
5 |
+
# Send a POST request to register the tool
|
6 |
+
response = requests.post("https://huggingface.co/chat/tools/new", json=tool_data)
|
7 |
+
return response.json()
|
8 |
+
|
9 |
+
def create_tool(display_name, description, inputs):
|
10 |
+
tool_data = {
|
11 |
+
"displayName": display_name,
|
12 |
+
"description": description,
|
13 |
+
"color": "yellow", # Example color
|
14 |
+
"icon": "tools",
|
15 |
+
"baseUrl": "K00B404/toolshed",
|
16 |
+
"endpoint": "/query",
|
17 |
+
"name": "query",
|
18 |
+
"inputs": inputs,
|
19 |
+
"outputComponent": "0;image", # Adjust based on your tool's output
|
20 |
+
"outputComponentIdx": 0,
|
21 |
+
"showOutput": True
|
22 |
+
}
|
23 |
+
return register_tool(tool_data)
|
24 |
+
|
25 |
+
inputs = [
|
26 |
+
gr.inputs.Textbox(label="Display Name"),
|
27 |
+
gr.inputs.Textbox(label="Description"),
|
28 |
+
gr.inputs.JSON(label="Inputs (JSON format)"), # Allow user to input inputs in JSON
|
29 |
+
]
|
30 |
+
|
31 |
+
gr.Interface(fn=create_tool, inputs=inputs, outputs="json").launch()
|