Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import gradio as grimport osimport sysimport importlib
# ConfigurationTOOLS_DIR = "tools"
# Ensure tools directory exists and is a packageif not os.path.exists(TOOLS_DIR): os.makedirs(TOOLS_DIR, exist_ok=True) with open(os.path.join(TOOLS_DIR, "__init__.py"), "w") as f: pass
# Add current directory to path so 'import tools.xxx' workssys.path.append(os.path.dirname(os.path.abspath(__file__)))
interfaces = []names = []
print(f"π Starting Meta-MCP Toolbox...")print(f"π Scanning '{TOOLS_DIR}' directory...")
# Scan and import toolstry: for filename in sorted(os.listdir(TOOLS_DIR)): if filename.endswith(".py") and not filename.startswith("_"): module_name = filename[:-3] full_module_name = f"{TOOLS_DIR}.{module_name}"
try: print(f" π Importing {full_module_name}...") # Standard dynamic import # Use reload to ensure latest version is taken if restarted module = importlib.import_module(full_module_name) importlib.reload(module)
if hasattr(module, "create_interface"): # Create Gradio interface for this tool tool_interface = module.create_interface() interfaces.append(tool_interface) names.append(module_name) print(f" β
Loaded {module_name}") else: print(f" β οΈ Module {module_name} has no create_interface()") except Exception as e: print(f" β Error loading {module_name}: {e}") import traceback traceback.print_exc()
except Exception as e: print(f"Error scanning tools directory: {e}")
# Final interface constructionif not interfaces: demo = gr.Interface( fn=lambda x: "No tools loaded yet. Add a tool via Meta-MCP!", inputs="text", outputs="text", title="Empty Toolbox", description="This Space is ready to receive tools." )else: demo = gr.TabbedInterface(interfaces, names)
if __name__ == "__main__": demo.launch(mcp_server=True, show_error=True)app.pyAdded+67