ammr commited on
Commit
9af6c67
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -19,6 +20,28 @@ class BasicAgent:
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
  """
24
  Fetches all questions, runs the BasicAgent on them, submits all answers,
@@ -40,7 +63,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
 
4
  import inspect
5
  import pandas as pd
6
 
7
+
8
  # (Keep Constants as is)
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
20
  print(f"Agent returning fixed answer: {fixed_answer}")
21
  return fixed_answer
22
 
23
+
24
+ class myAgent:
25
+ def __init__(self):
26
+ print("myAgent initialized.")
27
+ llm = HuggingFaceEndpoint(
28
+ repo_id="Qwen/Qwen2.5-Coder-32B-Instruct",
29
+ huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
30
+ )
31
+
32
+ self.agent = CodeAgent(
33
+ model=llm,
34
+ tools=[DuckDuckGoSearchTool()]#, WikipediaSearchTool(), SpeechToTextTool(), ExcelToTextTool()],
35
+ add_base_tools=True,
36
+ additional_authorized_imports=['pandas','numpy','csv']
37
+ )
38
+
39
+ def __call__(self, question: str) -> str:
40
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
41
+ fixed_answer = self.agent.run(question)
42
+ print(f"Agent returning fixed answer: {fixed_answer}")
43
+ return fixed_answer
44
+
45
  def run_and_submit_all( profile: gr.OAuthProfile | None):
46
  """
47
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
63
 
64
  # 1. Instantiate Agent ( modify this part to create your agent)
65
  try:
66
+ agent = myAgent()
67
  except Exception as e:
68
  print(f"Error instantiating agent: {e}")
69
  return f"Error initializing agent: {e}", None