Spaces:
Sleeping
Sleeping
File size: 3,283 Bytes
9c9b3ff 2705160 62ad9da |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# Hugging Face AI Agents Course - Final Exam Agent
This project contains an AI agent developed for the final exam of the Hugging Face AI Agents Course. The agent is designed to answer a variety of questions by leveraging a suite of powerful tools and a language model.
## Overview
This agent is built using the `LangGraph` library to create a robust and stateful agent. It can perform a variety of tasks, including web searches, calculations, code execution, and processing different types of media like audio, images, and documents. The project includes a Gradio application for evaluating the agent's performance on a set of questions provided by the course.
## Features
* **Multi-tool Integration**: The agent can use a wide range of tools to solve complex problems.
* **Conversational AI**: Powered by a capable language model from OpenRouter.
* **Stateful Execution**: Uses `LangGraph` to manage the conversation flow and tool execution in a structured manner.
* **Web Interface**: A Gradio app (`app.py`) is provided to test and evaluate the agent.
* **Extensible**: New tools can be easily added to enhance the agent's capabilities.
## Tools
The agent has access to the following tools:
### Community Tools
* **Brave Search**: Performs web searches to find up-to-date information.
* **Python REPL**: Executes Python code to solve logic and math problems.
### Custom Tools
* **Calculator**:
* `add(a, b)`: Adds two numbers.
* `subtract(a, b)`: Subtracts two numbers.
* `multiply(a, b)`: Multiplies two numbers.
* `divide(a, b)`: Divides two numbers.
* `power(a, b)`: Calculates `a` to the power of `b`.
* **Date & Time**:
* `current_date()`: Returns the current date.
* `day_of_week()`: Returns the current day of the week.
* `days_until(date_str)`: Calculates the number of days until a given date.
* **Media Processing**:
* `transcribe_audio(audio_file, file_extension)`: Transcribes audio files.
* `transcribe_youtube(youtube_url)`: Transcribes YouTube videos.
* `query_image(query, image_url)`: Answers questions about an image.
* **Web & Document Content**:
* `webpage_content(url)`: Extracts text from webpages and PDF files.
* `read_excel(file_path, sheet_name, query)`: Reads data from an Excel file and answers a query about it.
## How It Works
The agent's logic is defined in `agent.py`. It uses a `StateGraph` from the `LangGraph` library to manage its execution flow. The graph has two main nodes:
1. **`llm_call`**: This node calls the language model with the current conversation history and a system prompt (`prompt.py`). The LLM decides whether to respond directly to the user or to use one of the available tools.
2. **`environment`**: If the LLM decides to use a tool, this node executes the tool with the arguments provided by the LLM.
The agent alternates between these two nodes until the LLM generates a final answer for the user.
## Usage
### 1. Installation
Clone the repository and install the required dependencies:
```bash
git clone https://huggingface.co/spaces/YOUR_SPACE_HERE
cd YOUR_REPO
pip install -r requirements.txt
```
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference |