Psiska commited on
Commit
ebc57d0
·
1 Parent(s): 1daae6b
__pycache__/crew.cpython-310.pyc ADDED
Binary file (8.93 kB). View file
 
__pycache__/utils.cpython-310.pyc ADDED
Binary file (1.94 kB). View file
 
app.py CHANGED
@@ -1,152 +1,98 @@
1
- import os, threading
2
  import gradio as gr
3
- from crew import run_crew
4
- from utils import get_questions
5
-
6
- def ask(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name = ""):
7
- """
8
- Ask General AI Assistant a question to answer.
9
-
10
- Args:
11
- question (str): The question to answer
12
- openai_api_key (str): OpenAI API key
13
- gemini_api_key (str): Gemini API key
14
- anthropic_api_key (str): Anthropic API key
15
- file_name (str): Optional file name
16
-
17
- Returns:
18
- str: The answer to the question
19
- """
20
- if not question:
21
- raise gr.Error("Question is required.")
22
-
23
- if not openai_api_key:
24
- raise gr.Error("OpenAI API Key is required.")
25
-
26
- if not gemini_api_key:
27
- raise gr.Error("Gemini API Key is required.")
28
-
29
- if not anthropic_api_key:
30
- raise gr.Error("Anthropic API Key is required.")
31
-
32
- if file_name:
33
- file_name = f"data/{file_name}"
34
-
35
- lock = threading.Lock()
36
-
37
- with lock:
38
- answer = ""
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  try:
41
- os.environ["OPENAI_API_KEY"] = openai_api_key
42
- os.environ["GEMINI_API_KEY"] = gemini_api_key
43
- os.environ["MODEL_API_KEY"] = anthropic_api_key
44
-
45
- answer = run_crew(question, file_name)
46
  except Exception as e:
47
- raise gr.Error(e)
48
- finally:
49
- del os.environ["OPENAI_API_KEY"]
50
- del os.environ["GEMINI_API_KEY"]
51
- del os.environ["MODEL_API_KEY"]
52
-
53
- return answer
54
-
55
- gr.close_all()
56
-
57
- with gr.Blocks() as grady:
58
- gr.Markdown("## Grady - General AI Assistant")
59
-
60
- with gr.Tab("Solution"):
61
- gr.Markdown(os.environ.get("DESCRIPTION"))
62
-
63
- with gr.Row():
64
- with gr.Column(scale=3):
65
- with gr.Row():
66
- question = gr.Textbox(
67
- label="Question *",
68
- placeholder="In the 2025 Gradio Agents & MCP Hackathon, what percentage of participants submitted a solution during the last 24 hours?",
69
- interactive=True
70
- )
71
- with gr.Row():
72
- level = gr.Radio(
73
- choices=[1, 2, 3],
74
- label="GAIA Benchmark Level",
75
- interactive=True,
76
- scale=1
77
- )
78
- ground_truth = gr.Textbox(
79
- label="Ground Truth",
80
- interactive=True,
81
- scale=1
82
- )
83
- file_name = gr.Textbox(
84
- label="File Name",
85
- interactive=True,
86
- scale=2
87
- )
88
- with gr.Row():
89
- openai_api_key = gr.Textbox(
90
- label="OpenAI API Key *",
91
- type="password",
92
- placeholder="sk‑...",
93
- interactive=True
94
- )
95
- gemini_api_key = gr.Textbox(
96
- label="Gemini API Key *",
97
- type="password",
98
- interactive=True
99
- )
100
- anthropic_api_key = gr.Textbox(
101
- label="Anthropic API Key *",
102
- type="password",
103
- placeholder="sk-ant-...",
104
- interactive=True
105
- )
106
- with gr.Row():
107
- clear_btn = gr.ClearButton(
108
- components=[question, level, ground_truth, file_name]
109
- )
110
- submit_btn = gr.Button("Submit", variant="primary")
111
- with gr.Column(scale=1):
112
- answer = gr.Textbox(
113
- label="Answer",
114
- lines=1,
115
- interactive=False
116
- )
117
-
118
- submit_btn.click(
119
- fn=ask,
120
- inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, file_name],
121
- outputs=answer
122
- )
123
-
124
- QUESTION_FILE_PATH = "data/gaia_validation.jsonl"
125
-
126
- gr.Examples(
127
- label="GAIA Benchmark Level 1 Problems",
128
- examples=get_questions(QUESTION_FILE_PATH, 1),
129
- inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
130
- outputs=answer,
131
- cache_examples=False
132
- )
133
-
134
- gr.Examples(
135
- label="GAIA Benchmark Level 2 Problems",
136
- examples=get_questions(QUESTION_FILE_PATH, 2),
137
- inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
138
- outputs=answer,
139
- cache_examples=False
140
- )
141
-
142
- gr.Examples(
143
- label="GAIA Benchmark Level 3 Problems",
144
- examples=get_questions(QUESTION_FILE_PATH, 3),
145
- inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
146
- outputs=answer,
147
- cache_examples=False
148
  )
