Spaces:
Sleeping
Download README.md from manaankit/FinalAgent: direct link, hf CLI and curl.
- Browser
- Download file 5.33 kB
-
https://huggingface.co/spaces/manaankit/FinalAgent/resolve/main/README.md
- Command line
-
hf download hf://spaces/manaankit/FinalAgent/README.md
-
curl -L -o README.md https://huggingface.co/spaces/manaankit/FinalAgent/resolve/main/README.md
A newer version of the Gradio SDK is available: 6.32.0
title: GAIA Agent for HF Course
emoji: π
colorFrom: indigo
colorTo: green
sdk: gradio
sdk_version: 4.29.0
app_file: app.py
pinned: false
license: apache-2.0
GAIA Agent - Hugging Face Agents Course Final Assignment
This is a solution for the Hugging Face Agents Course Final Assignment. It implements an AI agent that attempts to solve a subset of Level 1 questions from the GAIA benchmark, aiming for a score of 30% or higher.
π Agent Capabilities
- Question Understanding: Parses questions from the GAIA API.
- File Handling: Downloads and processes associated files (text and images) for multimodal questions. Images are passed to Gemini.
- Web Search: Utilizes SerpApi for external web searches to gather relevant, up-to-date information.
- LLM Reasoning: Employs a Google Gemini model (specifically
gemini-1.5-flash-latestvia the official Python SDK) for advanced reasoning, multimodal understanding, and answer generation. - Formatted Output: Focuses on providing answers in the exact, concise format required by GAIA for scoring, guided by careful prompting.
π οΈ How it Works
- Setup: The application uses a Gradio interface. It requires API keys for Hugging Face (for submission and API access to the course API), Google Gemini (for the LLM), and SerpApi (for web search). These should be set as Secrets in your Hugging Face Space for deployment.
- Fetch Questions: The agent retrieves the list of 20 filtered GAIA questions from the course-specific API endpoint:
https://huggingface.co/spaces/agents-course/gaia_api_clone. - Process Each Question:
- If a file is associated with the question, it's downloaded. Images are prepared for multimodal input to Gemini, and text file contents are extracted.
- A web search is performed using the question text via SerpApi to gather external context.
- A detailed prompt is constructed, including the original question, context from any downloaded file, and web search results. This prompt instructs the Gemini model to provide a concise, accurately formatted answer without any extraneous text.
- The Gemini model is called to generate the answer.
- Submit Answers: Once all questions are processed, the collected answers are submitted to the GAIA API along with the Hugging Face username and a link to this Space's code.
- Display Results: The submission log, individual answers submitted (in JSON format), the final score, and the full submission result are displayed in the Gradio interface.
π Running the Agent on Hugging Face Spaces
- Duplicate this Space or create your own and upload these files (
app.py,requirements.txt,README.md). - Set Secrets: In your Hugging Face Space settings, go to the "Secrets" section and add the following:
HF_TOKEN: Your Hugging Face API token with write access (e.g.,hf_YourTokenHere).GEMINI_API_KEY: Your Google AI Studio API key for Gemini (e.g.,AIzaSyYourKeyHere).SERPAPI_API_KEY: Your SerpApi key for web search (e.g.,YourSerpApiKeyHere).
- Run the Application:
- Open the Gradio app.
- Enter your Hugging Face username (e.g.,
MyUserName) or your Space name (e.g.,MyUserName/MyGaiaAgentSpace) in the designated input field. The username part is used in the submission payload. The Space name helps form theagent_codelink if theSPACE_IDenvironment variable isn't automatically detected (it usually is on HF Spaces). - The API keys will be picked up from the Space secrets. You can optionally override them via the UI for testing, but this is less secure.
- Click the "Run GAIA Assignment β¨" button.
- Monitor the logs and results in the respective tabs.
π» Local Development
- Clone the repository or save the files locally.
- Create a
.envfile in the root directory and add your API keys:HF_TOKEN="hf_YourTokenHere" GEMINI_API_KEY="AIzaSyYourKeyHere" SERPAPI_API_KEY="YourSerpApiKeyHere" - Install requirements:
pip install -r requirements.txt - Run the app:
python app.py - Open the local Gradio URL in your browser and proceed as above.
π Code Structure
app.py: Contains the main Gradio application, agent logic for solving questions, interactions with the GAIA API, LLM calls to Gemini, and tool integrations (web search, file handling).requirements.txt: Lists the necessary Python packages for the project.README.md: This file, providing an overview and instructions.
π§ Model Choice
The agent uses Google's gemini-1.5-flash-latest model via the google-generativeai Python SDK. This model is chosen for its strong multimodal capabilities, reasoning skills, and efficiency, making it well-suited for GAIA tasks. The prompt explicitly instructs the model to avoid conversational fluff and adhere strictly to formatting requirements.
The initial prompt mentioned trying an "Hugging Face inference model of Gemini." Direct access to Google's Gemini models is typically through their own SDKs or cloud platforms rather than the general Hugging Face Inference API for open-source models. This solution uses the official Google Generative AI SDK for reliable and feature-rich access to Gemini.