Spaces:
Sleeping
Sleeping
Qscar KIM commited on
Commit ยท
dda8828
1
Parent(s): 3543516
update codes
Browse files
app.py
CHANGED
|
@@ -5,15 +5,12 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
import time
|
| 7 |
|
| 8 |
-
|
| 9 |
-
from smolagents import CodeAgent, HfApiModel, Tool
|
| 10 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 11 |
|
| 12 |
-
# (Keep Constants as is)
|
| 13 |
# --- Constants ---
|
| 14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 15 |
|
| 16 |
-
# ๐ ์์ด์ ํธ๊ฐ ๋ชจ๋ฅด๋ ์ง์์ ๊ตฌ๊ธ/๋ค์ด๋ฒ์ฒ๋ผ ์น์์ ๊ฒ์ํ ๋ ์ฌ์ฉํ ๋๊ตฌ ๊ฐ๋ฐฉ
|
| 17 |
class WebSearchTool(Tool):
|
| 18 |
name = "web_search"
|
| 19 |
description = "Use this tool to search the internet for up-to-date facts, data, or general information."
|
|
@@ -34,14 +31,12 @@ class WebSearchTool(Tool):
|
|
| 34 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 35 |
class BasicAgent:
|
| 36 |
def __init__(self):
|
| 37 |
-
|
| 38 |
-
self.model = HfApiModel(
|
| 39 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 40 |
)
|
| 41 |
|
| 42 |
search_tool = WebSearchTool()
|
| 43 |
|
| 44 |
-
# ๐ ์ง๋ฌธ์ ๋ฐ์ผ๋ฉด ํ์ด์ฌ ์ฝ๋๋ฅผ ์ง์ ์ค์ค๋ก ๊ณ์ฐํ๊ณ ๊ฒ์ฆํ๋ ์์จ ์์ด์ ํธ(CodeAgent)๋ฅผ ์กฐ๋ฆฝํฉ๋๋ค.
|
| 45 |
self.real_agent = CodeAgent(
|
| 46 |
tools=[search_tool],
|
| 47 |
model=self.model,
|
|
@@ -53,16 +48,13 @@ class BasicAgent:
|
|
| 53 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 54 |
|
| 55 |
try:
|
| 56 |
-
# GAIA ๋ฐ์ดํฐ์
์ฑ์ ๊ธฐ์ค์ ๋ง์ถ๊ธฐ ์ํด ์ต์ข
๋ต๋ณ ํ์๋ง ์กฐ๊ธ ๋ ๊ฐ์กฐํด ์ค๋๋ค.
|
| 57 |
refined_prompt = (
|
| 58 |
f"{question}\n\n"
|
| 59 |
f"Provide the final answer as briefly as possible at the very end. "
|
| 60 |
f"No explanations in the last line."
|
| 61 |
)
|
| 62 |
|
| 63 |
-
# ์์ด์ ํธ๋ฅผ ๊ตฌ๋ํ์ฌ ์์จ ์ถ๋ก ์ ์์ํฉ๋๋ค.
|
| 64 |
result = self.real_agent.run(refined_prompt)
|
| 65 |
-
|
| 66 |
final_answer = str(result).strip()
|
| 67 |
print(f"Agent returning answer: {final_answer}")
|
| 68 |
return final_answer
|
|
@@ -136,7 +128,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 136 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 137 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 138 |
|
| 139 |
-
# ๋ฌด๋ฃ ํธ์คํ
์๋ฒ์ ๊ณผ๋ํ ๋ถ๋ด์ ์ฃผ๋ ๊ฒ์ ๋ง๊ธฐ ์ํด ๋ฌธ์ ์ฌ์ด์ ๋๊ธฐ ์๊ฐ์ ๋ก๋๋ค.
|
| 140 |
time.sleep(2)
|
| 141 |
except Exception as e:
|
| 142 |
print(f"Error running agent on task {task_id}: {e}")
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import time
|
| 7 |
|
| 8 |
+
from smolagents import CodeAgent, ApiModel, Tool
|
|
|
|
| 9 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 10 |
|
|
|
|
| 11 |
# --- Constants ---
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
|
|
|
|
| 14 |
class WebSearchTool(Tool):
|
| 15 |
name = "web_search"
|
| 16 |
description = "Use this tool to search the internet for up-to-date facts, data, or general information."
|
|
|
|
| 31 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 32 |
class BasicAgent:
|
| 33 |
def __init__(self):
|
| 34 |
+
self.model = ApiModel(
|
|
|
|
| 35 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 36 |
)
|
| 37 |
|
| 38 |
search_tool = WebSearchTool()
|
| 39 |
|
|
|
|
| 40 |
self.real_agent = CodeAgent(
|
| 41 |
tools=[search_tool],
|
| 42 |
model=self.model,
|
|
|
|
| 48 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 49 |
|
| 50 |
try:
|
|
|
|
| 51 |
refined_prompt = (
|
| 52 |
f"{question}\n\n"
|
| 53 |
f"Provide the final answer as briefly as possible at the very end. "
|
| 54 |
f"No explanations in the last line."
|
| 55 |
)
|
| 56 |
|
|
|
|
| 57 |
result = self.real_agent.run(refined_prompt)
|
|
|
|
| 58 |
final_answer = str(result).strip()
|
| 59 |
print(f"Agent returning answer: {final_answer}")
|
| 60 |
return final_answer
|
|
|
|
| 128 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 129 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 130 |
|
|
|
|
| 131 |
time.sleep(2)
|
| 132 |
except Exception as e:
|
| 133 |
print(f"Error running agent on task {task_id}: {e}")
|