Abdenour Chaoui commited on
Commit
79533e5
·
1 Parent(s): ead3819

change done

Browse files
Files changed (2) hide show
  1. app.py +25 -10
  2. requirements.txt +10 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -10,14 +11,25 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
- class BasicAgent:
14
- def __init__(self):
15
- print("BasicAgent initialized.")
16
- def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
@@ -40,7 +52,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
  try:
43
- agent = BasicAgent()
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
@@ -76,11 +88,14 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
76
  for item in questions_data:
77
  task_id = item.get("task_id")
78
  question_text = item.get("question")
 
 
79
  if not task_id or question_text is None:
80
  print(f"Skipping item with missing task_id or question: {item}")
81
  continue
82
  try:
83
- submitted_answer = agent(question_text)
 
84
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
85
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
86
  except Exception as e:
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from agent import run_agent
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
+ class GAIAAgentWrapper:
15
+ """Wrap run_agent to match agent(question) signature."""
16
+ def __call__(self, question_data) -> str:
17
+ """
18
+ question_data: str or dict with keys:
19
+ - 'question': text
20
+ - 'file_path': optional path to attached file
21
+ """
22
+ if isinstance(question_data, str):
23
+ question_text = question_data
24
+ file_path = None
25
+ elif isinstance(question_data, dict):
26
+ question_text = question_data.get("question", "")
27
+ file_path = question_data.get("file_path")
28
+ else:
29
+ raise ValueError("Invalid input type for agent.")
30
+ return run_agent(question_text, file_path=file_path)
31
+
32
+
33
 
34
  def run_and_submit_all( profile: gr.OAuthProfile | None):
35
  """
 
52
 
53
  # 1. Instantiate Agent ( modify this part to create your agent)
54
  try:
55
+ agent = GAIAAgentWrapper()
56
  except Exception as e:
57
  print(f"Error instantiating agent: {e}")
58
  return f"Error initializing agent: {e}", None
 
88
  for item in questions_data:
89
  task_id = item.get("task_id")
90
  question_text = item.get("question")
91
+ file_path = item.get("file_name")
92
+ print(f"Question (Task {task_id}): {question_text}")
93
  if not task_id or question_text is None:
94
  print(f"Skipping item with missing task_id or question: {item}")
95
  continue
96
  try:
97
+ submitted_answer = agent({"question": question_text, "file_path": file_path})
98
+ print(f"Submitted Answer: {submitted_answer}\n{'-'*50}")
99
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
100
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
101
  except Exception as e:
requirements.txt CHANGED
@@ -1,2 +1,11 @@
 
1
  gradio
2
- requests
 
 
 
 
 
 
 
 
 
1
+ agent
2
  gradio
3
+ langchain
4
+ langchain_community
5
+ langchain_core
6
+ langchain_openai
7
+ langgraph
8
+ openai
9
+ pandas
10
+ requests
11
+ tavily