149
- with gr.Tab("Documentation"):
150
- gr.Markdown(os.environ.get("DOCUMENTATION"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
- grady.launch(mcp_server=True)
 
 
 
1
+ import os
2
  import gradio as gr
3
+ import requests
4
+ import pandas as pd
5
+ from crew import run_crew # This is your actual multi-agent logic
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
+
9
+ # Custom wrapper to integrate your real GAIA agent logic
10
+ class CrewAgent:
11
+ def __call__(self, question: str) -> str:
12
+ return run_crew(question, file_path="") # File support is optional here
13
+
14
+ def run_and_submit_all(profile: gr.OAuthProfile | None):
15
+ space_id = os.getenv("SPACE_ID")
16
+
17
+ if profile:
18
+ username = f"{profile.username}"
19
+ print(f"User logged in: {username}")
20
+ else:
21
+ print("User not logged in.")
22
+ return "Please log in with your Hugging Face account.", None
23
+
24
+ agent = CrewAgent()
25
+ agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
26
+
27
+ # Step 1: Fetch Questions
28
+ try:
29
+ response = requests.get(f"{DEFAULT_API_URL}/questions", timeout=15)
30
+ response.raise_for_status()
31
+ questions_data = response.json()
32
+ print(f"✅ Fetched {len(questions_data)} questions.")
33
+ except Exception as e:
34
+ return f"❌ Failed to fetch questions: {e}", None
35
+
36
+ # Step 2: Run Agent
37
+ results_log = []
38
+ answers_payload = []
39
+ for item in questions_data:
40
+ task_id = item.get("task_id")
41
+ question_text = item.get("question")
42
  try:
43
+ submitted_answer = agent(question_text)
 
 
 
 
44
  except Exception as e:
45
+ submitted_answer = f"AGENT ERROR: {e}"
46
+ answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
47
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
48
+
49
+ if not answers_payload:
50
+ return "⚠️ No answers generated.", pd.DataFrame(results_log)
51
+
52
+ # Step 3: Submit
53
+ submission = {
54
+ "username": username.strip(),
55
+ "agent_code": agent_code,
56
+ "answers": answers_payload,
57
+ }
58
+
59
+ try:
60
+ response = requests.post(f"{DEFAULT_API_URL}/submit", json=submission, timeout=60)
61
+ response.raise_for_status()
62
+ result_data = response.json()
63
+ final_status = (
64
+ f"✅ Submission Successful!\n"
65
+ f"User: {result_data.get('username')}\n"
66
+ f"Score: {result_data.get('score', 'N/A')}% "
67
+ f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
68
+ f"Message: {result_data.get('message', 'No message')}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  )
70
+ return final_status, pd.DataFrame(results_log)
71
+ except Exception as e:
72
+ return f"❌ Submission failed: {e}", pd.DataFrame(results_log)
73
+
74
+ # --- Gradio UI ---
75
+ with gr.Blocks() as demo:
76
+ gr.Markdown("# GAIA Agent Evaluation and Submission")
77
+ gr.Markdown(
78
+ """
79
+ Login and submit your answers for the Hugging Face GAIA Benchmark.
80
+
81
+ **Instructions**:
82
+ - Modify your GAIA agent logic in the `crew.py` file.
83
+ - Log in with Hugging Face.
84
+ - Press **Run Evaluation & Submit** to begin.
85
+ """
86
+ )
87
+
88
+ gr.LoginButton()
89
+ run_button = gr.Button("Run Evaluation & Submit")
90
+
91
+ status_output = gr.Textbox(label="Status", lines=6, interactive=False)
92
+ results_table = gr.DataFrame(label="Submitted Answers")
93
+
94
+ run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
95
 
96
+ if __name__ == "__main__":
97
+ print("🚀 Starting Submission App...")
98
+ demo.launch(debug=True)
app_or.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, threading
2
+ import gradio as gr
3
+ from crew import run_parallel_crew
4
+ from crew import run_crew
5
+ from utils import get_questions
6
+
7
+
8
+ def ask(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name = ""):
9
+ """
10
+ Ask General AI Assistant a question to answer.
11
+ Args:
12
+ question (str): The question to answer
13
+ openai_api_key (str): OpenAI API key
14
+ gemini_api_key (str): Gemini API key
15
+ anthropic_api_key (str): Anthropic API key
16
+ file_name (str): Optional file name
17
+ Returns:
18
+ str: The answer to the question
19
+ """
20
+ if not question:
21
+ raise gr.Error("Question is required.")
22
+
23
+ if not openai_api_key:
24
+ raise gr.Error("OpenAI API Key is required.")
25
+
26
+ if not gemini_api_key:
27
+ raise gr.Error("Gemini API Key is required.")
28
+
29
+ if not anthropic_api_key:
30
+ raise gr.Error("Anthropic API Key is required.")
31
+
32
+ if file_name:
33
+ file_name = f"data/{file_name}"
34
+
35
+ lock = threading.Lock()
36
+
37
+ with lock:
38
+ answer = ""
39
+
40
+ try:
41
+ os.environ["OPENAI_API_KEY"] = openai_api_key
42
+ os.environ["GEMINI_API_KEY"] = gemini_api_key
43
+ os.environ["MODEL_API_KEY"] = anthropic_api_key
44
+
45
+ #answer = run_parallel_crew(question, file_name)
46
+ answer = run_crew(question, file_name)
47
+ except Exception as e:
48
+ raise gr.Error(e)
49
+ finally:
50
+ del os.environ["OPENAI_API_KEY"]
51
+ del os.environ["GEMINI_API_KEY"]
52
+ del os.environ["MODEL_API_KEY"]
53
+
54
+ return answer
55
+
56
+ gr.close_all()
57
+
58
+ with gr.Blocks() as grady:
59
+ gr.Markdown("## Grady - General AI Assistant")
60
+
61
+ with gr.Tab("Solution"):
62
+ gr.Markdown(os.environ.get("DESCRIPTION"))
63
+
64
+ with gr.Row():
65
+ with gr.Column(scale=3):
66
+ with gr.Row():
67
+ question = gr.Textbox(
68
+ label="Question *",
69
+ placeholder="In the 2025 Gradio Agents & MCP Hackathon, what percentage of participants submitted a solution during the last 24 hours?",
70
+ interactive=True
71
+ )
72
+ with gr.Row():
73
+ level = gr.Radio(
74
+ choices=[1, 2, 3],
75
+ label="GAIA Benchmark Level",
76
+ interactive=True,
77
+ scale=1
78
+ )
79
+ ground_truth = gr.Textbox(
80
+ label="Ground Truth",
81
+ interactive=True,
82
+ scale=1
83
+ )
84
+ file_name = gr.Textbox(
85
+ label="File Name",
86
+ interactive=True,
87
+ scale=2
88
+ )
89
+ with gr.Row():
90
+ openai_api_key = gr.Textbox(
91
+ label="OpenAI API Key *",
92
+ type="password",
93
+ placeholder="sk‑...",
94
+ interactive=True
95
+ )
96
+ gemini_api_key = gr.Textbox(
97
+ label="Gemini API Key *",
98
+ type="password",
99
+ interactive=True
100
+ )
101
+ anthropic_api_key = gr.Textbox(
102
+ label="Anthropic API Key *",
103
+ type="password",
104
+ placeholder="sk-ant-...",
105
+ interactive=True
106
+ )
107
+ with gr.Row():
108
+ clear_btn = gr.ClearButton(
109
+ components=[question, level, ground_truth, file_name]
110
+ )
111
+ submit_btn = gr.Button("Submit", variant="primary")
112
+ with gr.Column(scale=1):
113
+ answer = gr.Textbox(
114
+ label="Answer",
115
+ lines=1,
116
+ interactive=False
117
+ )
118
+
119
+ submit_btn.click(
120
+ fn=ask,
121
+ inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, file_name],
122
+ outputs=answer
123
+ )
124
+
125
+ QUESTION_FILE_PATH = "data/gaia_validation.jsonl"
126
+
127
+ gr.Examples(
128
+ label="GAIA Benchmark Level 1 Problems",
129
+ examples=get_questions(QUESTION_FILE_PATH, 1),
130
+ inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
131
+ outputs=answer,
132
+ cache_examples=False
133
+ )
134
+
135
+ gr.Examples(
136
+ label="GAIA Benchmark Level 2 Problems",
137
+ examples=get_questions(QUESTION_FILE_PATH, 2),
138
+ inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
139
+ outputs=answer,
140
+ cache_examples=False
141
+ )
142
+
143
+ gr.Examples(
144
+ label="GAIA Benchmark Level 3 Problems",
145
+ examples=get_questions(QUESTION_FILE_PATH, 3),
146
+ inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
147
+ outputs=answer,
148
+ cache_examples=False
149
+ )
150
+ with gr.Tab("Documentation"):
151
+ gr.Markdown(os.environ.get("DOCUMENTATION"))
152
+
153
+ grady.launch(mcp_server=True)
config/agents.yaml CHANGED
@@ -5,7 +5,6 @@ web_search_agent:
5
  Given a question only, search the web and answer the question: {question}
6
  backstory: >
7
  As an expert web search assistant, you search the web to answer the question.
8
-
9
  web_browser_agent:
10
  role: >
11
  Web Browser Agent
@@ -13,7 +12,6 @@ web_browser_agent:
13
  Given a question, URL, and action, load the URL and act, extract, or observe, and answer the question: {question}
14
  backstory: >
15
  As an expert browser assistant, you load the URL and act, extract, or observe to answer the question.
16
-
17
  image_analysis_agent:
18
  role: >
19
  Image Analysis Agent
@@ -21,7 +19,6 @@ image_analysis_agent:
21
  Given a question and image file, analyze the image and answer the question: {question}
22
  backstory: >
23
  As an expert image analysis assistant, you analyze the image to answer the question.
24
-
25
  audio_analysis_agent:
26
  role: >
27
  Audio Analysis Agent
@@ -29,7 +26,6 @@ audio_analysis_agent:
29
  Given a question and audio file, analyze the audio and answer the question: {question}
30
  backstory: >
31
  As an expert audio analysis assistant, you analyze the audio to answer the question.
32
-
33
  video_analysis_agent:
34
  role: >
35
  Video Analysis Agent
@@ -37,7 +33,6 @@ video_analysis_agent:
37
  Given a question and video file, analyze the video and answer the question: {question}
38
  backstory: >
39
  As an expert video analysis assistant, you analyze the video file to answer the question.
40
-
41
  youtube_analysis_agent:
42
  role: >
43
  YouTube Analysis Agent
@@ -45,7 +40,6 @@ youtube_analysis_agent:
45
  Given a question and YouTube URL, analyze the video and answer the question: {question}
46
  backstory: >
47
  As an expert YouTube analysis assistant, you analyze the video to answer the question.
48
-
49
  document_analysis_agent:
50
  role: >
51
  Document Analysis Agent
@@ -53,7 +47,6 @@ document_analysis_agent:
53
  Given a question and document file, analyze the document and answer the question: {question}
54
  backstory: >
55
  As an expert document analysis assistant, you analyze the document to answer the question.
56
-
57
  arithmetic_agent:
58
  role: >
59
  Arithmetic Agent
@@ -69,7 +62,6 @@ code_generation_agent:
69
  Given a question and JSON data, generate and execute code to answer the question: {question}
70
  backstory: >
71
  As an expert Python code generation assistant, you generate and execute code to answer the question.
72
-
73
  code_execution_agent:
74
  role: >
75
  Code Execution Agent
@@ -77,7 +69,20 @@ code_execution_agent:
77
  Given a question and Python file, execute the file to answer the question: {question}
78
  backstory: >
79
  As an expert Python code execution assistant, you execute code to answer the question.
80
-
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  manager_agent:
82
  role: >
83
  Manager Agent
 
5
  Given a question only, search the web and answer the question: {question}
6
  backstory: >
7
  As an expert web search assistant, you search the web to answer the question.
 
8
  web_browser_agent:
9
  role: >
10
  Web Browser Agent
 
12
  Given a question, URL, and action, load the URL and act, extract, or observe, and answer the question: {question}
13
  backstory: >
14
  As an expert browser assistant, you load the URL and act, extract, or observe to answer the question.
 
15
  image_analysis_agent:
16
  role: >
17
  Image Analysis Agent
 
19
  Given a question and image file, analyze the image and answer the question: {question}
20
  backstory: >
21
  As an expert image analysis assistant, you analyze the image to answer the question.
 
22
  audio_analysis_agent:
23
  role: >
24
  Audio Analysis Agent
 
26
  Given a question and audio file, analyze the audio and answer the question: {question}
27
  backstory: >
28
  As an expert audio analysis assistant, you analyze the audio to answer the question.
 
29
  video_analysis_agent:
30
  role: >
31
  Video Analysis Agent
 
33
  Given a question and video file, analyze the video and answer the question: {question}
34
  backstory: >
35
  As an expert video analysis assistant, you analyze the video file to answer the question.
 
36
  youtube_analysis_agent:
37
  role: >
38
  YouTube Analysis Agent
 
40
  Given a question and YouTube URL, analyze the video and answer the question: {question}
41
  backstory: >
42
  As an expert YouTube analysis assistant, you analyze the video to answer the question.
 
43
  document_analysis_agent:
44
  role: >
45
  Document Analysis Agent
 
47
  Given a question and document file, analyze the document and answer the question: {question}
48
  backstory: >
49
  As an expert document analysis assistant, you analyze the document to answer the question.
 
50
  arithmetic_agent:
51
  role: >
52
  Arithmetic Agent
 
62
  Given a question and JSON data, generate and execute code to answer the question: {question}
63
  backstory: >
64
  As an expert Python code generation assistant, you generate and execute code to answer the question.
 
65
  code_execution_agent:
66
  role: >
67
  Code Execution Agent
 
69
  Given a question and Python file, execute the file to answer the question: {question}
70
  backstory: >
71
  As an expert Python code execution assistant, you execute code to answer the question.
72
+ translation_agent:
73
+ role: >
74
+ A language translator agent that converts text from one language to another.
75
+ goal: >
76
+ Translate any given text into the requested target language.
77
+ backstory: >
78
+ An expert polyglot AI fluent in hundreds of languages.
79
+ summarization_agent:
80
+ role: >
81
+ A summarizer agent that condenses long text into clear and concise summaries.
82
+ goal: >
83
+ Summarize long articles, documents, or extracted content upon request.
84
+ backstory: >
85
+ A highly trained AI editor capable of identifying the core meaning of complex passages, documents, and technical content.
86
  manager_agent:
87
  role: >
88
  Manager Agent
config/tasks.yaml CHANGED
@@ -11,8 +11,9 @@ manager_task:
11
  - Arithmetic Agent requires a question and **two numbers to add, subtract, multiply, divide, or get the modulus**. In case there are more than two numbers, use the Code Generation Agent instead.
12
  - Code Generation Agent requires a question and **JSON data**.
13
  - Code Execution Agent requires a question and **Python file**.
 
 
14
  In case you cannot answer the question and there is not a good coworker, delegate to the Code Generation Agent.
15
  Question: {question}
16
  expected_output: >
17
- The answer to the question.
18
- agent: manager_agent
 
11
  - Arithmetic Agent requires a question and **two numbers to add, subtract, multiply, divide, or get the modulus**. In case there are more than two numbers, use the Code Generation Agent instead.
12
  - Code Generation Agent requires a question and **JSON data**.
13
  - Code Execution Agent requires a question and **Python file**.
14
+ - Translation Agent requires a question and **a target language** (e.g. Translate this to French: 'Hello').
15
+ - Summarization Agent requires a question and **a long text to summarize** (e.g. Summarize this: 'The history of AI began in...').
16
  In case you cannot answer the question and there is not a good coworker, delegate to the Code Generation Agent.
17
  Question: {question}
18
  expected_output: >
19
+ The answer to the question.
 
crew.py CHANGED
@@ -34,160 +34,145 @@ tracer_provider = register(
34
  project_name="gaia"
35
  )
36
 
37
- #CrewAIInstrumentor().instrument(tracer_provider=tracer_provider)
38
 
39
- @CrewBase
40
- class GAIACrew():
41
- agents: List[BaseAgent]
42
- tasks: List[Task]
 
43
 
44
- @agent
45
- def web_search_agent(self) -> Agent:
46
- return Agent(
47
- config=self.agents_config["web_search_agent"],
48
- allow_delegation=False,
49
- llm=AGENT_MODEL,
50
- max_iter=2,
51
- tools=[AITools.web_search_tool],
52
- verbose=True
53
- )
54
 
55
- @agent
56
- def web_browser_agent(self) -> Agent:
57
- return Agent(
58
- config=self.agents_config["web_browser_agent"],
59
- allow_delegation=False,
60
- llm=AGENT_MODEL,
61
- max_iter=3,
62
- tools=[AITools.web_browser_tool],
63
- verbose=True
64
- )
65
-
66
- @agent
67
- def image_analysis_agent(self) -> Agent:
68
- return Agent(
69
- config=self.agents_config["image_analysis_agent"],
70
- allow_delegation=False,
71
- llm=AGENT_MODEL,
72
- max_iter=2,
73
- tools=[AITools.image_analysis_tool],
74
- verbose=True
75
- )
76
 
77
- @agent
78
- def audio_analysis_agent(self) -> Agent:
79
- return Agent(
80
- config=self.agents_config["audio_analysis_agent"],
81
- allow_delegation=False,
82
- llm=AGENT_MODEL,
83
- max_iter=2,
84
- tools=[AITools.audio_analysis_tool],
85
- verbose=True
86
- )
87
 
88
- @agent
89
- def video_analysis_agent(self) -> Agent:
90
- return Agent(
91
- config=self.agents_config["video_analysis_agent"],
92
- allow_delegation=False,
93
- llm=AGENT_MODEL,
94
- max_iter=2,
95
- tools=[AITools.video_analysis_tool],
96
- verbose=True
97
- )
98
 
99
- @agent
100
- def youtube_analysis_agent(self) -> Agent:
101
- return Agent(
102
- config=self.agents_config["youtube_analysis_agent"],
103
- allow_delegation=False,
104
- llm=AGENT_MODEL,
105
- max_iter=2,
106
- tools=[AITools.youtube_analysis_tool],
107
- verbose=True
108
- )
 
 
 
 
 
 
109
 
110
- @agent
111
- def document_analysis_agent(self) -> Agent:
112
- return Agent(
113
- config=self.agents_config["document_analysis_agent"],
114
- allow_delegation=False,
115
- llm=AGENT_MODEL,
116
- max_iter=2,
117
- tools=[AITools.document_analysis_tool],
118
- verbose=True
119
- )
120
 
121
- @agent
122
- def arithmetic_agent(self) -> Agent:
123
- return Agent(
124
- config=self.agents_config["document_analysis_agent"],
125
- allow_delegation=False,
126
- llm=AGENT_MODEL,
127
- max_iter=2,
128
- tools=[ArithmeticTools.add, ArithmeticTools.subtract, ArithmeticTools.multiply, ArithmeticTools.divide, ArithmeticTools.modulus],
129
- verbose=True
130
- )
131
 
132
- @agent
133
- def code_generation_agent(self) -> Agent:
134
- return Agent(
135
- config=self.agents_config["code_generation_agent"],
136
- allow_delegation=False,
137
- llm=AGENT_MODEL,
138
- max_iter=3,
139
- tools=[AITools.code_generation_tool],
140
- verbose=True
141
- )
142
 
143
- @agent
144
- def code_execution_agent(self) -> Agent:
145
- return Agent(
146
- config=self.agents_config["code_execution_agent"],
147
- allow_delegation=False,
148
- llm=AGENT_MODEL,
149
- max_iter=3,
150
- tools=[AITools.code_execution_tool],
151
- verbose=True
152
- )
153
 
154
- @agent
155
- def manager_agent(self) -> Agent:
156
- return Agent(
157
- config=self.agents_config["manager_agent"],
158
- allow_delegation=True,
159
- llm=MANAGER_MODEL,
160
- max_iter=5,
161
- verbose=True
162
- )
 
 
 
 
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  @task
165
  def manager_task(self) -> Task:
166
- return Task(
167
- config=self.tasks_config["manager_task"]
168
- )
 
 
 
 
 
 
 
 
 
169
 
170
- @crew
171
- def crew(self) -> Crew:
172
  return Crew(
173
  agents=self.agents,
174
- tasks=self.tasks,
175
  verbose=True
176
  )
177
 
178
  def run_crew(question, file_path):
 
 
 
 
 
 
 
 
 
179
  final_question = question
180
-
181
  if file_path:
182
- if is_ext(file_path, ".csv") or is_ext(file_path, ".xls") or is_ext(file_path, ".xlsx") or is_ext(file_path, ".json") or is_ext(file_path, ".jsonl"):
 
 
183
  json_data = read_file_json(file_path)
184
  final_question = f"{question} JSON data:\n{json_data}."
185
  else:
186
  final_question = f"{question} File path: {file_path}."
187
-
188
- answer = GAIACrew().crew().kickoff(inputs={"question": final_question})
 
 
 
 
 
189
  final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(answer))
190
 
 
191
  print(f"=> Initial question: {question}")
192
  print(f"=> Final question: {final_question}")
193
  print(f"=> Initial answer: {answer}")
@@ -195,6 +180,66 @@ def run_crew(question, file_path):
195
 
196
  return final_answer
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  def get_final_answer(model, question, answer):
199
  prompt_template = """
200
  You are an expert question answering assistant. Given a question and an initial answer, your task is to provide the final answer.
 
34
  project_name="gaia"
35
  )
36
 
37
+ ## Tools
38
 
39
+ DOCUMENT_TOOLS = [
40
+ AITools.document_analysis_tool,
41
+ AITools.summarize_tool,
42
+ AITools.translate_tool
43
+ ]
44
 
45
+ MEDIA_TOOLS = [
46
+ AITools.image_analysis_tool,
47
+ AITools.audio_analysis_tool,
48
+ AITools.video_analysis_tool,
49
+ AITools.youtube_analysis_tool
50
+ ]
 
 
 
 
51
 
52
+ WEB_TOOLS = [
53
+ AITools.web_search_tool,
54
+ AITools.web_browser_tool
55
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
+ ARITHMETIC_TOOLS = [
58
+ ArithmeticTools.add,
59
+ ArithmeticTools.subtract,
60
+ ArithmeticTools.multiply,
61
+ ArithmeticTools.divide,
62
+ ArithmeticTools.modulus
63
+ ]
 
 
 
64
 
65
+ CODE_TOOLS = [
66
+ AITools.code_generation_tool,
67
+ AITools.code_execution_tool
68
+ ]
 
 
 
 
 
 
69
 
70
+ #Get specific tools
71
+ def get_tools_for(agent_name: str):
72
+ if "document" in agent_name or "translation" in agent_name or "summarization" in agent_name:
73
+ return DOCUMENT_TOOLS
74
+ elif any(keyword in agent_name for keyword in ["image", "audio", "video", "youtube"]):
75
+ return MEDIA_TOOLS
76
+ elif "web_search" in agent_name or "web_browser" in agent_name:
77
+ return WEB_TOOLS
78
+ elif "code_generation" in agent_name or "code_execution" in agent_name:
79
+ return CODE_TOOLS
80
+ elif "arithmetic" in agent_name:
81
+ return ARITHMETIC_TOOLS
82
+ elif "manager" in agent_name:
83
+ return []
84
+ else:
85
+ return []
86
 
 
 
 
 
 
 
 
 
 
 
87
 
88
+ #CrewAIInstrumentor().instrument(tracer_provider=tracer_provider)
 
 
 
 
 
 
 
 
 
89
 
90
+ #@CrewBase
91
+ class GAIACrew():
92
+ tasks: List[Task]
 
 
 
 
 
 
 
93
 
94
+ def __init__(self):
95
+ self.agents_config = self._load_yaml("config/agents.yaml")
96
+ self.tasks_config = self._load_yaml("config/tasks.yaml")
 
 
 
 
 
 
 
97
 
98
+ def _load_yaml(self, path):
99
+ import yaml
100
+ with open(path, "r") as f:
101
+ return yaml.safe_load(f)
102
+
103
+ @property
104
+ def agents(self) -> List[Agent]:
105
+ agents = []
106
+ for name in self.agents_config:
107
+ config = self.agents_config[name]
108
+ if config is None:
109
+ print(f"❌ Agent config for '{name}' is None!")
110
+ continue
111
 
112
+ full_config = {**config, "name": name}
113
+ print(f"✅ Creating agent: {name}")
114
+
115
+ agents.append(Agent(
116
+ config=full_config,
117
+ allow_delegation=("manager" in name),
118
+ llm=MANAGER_MODEL if "manager" in name else AGENT_MODEL,
119
+ max_iter=5 if "manager" in name else 2,
120
+ tools=get_tools_for(name),
121
+ verbose=True
122
+ ))
123
+ return agents
124
+
125
  @task
126
  def manager_task(self) -> Task:
127
+ # Build the Task object from your YAML
128
+ task = Task(config=self.tasks_config["manager_task"])
129
+
130
+ # Find the Agent instance whose YAML key is "manager_agent"
131
+ agent_list = self.agents
132
+ name_list = list(self.agents_config.keys())
133
+ for idx, name in enumerate(name_list):
134
+ if name == "manager_agent":
135
+ task.agent = agent_list[idx]
136
+ break
137
+
138
+ return task
139
 
140
+ def get_crew(self) -> Crew:
 
141
  return Crew(
142
  agents=self.agents,
143
+ tasks=[self.manager_task()],
144
  verbose=True
145
  )
146
 
147
  def run_crew(question, file_path):
148
+ """
149
+ Orchestrates the GAIA crew to answer a question, optionally with a file.
150
+ Args:
151
+ question (str): The user's question.
152
+ file_path (str): Optional path to a data file to include in the prompt.
153
+ Returns:
154
+ str: The final answer from the manager agent.
155
+ """
156
+ # Build the final prompt, including file JSON if needed
157
  final_question = question
 
158
  if file_path:
159
+ if is_ext(file_path, ".csv") or is_ext(file_path, ".xls") \
160
+ or is_ext(file_path, ".xlsx") or is_ext(file_path, ".json") \
161
+ or is_ext(file_path, ".jsonl"):
162
  json_data = read_file_json(file_path)
163
  final_question = f"{question} JSON data:\n{json_data}."
164
  else:
165
  final_question = f"{question} File path: {file_path}."
166
+
167
+ # Instantiate the crew and kick off the workflow
168
+ crew_instance = GAIACrew()
169
+ crew = crew_instance.get_crew()
170
+ answer = crew.kickoff(inputs={"question": final_question})
171
+
172
+ # Post-process through the final-answer model
173
  final_answer = get_final_answer(FINAL_ANSWER_MODEL, question, str(answer))
174
 
175
+ # Debug logging
176
  print(f"=> Initial question: {question}")
177
  print(f"=> Final question: {final_question}")
178
  print(f"=> Initial answer: {answer}")
 
180
 
181
  return final_answer
182
 
183
+ import concurrent.futures
184
+
185
+ def run_parallel_crew(question: str, file_path: str):
186
+ """
187
+ 1) Prepares the prompt (including file data if any).
188
+ 2) Runs every non-manager agent in parallel on that prompt.
189
+ 3) Gathers their raw outputs.
190
+ 4) Sends a combined prompt to the manager_agent for the final answer.
191
+ """
192
+ # 1) Build the final prompt
193
+ final_question = question
194
+ if file_path:
195
+ if is_ext(file_path, ".csv") or is_ext(file_path, ".xls") \
196
+ or is_ext(file_path, ".xlsx") or is_ext(file_path, ".json") \
197
+ or is_ext(file_path, ".jsonl"):
198
+ json_data = read_file_json(file_path)
199
+ final_question = f"{question} JSON data:\n{json_data}."
200
+ else:
201
+ final_question = f"{question} File path: {file_path}."
202
+
203
+ # 2) Instantiate your crew and split manager vs workers
204
+ crew_instance = GAIACrew()
205
+ names = list(crew_instance.agents_config.keys())
206
+ agents = crew_instance.agents
207
+ pairs = list(zip(names, agents))
208
+
209
+ workers = [(n, a) for n, a in pairs if n != "manager_agent"]
210
+ manager_name, manager = next((n, a) for n, a in pairs if n == "manager_agent")
211
+
212
+ # 3) Run workers in parallel, giving each the plain-string prompt
213
+ results = {}
214
+ with concurrent.futures.ThreadPoolExecutor(max_workers=len(workers)) as pool:
215
+ future_to_name = {
216
+ pool.submit(agent.kickoff, final_question): name
217
+ for name, agent in workers
218
+ }
219
+ for fut in concurrent.futures.as_completed(future_to_name):
220
+ name = future_to_name[fut]
221
+ try:
222
+ results[name] = fut.result()
223
+ except Exception as e:
224
+ results[name] = f"<error: {e}>"
225
+
226
+ # 4) Compose a manager prompt with all the raw outputs
227
+ combined = "\n\n".join(f"--- {n} output ---\n{out}"
228
+ for n, out in results.items())
229
+ manager_prompt = (
230
+ f"You have received these reports from your coworkers:\n\n"
231
+ f"{combined}\n\n"
232
+ f"Now, based on the original question, provide the final answer.\n"
233
+ f"Original question: {question}"
234
+ )
235
+
236
+ # 5) Run the manager agent on the combined prompt
237
+ final = manager.kickoff(manager_prompt)
238
+
239
+ # 6) Post-process via your final-answer model
240
+ return get_final_answer(FINAL_ANSWER_MODEL, question, str(final))
241
+
242
+
243
  def get_final_answer(model, question, answer):
244
  prompt_template = """
