Download app_backup.py from K00B404/toolshed: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/K00B404/toolshed/resolve/main/app_backup.py
- Command line
-
hf download hf://spaces/K00B404/toolshed/app_backup.py
-
curl -L -o app_backup.py https://huggingface.co/spaces/K00B404/toolshed/resolve/main/app_backup.py
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) |