kuzumab commited on
Commit
45512c4
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -5
app.py CHANGED
@@ -3,21 +3,55 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
-
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
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
 
 
 
 
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, VisitWebpageTool
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
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
21
  class BasicAgent:
22
  def __init__(self):
23
+
24
+ self.model = OpenAIServerModel(
25
+ model_id="Qwen/Qwen2.5-VL-32B-Instruct",
26
+ api_base="https://api.siliconflow.cn/v1/",
27
+ api_key=os.getenv('MODEL_TOKEN'),
28
+ )
29
+
30
+ self.tools = [DuckDuckGoSearchTool(), VisitWebpageTool()]
31
+
32
+ self.agent = CodeAgent(
33
+ tools=self.tools,
34
+ model=self.model,
35
+ max_steps=20
36
+ )
37
  print("BasicAgent initialized.")
38
+
39
+ def __call__(self, question: str, images=None) -> str:
40
+
41
  print(f"Agent received question (first 50 chars): {question[:50]}...")
42
+
43
+ try:
44
+ if images is not None:
45
+ result = self.agent.run(question, images=images)
46
+ else:
47
+ result = self.agent.run(question)
48
+
49
+ print(f"Agent returning answer: {result}")
50
+ return result
51
+ except Exception as e:
52
+ print(f"Agent error: {e}")
53
+ return f"AGENT ERROR: {e}"
54
+
55
 
56
  def run_and_submit_all( profile: gr.OAuthProfile | None):
57
  """