YajieXu commited on
Commit
523b5ec
·
verified ·
1 Parent(s): 8fb3e41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -9,12 +9,12 @@ import gradio as gr
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Enhanced Agent Definition ---
 
12
  class GAIAAgent:
13
  def __init__(self):
14
  print("GAIAAgent initialized.")
15
  self.model = gr.load("models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B", provider="novita")
16
- search_tool = DuckDuckGoSearchTool()
17
- self.agent = CodeAgent(model=model, tools=[search_tool])
18
 
19
  def format_prompt(self, question: str, file_content: str = None) -> str:
20
  prompt = (
@@ -36,10 +36,40 @@ class GAIAAgent:
36
  def __call__(self, question: str, file_name: str = None) -> str:
37
  file_content = self.read_file(file_name) if file_name else None
38
  prompt = self.format_prompt(question, file_content)
39
- result = self.agent.run(prompt)
40
  return result.strip()
41
-
42
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  def run_and_submit_all(profile: gr.OAuthProfile | None):
44
  space_id = os.getenv("SPACE_ID")
45
  if profile:
 
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Enhanced Agent Definition ---
12
+
13
  class GAIAAgent:
14
  def __init__(self):
15
  print("GAIAAgent initialized.")
16
  self.model = gr.load("models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B", provider="novita")
17
+ self.search_tool = DuckDuckGoSearchTool() # optional if you still want to use search manually
 
18
 
19
  def format_prompt(self, question: str, file_content: str = None) -> str:
20
  prompt = (
 
36
  def __call__(self, question: str, file_name: str = None) -> str:
37
  file_content = self.read_file(file_name) if file_name else None
38
  prompt = self.format_prompt(question, file_content)
39
+ result = self.model(prompt) # directly call the Gradio-loaded model
40
  return result.strip()
41
+
42
+ # class GAIAAgent:
43
+ # def __init__(self):
44
+ # print("GAIAAgent initialized.")
45
+ # self.model = gr.load("models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B", provider="novita")
46
+ # search_tool = DuckDuckGoSearchTool()
47
+ # self.agent = CodeAgent(model=model, tools=[search_tool])
48
+
49
+ # def format_prompt(self, question: str, file_content: str = None) -> str:
50
+ # prompt = (
51
+ # "You are a helpful AI agent solving a question from the GAIA benchmark. "
52
+ # "Respond only with the final answer."
53
+ # )
54
+ # if file_content:
55
+ # prompt += f"\nAttached File Content:\n{file_content}\n"
56
+ # prompt += f"\nQuestion: {question}\nAnswer:"
57
+ # return prompt
58
+
59
+ # def read_file(self, filename: str) -> str:
60
+ # filepath = os.path.join("./", filename)
61
+ # if filename.endswith(".txt") and os.path.exists(filepath):
62
+ # with open(filepath, "r") as file:
63
+ # return file.read()[:1000] # limit to 1000 chars
64
+ # return ""
65
+
66
+ # def __call__(self, question: str, file_name: str = None) -> str:
67
+ # file_content = self.read_file(file_name) if file_name else None
68
+ # prompt = self.format_prompt(question, file_content)
69
+ # result = self.agent.run(prompt)
70
+ # return result.strip()
71
+
72
+
73
  def run_and_submit_all(profile: gr.OAuthProfile | None):
74
  space_id = os.getenv("SPACE_ID")
75
  if profile: