toolshed / app_backup.py
K00B404's picture
Rename app.py to app_backup.py
3681e7c verified
raw
history blame
1.5 kB
import gradio as gr
import requests
def register_tool(tool_data):
# Send a POST request to register the tool
response = requests.post("https://huggingface.co/chat/tools/new", json=tool_data)
return response.json()
def create_tool(tool_name, tool_data):
print("fn create_tool")
print(tool_name)
print(dir(tool_data))
tool_payload = {
"displayName": tool_data.get("displayName"),
"description": tool_data.get("description"),
"color": tool_data.get("color"), # Example color
"icon": tool_data.get("icon"),
"baseUrl": "K00B404/toolshed",
"endpoint": "/router",
"name": tool_data.get("name"),
"inputs": inputs,
"outputComponent": tool_data.get("outputComponent"), # Adjust based on your tool's output
"outputComponentIdx": tool_data.get("outputComponentIdx"),
"showOutput": tool_data.get("showOutput")
}
print(dir(tool_payload))
return register_tool(tool_payload)
def no_tool_match(tool_name: str, tool_inputs: dict):
print("fn no match")
print(tool)
print(dir(tool_inputs))
def tool_router(tool_name: str, tool_inputs: dict):
print("fn tool_router")
print(tool_name)
print(dir(tool_data))
if tool_name == "create_tool":
create_tool(tool_name, tool_inputs)
else:
no_tool_match()
demo = gr.Interface(
fn=tool_router,
inputs=["text", {}],
outputs=["text", "number"],
)
demo.launch(show_api=True, share=True)