Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -16,3 +16,142 @@ tags:
|
|
| 16 |
---
|
| 17 |
|
| 18 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
---
|
| 17 |
|
| 18 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# 🤖 First Agent Project
|
| 22 |
+
|
| 23 |
+
Welcome to the **First Agent Project** — an elegant and modular AI agent system powered by [SmolAgents](https://github.com/huggingface/smol-agents), capable of solving complex tasks using structured reasoning, tool use, and code execution. Designed with usability and extensibility in mind, this project features a dynamic Gradio-based interface, plug-and-play tools, and a powerful HuggingFace model backend.
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## ✨ Features
|
| 28 |
+
|
| 29 |
+
- 🔁 **Multi-Step Reasoning** with an agent that can plan, execute code, and invoke tools.
|
| 30 |
+
- 🌐 **Web Search Tool** via DuckDuckGo for live queries.
|
| 31 |
+
- 🧭 **Webpage Reader Tool** to fetch and parse web pages in Markdown.
|
| 32 |
+
- 📅 **Time and Weather Tools** for real-time timezone and temperature queries.
|
| 33 |
+
- 🖼️ **Image Generation** support using HuggingFace tool hub.
|
| 34 |
+
- 🎯 **Gradio UI Integration** with step-wise conversational tracing.
|
| 35 |
+
- 📦 Modular structure — easily extensible with custom tools.
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## 🧠 Project Structure
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
.
|
| 43 |
+
├── app.py # Main entrypoint - defines tools, loads agent, and launches Gradio UI
|
| 44 |
+
├── Gradio_UI.py # Elegant multi-step UI for interaction using Gradio
|
| 45 |
+
├── tools/final_answer.py # Defines a final answer tool to conclude tasks
|
| 46 |
+
├── tools/visit_webpage.py # Tool to visit a URL and extract readable markdown content
|
| 47 |
+
├── tools/web_search.py # Tool for DuckDuckGo web search queries
|
| 48 |
+
├── requirements.txt # Python dependencies
|
| 49 |
+
├── agent.json # Agent configuration (tools, model, prompts, rules)
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## 🧰 Built-in Tools
|
| 55 |
+
|
| 56 |
+
| Tool Name | Description |
|
| 57 |
+
|-------------------|-----------------------------------------------------------------------------|
|
| 58 |
+
| `web_search` | Search the web using DuckDuckGo |
|
| 59 |
+
| `visit_webpage` | Visit and parse the content of a webpage as markdown |
|
| 60 |
+
| `get_temperature` | Get real-time temperature of a given city |
|
| 61 |
+
| `get_current_time_in_timezone` | Get local time in a specified timezone |
|
| 62 |
+
| `final_answer` | Returns the final response to a task |
|
| 63 |
+
| `text-to-image` | Generates images using HuggingFace image generation API (remote tool) |
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## 🚀 Quick Start
|
| 68 |
+
|
| 69 |
+
### 1. Install Dependencies
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
pip install -r requirements.txt
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### 2. Run the App
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
python app.py
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
This will launch a Gradio interface where you can interact with your agent conversationally.
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## 🌈 Sample Tasks
|
| 86 |
+
|
| 87 |
+
Try asking the agent:
|
| 88 |
+
|
| 89 |
+
- "What is the current temperature in Tokyo?"
|
| 90 |
+
- "Find the age of the Pope and raise it to the power of 0.36"
|
| 91 |
+
- "Search for latest news on Mars exploration"
|
| 92 |
+
- "Generate an image of a futuristic AI-powered city"
|
| 93 |
+
- "What’s the current time in New York?"
|
| 94 |
+
|
| 95 |
+
---
|
| 96 |
+
|
| 97 |
+
## 🛠️ Under the Hood
|
| 98 |
+
|
| 99 |
+
### 🧠 Agent Model
|
| 100 |
+
- Powered by [`Qwen/Qwen2.5-Coder-32B-Instruct`](https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct)
|
| 101 |
+
- HuggingFace API wrapper (`HfApiModel`) with streaming and code execution.
|
| 102 |
+
|
| 103 |
+
### 💬 Prompt Planning Logic
|
| 104 |
+
- Configured in `agent.json` with step-by-step templates, planning logic, and reasoning strategy.
|
| 105 |
+
- Structured prompt system encourages:
|
| 106 |
+
- Thought → Code → Observation → Final Answer loops
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
## 🖼️ UI Highlights
|
| 111 |
+
|
| 112 |
+
- 💬 Chat-based interface with message tracking
|
| 113 |
+
- ⚙️ Shows tool usage logs, execution reasoning, and token statistics
|
| 114 |
+
- 📁 Supports file uploads (PDF, DOCX, TXT)
|
| 115 |
+
- 🧵 Maintains step context and memory
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
## 🔧 Customize or Extend
|
| 120 |
+
|
| 121 |
+
### Adding Your Own Tool
|
| 122 |
+
|
| 123 |
+
You can add custom tools easily by subclassing `Tool`. Example:
|
| 124 |
+
```python
|
| 125 |
+
from smolagents.tools import Tool
|
| 126 |
+
|
| 127 |
+
class MyTool(Tool):
|
| 128 |
+
name = "my_tool"
|
| 129 |
+
description = "Describe what your tool does here."
|
| 130 |
+
inputs = {'input1': {'type': 'string', 'description': 'Your input'}}
|
| 131 |
+
output_type = "string"
|
| 132 |
+
|
| 133 |
+
def forward(self, input1: str) -> str:
|
| 134 |
+
# Your logic
|
| 135 |
+
return "Output result"
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
Then add it in `app.py` to the agent's tools list.
|
| 139 |
+
|
| 140 |
+
---
|
| 141 |
+
|
| 142 |
+
## 📜 License
|
| 143 |
+
|
| 144 |
+
This project is licensed under the Apache 2.0 License. See the [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) file for details.
|
| 145 |
+
|
| 146 |
+
---
|
| 147 |
+
|
| 148 |
+
## 🌟 Acknowledgements
|
| 149 |
+
|
| 150 |
+
Built using:
|
| 151 |
+
|
| 152 |
+
- 🤖 [SmolAgents](https://github.com/huggingface/smol-agents)
|
| 153 |
+
- 🌐 [DuckDuckGo Search](https://pypi.org/project/duckduckgo-search/)
|
| 154 |
+
- 🧾 [Markdownify](https://pypi.org/project/markdownify/)
|
| 155 |
+
- 🔥 [Gradio](https://gradio.app/)
|
| 156 |
+
- 🧠 [Qwen Model on HuggingFace](https://huggingface.co/Qwen)
|
| 157 |
+
|