| | |
| | """ |
| | HuggingFace Agents Course Unit 4 Final Assignment |
| | Multi-Agent System using LangGraph for GAIA Benchmark |
| | |
| | Goal: Achieve 30%+ score on Unit 4 API (GAIA benchmark subset) |
| | Architecture: Multi-agent LangGraph system with Qwen 2.5 models |
| | """ |
| |
|
| | import os |
| | import gradio as gr |
| | from typing import Dict, Any |
| | from dotenv import load_dotenv |
| |
|
| | |
| | load_dotenv() |
| |
|
| | class GAIAAgentSystem: |
| | """Main orchestrator for the GAIA benchmark multi-agent system""" |
| | |
| | def __init__(self): |
| | self.setup_environment() |
| | self.initialize_agents() |
| | |
| | def setup_environment(self): |
| | """Initialize environment and validate required settings""" |
| | self.hf_token = os.getenv("HUGGINGFACE_TOKEN") |
| | if not self.hf_token: |
| | print("WARNING: HUGGINGFACE_TOKEN not set. Some features may be limited.") |
| | |
| | |
| | self.router_model = "Qwen/Qwen2.5-7B-Instruct" |
| | self.main_model = "Qwen/Qwen2.5-32B-Instruct" |
| | self.complex_model = "Qwen/Qwen2.5-72B-Instruct" |
| | |
| | def initialize_agents(self): |
| | """Initialize the multi-agent system components""" |
| | print("🚀 Initializing GAIA Agent System...") |
| | print(f"📱 Router Model: {self.router_model}") |
| | print(f"🧠 Main Model: {self.main_model}") |
| | print(f"🔬 Complex Model: {self.complex_model}") |
| | |
| | |
| | |
| | |
| | |
| | def process_question(self, question: str, files: list = None) -> Dict[str, Any]: |
| | """Process a GAIA benchmark question through the multi-agent system""" |
| | |
| | if not question.strip(): |
| | return { |
| | "answer": "Please provide a question to process.", |
| | "confidence": 0.0, |
| | "reasoning": "No input provided", |
| | "agent_path": [] |
| | } |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | return { |
| | "answer": f"Processing question: {question[:100]}...", |
| | "confidence": 0.5, |
| | "reasoning": "Phase 1 placeholder - agent system initializing", |
| | "agent_path": ["router", "main_agent"] |
| | } |
| |
|
| | def create_gradio_interface(): |
| | """Create the Gradio web interface for HuggingFace Space deployment""" |
| | |
| | agent_system = GAIAAgentSystem() |
| | |
| | def process_with_files(question: str, files): |
| | """Handle question processing with optional file uploads""" |
| | file_list = files if files else [] |
| | result = agent_system.process_question(question, file_list) |
| | |
| | |
| | output = f""" |
| | **Answer:** {result['answer']} |
| | |
| | **Confidence:** {result['confidence']:.1%} |
| | |
| | **Reasoning:** {result['reasoning']} |
| | |
| | **Agent Path:** {' → '.join(result['agent_path'])} |
| | """ |
| | return output |
| | |
| | |
| | interface = gr.Interface( |
| | fn=process_with_files, |
| | inputs=[ |
| | gr.Textbox( |
| | label="GAIA Question", |
| | placeholder="Enter your question here...", |
| | lines=3 |
| | ), |
| | gr.Files( |
| | label="Upload Files (Optional)", |
| | file_count="multiple", |
| | file_types=["image", "audio", ".txt", ".csv", ".xlsx", ".py"] |
| | ) |
| | ], |
| | outputs=gr.Markdown(label="Agent Response"), |
| | title="🤖 GAIA Benchmark Agent System", |
| | description=""" |
| | Multi-agent system for the GAIA benchmark using LangGraph framework. |
| | |
| | **Capabilities:** |
| | - Multi-step reasoning and planning |
| | - Web search and research |
| | - File processing (images, audio, documents) |
| | - Mathematical computation |
| | - Code execution and analysis |
| | |
| | **Target:** 30%+ accuracy on GAIA benchmark questions |
| | """, |
| | examples=[ |
| | ["What is the population of France?", None], |
| | ["Calculate the square root of 144", None], |
| | ["Analyze the uploaded image and describe what you see", None] |
| | ], |
| | theme=gr.themes.Soft() |
| | ) |
| | |
| | return interface |
| |
|
| | def main(): |
| | """Main entry point""" |
| | print("🎯 HuggingFace Agents Course Unit 4 - Final Assignment") |
| | print("📊 Target: 30%+ score on GAIA benchmark") |
| | print("🔧 Framework: LangGraph multi-agent system") |
| | print("💰 Budget: Free tier models (~$0.10/month)") |
| | |
| | |
| | interface = create_gradio_interface() |
| | |
| | |
| | interface.launch( |
| | share=False, |
| | server_name="0.0.0.0", |
| | server_port=7860, |
| | show_error=True |
| | ) |
| |
|
| | if __name__ == "__main__": |
| | main() |