jk2k
commited on
Commit
·
699d6bd
1
Parent(s):
81917a3
initial commit
Browse files- app.py +25 -0
- requirements.txt +6 -1
app.py
CHANGED
@@ -2,7 +2,9 @@ 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 ---
|
@@ -11,10 +13,31 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
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
|
@@ -74,6 +97,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
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")
|
78 |
question_text = item.get("question")
|
79 |
if not task_id or question_text is None:
|
@@ -91,6 +115,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
91 |
print("Agent did not produce any answers to submit.")
|
92 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
93 |
|
|
|
94 |
# 4. Prepare Submission
|
95 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
96 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import inspect
|
5 |
+
import time
|
6 |
import pandas as pd
|
7 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
|
|
13 |
# --- Basic Agent Definition ---
|
14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
class BasicAgent:
|
16 |
+
agent: CodeAgent
|
17 |
+
|
18 |
def __init__(self):
|
19 |
print("BasicAgent initialized.")
|
20 |
+
# Instantiate the agent
|
21 |
+
# Initialize the search tool
|
22 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
23 |
+
search_tool = DuckDuckGoSearchTool()
|
24 |
+
model = LiteLLMModel(
|
25 |
+
model_id="gemini/gemini-2.5-pro-preview-05-06", # Or try other Ollama-supported models
|
26 |
+
api_Key=api_key,
|
27 |
+
num_ctx=8192,
|
28 |
+
)
|
29 |
+
self.agent = CodeAgent(
|
30 |
+
tools=[search_tool],
|
31 |
+
model=model,
|
32 |
+
max_steps=20,
|
33 |
+
verbosity_level=2
|
34 |
+
)
|
35 |
def __call__(self, question: str) -> str:
|
36 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
37 |
+
response = self.agent.run("""
|
38 |
+
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
39 |
+
""" + question)
|
40 |
+
print(response)
|
41 |
fixed_answer = "This is a default answer."
|
42 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
43 |
return fixed_answer
|
|
|
97 |
answers_payload = []
|
98 |
print(f"Running agent on {len(questions_data)} questions...")
|
99 |
for item in questions_data:
|
100 |
+
time.sleep(3)
|
101 |
task_id = item.get("task_id")
|
102 |
question_text = item.get("question")
|
103 |
if not task_id or question_text is None:
|
|
|
115 |
print("Agent did not produce any answers to submit.")
|
116 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
117 |
|
118 |
+
return "ok"
|
119 |
# 4. Prepare Submission
|
120 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
121 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
requirements.txt
CHANGED
@@ -1,2 +1,7 @@
|
|
1 |
gradio
|
2 |
-
requests
|
|
|
|
|
|
|
|
|
|
|
|
1 |
gradio
|
2 |
+
requests
|
3 |
+
smolagents
|
4 |
+
smolagents[litellm]
|
5 |
+
smolagents[vision]
|
6 |
+
gradio[oauth]
|
7 |
+
itsdangerous
|