Qscar KIM commited on
Commit
dda8828
ยท
1 Parent(s): 3543516

update codes

Browse files
Files changed (1) hide show
  1. app.py +2 -11
app.py CHANGED
@@ -5,15 +5,12 @@ import inspect
5
  import pandas as pd
6
  import time
7
 
8
- # ๐ŸŒŸ Hugging Face ๋ฌด๋ฃŒ ์˜คํ”ˆ์†Œ์Šค ๋ชจ๋ธ๊ณผ ์ฝ”๋”ฉ ์—์ด์ „ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ปดํฌ๋„ŒํŠธ ์ž„ํฌํŠธ
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
- # ๐ŸŒŸ ์™ธ๋ถ€ ์œ ๋ฃŒ Key ์—†์ด, ์ˆ˜๊ฐ•์ƒ์ด ๋กœ๊ทธ์ธํ•œ ํ† ํฐ์„ ์‚ฌ์šฉํ•ด ๋ฌด๋ฃŒ๋กœ ์ตœ๊ณ  ์„ฑ๋Šฅ์˜ ์˜คํ”ˆ์†Œ์Šค ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
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}")