245
  You are an expert question answering assistant. Given a question and an initial answer, your task is to provide the final answer.
tools/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (125 Bytes). View file
 
tools/__pycache__/ai_tools.cpython-310.pyc ADDED
Binary file (10.9 kB). View file
 
tools/__pycache__/arithmetic_tools.cpython-310.pyc ADDED
Binary file (2.01 kB). View file
 
tools/ai_tools.py CHANGED
@@ -319,4 +319,53 @@ class AITools():
319
  if part.code_execution_result is not None:
320
  return part.code_execution_result.output
321
  except Exception as e:
322
- raise RuntimeError(f"Processing failed: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  if part.code_execution_result is not None:
320
  return part.code_execution_result.output
321
  except Exception as e:
322
+ raise RuntimeError(f"Processing failed: {str(e)}")
323
+
324
+ @tool("Translation Tool")
325
+ def translate_tool(text: str, target_lang: str) -> str:
326
+ """Translate a given text into the target language.
327
+
328
+ Args:
329
+ text (str): The text to translate.
330
+ target_lang (str): The target language (e.g., 'french', 'de', 'zh').
331
+
332
+ Returns:
333
+ str: Translated text.
334
+ """
335
+ try:
336
+ client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
337
+
338
+ prompt = f"Translate this text to {target_lang}: '{text}'"
339
+
340
+ response = client.models.generate_content(
341
+ model="gemini-2.5-flash-preview-04-17",
342
+ contents=prompt
343
+ )
344
+
345
+ return response.text
346
+ except Exception as e:
347
+ raise RuntimeError(f"Translation failed: {str(e)}")
348
+
349
+ @tool("Summarization Tool")
350
+ def summarize_tool(text: str) -> str:
351
+ """Summarize the given text input.
352
+
353
+ Args:
354
+ text (str): Long content to summarize.
355
+
356
+ Returns:
357
+ str: A concise summary.
358
+ """
359
+ try:
360
+ client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
361
+
362
+ prompt = f"Summarize this content: {text}"
363
+
364
+ response = client.models.generate_content(
365
+ model="gemini-2.5-flash-preview-04-17",
366
+ contents=prompt
367
+ )
368
+
369
+ return response.text
370
+ except Exception as e:
371
+ raise RuntimeError(f"Summarization failed: {str(e)}")