Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
6.5.1
metadata
title: SecrectDocumentLocker
app_file: app.py
sdk: gradio
sdk_version: 6.3.0
SmolAgents with FastMCP Demo
This project demonstrates a SmolAgents agent interacting with a local MCP server created using FastMCP.
Features
- MCP Server: (
mcp_server.py)- Implements a dummy authentication tool.
- Protects a "treasure" resource (
treasure://secret) which is only accessible after authentication. - Exposes a
read_treasuretool.
- Agent: (
agent.py)- Uses
smolagents.MCPClientto connect to the local MCP server. - Dynamically loads tools from the MCP server.
- Uses
meta-llama/Llama-4-Scoutmodel via Hugging Face Inference API.
- Uses
- UI: (
app.py)- Provides a Gradio chat interface for the agent.
Setup
Install Dependencies:
pip install -r requirements.txtEnvironment Variables: You need a Hugging Face Token to use the Inference API. Create a
.envfile in the root directory:HF_TOKEN=your_hf_token_here
Running Locally
- Run the Gradio app:
python app.py - Open the link provided in the terminal (usually http://127.0.0.1:7860).
- Chat with the agent! Try:
"Read the treasure file." (The agent should try, fail, then realize it needs to authenticate. Hint: the password is "open sesame")
Deploying to Hugging Face Spaces
- Create a new Space on Hugging Face (SDK: Gradio).
- Upload the files:
app.pyagent.pymcp_server.pydummy_treasure.txtrequirements.txt
- Set the
HF_TOKENin the Space's Settings > Variables and secrets (if not automatically handled, though Spaces usually have access to the token of the owner if configured, but explicit token is safer for specific model access). - The Space should build and run automatically!
Files
mcp_server.py: The FastMCP server implementation.agent.py: Agent logic including MCP connection.app.py: Entry point for Gradio.dummy_treasure.txt: The protected content.
Deploying to Hugging Face Spaces
- Create a new Space on Hugging Face (SDK: Gradio).
- Upload the files:
app.pyagent.pymcp_server.pydummy_treasure.txtrequirements.txt
- Set the
HF_TOKENin the Space's Settings > Variables and secrets (if not automatically handled, though Spaces usually have access to the token of the owner if configured, but explicit token is safer for specific model access). - The Space should build and run automatically!
Files
mcp_server.py: The FastMCP server implementation.agent.py: Agent logic including MCP connection.app.py: Entry point for Gradio.dummy_treasure.txt: The protected content.
Deploying to Hugging Face Spaces
hf upload --repo-type space ohmp/SecrectDocumentLocker . --exclude ".env" ".venv/**" "__pycache__/**" "*.pyc"