YajieXu commited on
Commit
0b2a728
·
verified ·
1 Parent(s): 523b5ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -40
app.py CHANGED
@@ -2,19 +2,16 @@ import os
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
- from smolagents import CodeAgent, DuckDuckGoSearchTool
6
- import gradio as gr
7
 
8
  # --- Constants ---
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,40 +33,10 @@ 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.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:
@@ -153,4 +120,4 @@ with gr.Blocks() as demo:
153
 
154
  if __name__ == "__main__":
155
  print("Launching GAIA agent app...")
156
- demo.launch(debug=True, share=False)
 
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
+ from transformers import pipeline
 
6
 
7
  # --- Constants ---
8
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
9
 
10
  # --- Enhanced Agent Definition ---
 
11
  class GAIAAgent:
12
  def __init__(self):
13
  print("GAIAAgent initialized.")
14
+ self.model = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
 
15
 
16
  def format_prompt(self, question: str, file_content: str = None) -> str:
17
  prompt = (
 
33
  def __call__(self, question: str, file_name: str = None) -> str:
34
  file_content = self.read_file(file_name) if file_name else None
35
  prompt = self.format_prompt(question, file_content)
36
+ result = self.model(prompt, max_new_tokens=100)[0]["generated_text"]
37
+ return result.strip().split("Answer:")[-1].strip()
38
+
39
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  def run_and_submit_all(profile: gr.OAuthProfile | None):
41
  space_id = os.getenv("SPACE_ID")
42
  if profile:
 
120
 
121
  if __name__ == "__main__":
122
  print("Launching GAIA agent app...")
123
+ demo.launch(debug=True, share=False)