AIVAHr-project commited on
Commit
5398dda
·
verified ·
1 Parent(s): a9e2f9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -8,24 +8,49 @@ import pandas as pd
8
  # --- Constants ---
9
  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
  """
24
  Fetches all questions, runs the BasicAgent on them, submits all answers,
25
  and displays the results.
26
  """
27
  # --- Determine HF Space Runtime URL and Repo URL ---
28
- space_id = os.getenv("OppaAI") # Get the SPACE_ID for sending link to the code
29
 
30
  if profile:
31
  username= f"{profile.username}"
 
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
+ # 🛠️ Custom tool
12
+ @tool
13
+ def get_hugging_face_top_daily_paper() -> str:
14
+ try:
15
+ url = "https://huggingface.co/papers"
16
+ response = requests.get(url)
17
+ response.raise_for_status()
18
+ soup = BeautifulSoup(response.content, "html.parser")
19
+ containers = soup.find_all('div', attrs={'data-props': True})
20
+ for container in containers:
21
+ try:
22
+ json_data = json.loads(container.get('data-props', '').replace('"', '"'))
23
+ if 'dailyPapers' in json_data:
24
+ return json_data['dailyPapers'][0]['title']
25
+ except json.JSONDecodeError:
26
+ continue
27
+ return "No top paper found."
28
+ except requests.exceptions.RequestException as e:
29
+ return f"Error: {e}"
30
+
31
  # --- Basic Agent Definition ---
32
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
33
  class BasicAgent:
34
  def __init__(self):
35
+ HF_TOKEN = os.getenv("HF_API_KEY")
36
+ model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct", api_key=HF_TOKEN)
37
+ search_tool = DuckDuckGoSearchTool()
38
+ self.agent = CodeAgent(
39
+ tools=[search_tool, get_hugging_face_top_daily_paper],
40
+ model=model,
41
+ additional_authorized_imports=["requests", "bs4", "json"]
42
+ )
43
 
44
+ def run(self, input_text):
45
+ return self.agent.run(input_text)
46
+
47
  def run_and_submit_all( profile: gr.OAuthProfile | None):
48
  """
49
  Fetches all questions, runs the BasicAgent on them, submits all answers,
50
  and displays the results.
51
  """
52
  # --- Determine HF Space Runtime URL and Repo URL ---
53
+ space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
54
 
55
  if profile:
56
  username= f"{profile.username}"