Gary Simmons commited on
Commit
5a549a8
·
1 Parent(s): 81917a3

add BasicAgent implementation and .gitignore file

Browse files
Files changed (2) hide show
  1. .gitignore +22 -0
  2. app.py +26 -3
.gitignore ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Bytecode / caches
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Virtual envs
7
+ venv/
8
+ .env/
9
+ .venv/
10
+
11
+ # Test / tooling caches
12
+ .pytest_cache/
13
+ .mypy_cache/
14
+ .coverage
15
+
16
+ # Editor / OS
17
+ .vscode/
18
+ .idea/
19
+ .DS_Store
20
+
21
+ # Environment files
22
+ .env
app.py CHANGED
@@ -3,6 +3,15 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
 
 
 
 
 
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -12,12 +21,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import (
7
+ CodeAgent,
8
+ DuckDuckGoSearchTool,
9
+ InferenceClientModel,
10
+ VisitWebpageTool,
11
+ PythonInterpreterTool,
12
+ WikipediaSearchTool,
13
+ )
14
+
15
 
16
  # (Keep Constants as is)
17
  # --- Constants ---
 
21
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
22
  class BasicAgent:
23
  def __init__(self):
24
+ self.code_agent = CodeAgent(
25
+ tools=[
26
+ DuckDuckGoSearchTool(),
27
+ VisitWebpageTool(),
28
+ PythonInterpreterTool(),
29
+ WikipediaSearchTool(),
30
+ ],
31
+ model=InferenceClientModel("Qwen/Qwen2.5-Coder-32b-instruct")
32
+ )
33
  print("BasicAgent initialized.")
34
  def __call__(self, question: str) -> str:
35
  print(f"Agent received question (first 50 chars): {question[:50]}...")
36
+ try:
37
+ response = self.code_agent({"input": question})
38
+ print(f"Agent returning response: {response}")
39
+ return response
40
+ except Exception as e:
41
+ print(f"Error in code agent: {e}")
42
+ return f"AGENT ERROR: {e}"
43
+
44
 
45
  def run_and_submit_all( profile: gr.OAuthProfile | None):
46
  """