AlexanderKazakov
commited on
Commit
·
ae3d12b
1
Parent(s):
81917a3
basic smolagents
Browse files- .gitignore +1 -0
- app.py +32 -6
- requirements.txt +3 -1
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/.idea
|
app.py
CHANGED
@@ -1,18 +1,41 @@
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
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"
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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."
|
@@ -21,7 +44,7 @@ class BasicAgent:
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
24 |
-
Fetches all questions, runs the
|
25 |
and displays the results.
|
26 |
"""
|
27 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
@@ -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 =
|
44 |
except Exception as e:
|
45 |
print(f"Error instantiating agent: {e}")
|
46 |
return f"Error initializing agent: {e}", None
|
@@ -72,6 +95,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
72 |
# 3. Run your Agent
|
73 |
results_log = []
|
74 |
answers_payload = []
|
|
|
|
|
|
|
75 |
print(f"Running agent on {len(questions_data)} questions...")
|
76 |
for item in questions_data:
|
77 |
task_id = item.get("task_id")
|
|
|
1 |
+
import json
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
import inspect
|
6 |
import pandas as pd
|
7 |
+
from smolagents import CodeAgent, HfApiModel, FinalAnswerTool, DuckDuckGoSearchTool, VisitWebpageTool
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
12 |
|
13 |
+
|
14 |
+
class SmolAgent:
|
|
|
15 |
def __init__(self):
|
16 |
+
final_answer = FinalAnswerTool()
|
17 |
+
search_tool = DuckDuckGoSearchTool()
|
18 |
+
visit_webpage_tool = VisitWebpageTool()
|
19 |
+
model = HfApiModel(
|
20 |
+
max_tokens=2096,
|
21 |
+
temperature=0.01,
|
22 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
23 |
+
custom_role_conversions=None,
|
24 |
+
token=open("data/keys/hf.key").read()
|
25 |
+
)
|
26 |
+
agent = CodeAgent(
|
27 |
+
model=model,
|
28 |
+
tools=[search_tool, visit_webpage_tool, final_answer],
|
29 |
+
max_steps=3,
|
30 |
+
verbosity_level=100,
|
31 |
+
grammar=None,
|
32 |
+
planning_interval=None,
|
33 |
+
name=None,
|
34 |
+
description=None,
|
35 |
+
)
|
36 |
+
print(f'--- agent.visualize(): ---')
|
37 |
+
agent.visualize()
|
38 |
+
|
39 |
def __call__(self, question: str) -> str:
|
40 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
41 |
fixed_answer = "This is a default answer."
|
|
|
44 |
|
45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
46 |
"""
|
47 |
+
Fetches all questions, runs the SmolAgent on them, submits all answers,
|
48 |
and displays the results.
|
49 |
"""
|
50 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
|
|
63 |
|
64 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
65 |
try:
|
66 |
+
agent = SmolAgent()
|
67 |
except Exception as e:
|
68 |
print(f"Error instantiating agent: {e}")
|
69 |
return f"Error initializing agent: {e}", None
|
|
|
95 |
# 3. Run your Agent
|
96 |
results_log = []
|
97 |
answers_payload = []
|
98 |
+
print('#@#')
|
99 |
+
print(json.dumps(questions_data))
|
100 |
+
print('#@#')
|
101 |
print(f"Running agent on {len(questions_data)} questions...")
|
102 |
for item in questions_data:
|
103 |
task_id = item.get("task_id")
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
gradio
|
2 |
-
requests
|
|
|
|
|
|
1 |
gradio
|
2 |
+
requests
|
3 |
+
smolagents
|
4 |
+
pandas
|