at1300 commited on
Commit
ea8729e
·
verified ·
1 Parent(s): 9d6e8ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -15,7 +15,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
  # --- Agent Definition ---
16
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
17
  class CoderAgent:
18
- """Coder agent that is running the Qwen2.5 coder model and can generate and execute python code. It can import the pandas library for """
19
  def __init__(self):
20
  model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
21
 
@@ -40,6 +40,7 @@ class CoderAgent:
40
  "numpy",
41
  ],
42
  )
 
43
 
44
  def __call__(self, prompt: str) -> str:
45
  agent_answer = self.coder_agent.run(prompt)
@@ -96,11 +97,19 @@ class MasterAgent:
96
  def __call__(self, question: str, attached_file: str) -> str:
97
  """"""
98
  print(f"Agent received question (first 50 chars): {question[:50]}...")
99
- #TODO Handle the file, some will need to be accessed locally, some can just be passed as public URLs
100
- agent_answer = self.master_agent.run(question)
 
 
 
 
 
 
 
101
  print(f"Agent answer: {agent_answer}")
102
  return agent_answer
103
 
 
104
  def run_and_submit_all( profile: gr.OAuthProfile | None):
105
  """
106
  Fetches all questions, runs the MasterAgent on them, submits all answers,
@@ -169,7 +178,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
169
  local_file_path = os.path.join(cache_dir, attached_file)
170
  if not os.path.exists(local_file_path):
171
  file_name_no_ext = os.path.splitext(attached_file)[0] # e.g., 'document' from 'document.pdf'
172
- download_url = f"{questions_url}/files/{file_name_no_ext}"
173
 
174
  try:
175
  print(f"Downloading from {download_url}")
@@ -196,7 +205,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
196
  print(f"Skipping item with missing task_id or question: {item}")
197
  continue
198
  try:
199
- submitted_answer = agent(question_text)
200
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
201
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
202
  except Exception as e:
 
15
  # --- Agent Definition ---
16
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
17
  class CoderAgent:
18
+ """Coder agent that is running the Qwen2.5 coder model and can generate and execute python code. It can import the pandas library for data analysis and manipulation."""
19
  def __init__(self):
20
  model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
21
 
 
40
  "numpy",
41
  ],
42
  )
43
+ print("ManagedAgent CoderAgent initialized.")
44
 
45
  def __call__(self, prompt: str) -> str:
46
  agent_answer = self.coder_agent.run(prompt)
 
97
  def __call__(self, question: str, attached_file: str) -> str:
98
  """"""
99
  print(f"Agent received question (first 50 chars): {question[:50]}...")
100
+
101
+ additional_args = {}
102
+ if attached_file:
103
+ additional_args = {
104
+ "attached_file" = attached_file
105
+ }
106
+ question = question + f" The file in attached_file can be accessed locally at this path 'file_cache/{attached_file}' or as a public URL at f{DEFAULT_API_URL}/files/f{os.path.splitext(attached_file)[0]}"
107
+
108
+ agent_answer = self.master_agent.run(question, additional_args: additional_args)
109
  print(f"Agent answer: {agent_answer}")
110
  return agent_answer
111
 
112
+
113
  def run_and_submit_all( profile: gr.OAuthProfile | None):
114
  """
115
  Fetches all questions, runs the MasterAgent on them, submits all answers,
 
178
  local_file_path = os.path.join(cache_dir, attached_file)
179
  if not os.path.exists(local_file_path):
180
  file_name_no_ext = os.path.splitext(attached_file)[0] # e.g., 'document' from 'document.pdf'
181
+ download_url = f"{api_url}/files/{file_name_no_ext}"
182
 
183
  try:
184
  print(f"Downloading from {download_url}")
 
205
  print(f"Skipping item with missing task_id or question: {item}")
206
  continue
207
  try:
208
+ submitted_answer = agent(question_text, attached_file)
209
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
210
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
211
  except Exception as e: