manaankit commited on
Commit
f0e18e5
Β·
verified Β·
1 Parent(s): aec8da0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +68 -7
README.md CHANGED
@@ -1,13 +1,74 @@
1
  ---
2
- title: FinalAgent
3
- emoji: πŸ“‰
4
- colorFrom: blue
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 5.31.0
8
  app_file: app.py
9
  pinned: false
10
- short_description: Agent Course Final Agent Assignment
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: GAIA Agent for HF Course
3
+ emoji: πŸš€
4
+ colorFrom: indigo
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 4.29.0 # Match your Gradio version from requirements.txt
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
+ # GAIA Agent - Hugging Face Agents Course Final Assignment
14
+
15
+ 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.
16
+
17
+ ## 🌟 Agent Capabilities
18
+
19
+ * **Question Understanding**: Parses questions from the GAIA API.
20
+ * **File Handling**: Downloads and processes associated files (text and images) for multimodal questions. Images are passed to Gemini.
21
+ * **Web Search**: Utilizes SerpApi for external web searches to gather relevant, up-to-date information.
22
+ * **LLM Reasoning**: Employs a Google Gemini model (specifically `gemini-1.5-flash-latest` via the official Python SDK) for advanced reasoning, multimodal understanding, and answer generation.
23
+ * **Formatted Output**: Focuses on providing answers in the exact, concise format required by GAIA for scoring, guided by careful prompting.
24
+
25
+ ## πŸ› οΈ How it Works
26
+
27
+ 1. **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.**
28
+ 2. **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`.
29
+ 3. **Process Each Question**:
30
+ * 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.
31
+ * A web search is performed using the question text via SerpApi to gather external context.
32
+ * 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.
33
+ * The Gemini model is called to generate the answer.
34
+ 4. **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.
35
+ 5. **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.
36
+
37
+ ## πŸš€ Running the Agent on Hugging Face Spaces
38
+
39
+ 1. **Duplicate this Space** or create your own and upload these files (`app.py`, `requirements.txt`, `README.md`).
40
+ 2. **Set Secrets**: In your Hugging Face Space settings, go to the "Secrets" section and add the following:
41
+ * `HF_TOKEN`: Your Hugging Face API token with write access (e.g., `hf_YourTokenHere`).
42
+ * `GEMINI_API_KEY`: Your Google AI Studio API key for Gemini (e.g., `AIzaSyYourKeyHere`).
43
+ * `SERPAPI_API_KEY`: Your SerpApi key for web search (e.g., `YourSerpApiKeyHere`).
44
+ 3. **Run the Application**:
45
+ * Open the Gradio app.
46
+ * 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 the `agent_code` link if the `SPACE_ID` environment variable isn't automatically detected (it usually is on HF Spaces).
47
+ * 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.
48
+ * Click the "Run GAIA Assignment ✨" button.
49
+ * Monitor the logs and results in the respective tabs.
50
+
51
+ ## πŸ’» Local Development
52
+
53
+ 1. Clone the repository or save the files locally.
54
+ 2. Create a `.env` file in the root directory and add your API keys:
55
+ ```env
56
+ HF_TOKEN="hf_YourTokenHere"
57
+ GEMINI_API_KEY="AIzaSyYourKeyHere"
58
+ SERPAPI_API_KEY="YourSerpApiKeyHere"
59
+ ```
60
+ 3. Install requirements: `pip install -r requirements.txt`
61
+ 4. Run the app: `python app.py`
62
+ 5. Open the local Gradio URL in your browser and proceed as above.
63
+
64
+ ## πŸ“ Code Structure
65
+
66
+ * `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).
67
+ * `requirements.txt`: Lists the necessary Python packages for the project.
68
+ * `README.md`: This file, providing an overview and instructions.
69
+
70
+ ## 🧠 Model Choice
71
+
72
+ 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.
73
+
74
+ 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.