jcleee commited on
Commit
8fb774d
·
verified ·
1 Parent(s): bb4d2ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -32
app.py CHANGED
@@ -9,25 +9,18 @@ from langchain.text_splitter import CharacterTextSplitter
9
  from tools.final_answer import FinalAnswerTool
10
  from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
11
  from Gradio_UI import GradioUI
 
12
 
13
  # === TOOLS ===
14
 
15
  @tool
16
  def web_search(query: str) -> str:
17
- """Allows search through DuckDuckGo.
18
- Args:
19
- query: what you want to search
20
- """
21
  search_tool = DuckDuckGoSearchTool()
22
  results = search_tool(query)
23
  return "\n".join(results)
24
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
27
- """Fetches the current local time in a specified timezone.
28
- Args:
29
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
30
- """
31
  try:
32
  tz = pytz.timezone(timezone)
33
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
@@ -37,22 +30,14 @@ def get_current_time_in_timezone(timezone: str) -> str:
37
 
38
  @tool
39
  def visit_webpage(url: str) -> str:
40
- """Fetches raw HTML content of a web page.
41
- Args:
42
- url: The url of the webpage.
43
- """
44
  try:
45
  response = requests.get(url, timeout=5)
46
- return response.text[:5000] # Limit length
47
  except Exception as e:
48
  return f"[ERROR fetching {url}]: {str(e)}"
49
 
50
  @tool
51
  def text_splitter(text: str) -> List[str]:
52
- """Splits text into chunks using LangChain's CharacterTextSplitter.
53
- Args:
54
- text: A string of text to split.
55
- """
56
  splitter = CharacterTextSplitter(chunk_size=450, chunk_overlap=10)
57
  return splitter.split_text(text)
58
 
@@ -63,7 +48,7 @@ final_answer = FinalAnswerTool()
63
  with open("prompts.yaml", "r") as stream:
64
  prompt_templates = yaml.safe_load(stream)
65
 
66
- # === LOAD agent.json CONFIG ===
67
  with open("agent.json", "r") as f:
68
  agent_config = yaml.safe_load(f)
69
 
@@ -77,9 +62,7 @@ model = LiteLLMModel(
77
  max_tokens=1024,
78
  )
79
 
80
-
81
-
82
- # === IMPORT TOOL FROM HUB ===
83
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
84
 
85
  # === BUILD AGENT ===
@@ -95,17 +78,8 @@ agent = CodeAgent(
95
  ],
96
  max_steps=6,
97
  verbosity_level=1,
98
- grammar=None,
99
- planning_interval=None,
100
- name=None,
101
- description=None,
102
  prompt_templates=prompt_templates
103
  )
104
 
105
- # === LAUNCH UI ===
106
- # GradioUI(agent).launch() # This was the original one we replaced
107
-
108
- from submit import submit_answers
109
-
110
- GradioUI(agent, file_upload_folder="downloads").launch(submit_fn=lambda: submit_answers(agent))
111
-
 
9
  from tools.final_answer import FinalAnswerTool
10
  from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
11
  from Gradio_UI import GradioUI
12
+ from submit import submit_answers # <- no circular import since submit.py doesn't import this file
13
 
14
  # === TOOLS ===
15
 
16
  @tool
17
  def web_search(query: str) -> str:
 
 
 
 
18
  search_tool = DuckDuckGoSearchTool()
19
  results = search_tool(query)
20
  return "\n".join(results)
21
 
22
  @tool
23
  def get_current_time_in_timezone(timezone: str) -> str:
 
 
 
 
24
  try:
25
  tz = pytz.timezone(timezone)
26
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
 
30
 
31
  @tool
32
  def visit_webpage(url: str) -> str:
 
 
 
 
33
  try:
34
  response = requests.get(url, timeout=5)
35
+ return response.text[:5000]
36
  except Exception as e:
37
  return f"[ERROR fetching {url}]: {str(e)}"
38
 
39
  @tool
40
  def text_splitter(text: str) -> List[str]:
 
 
 
 
41
  splitter = CharacterTextSplitter(chunk_size=450, chunk_overlap=10)
42
  return splitter.split_text(text)
43
 
 
48
  with open("prompts.yaml", "r") as stream:
49
  prompt_templates = yaml.safe_load(stream)
50
 
51
+ # === LOAD AGENT CONFIG ===
52
  with open("agent.json", "r") as f:
53
  agent_config = yaml.safe_load(f)
54
 
 
62
  max_tokens=1024,
63
  )
64
 
65
+ # === LOAD ADDITIONAL TOOLS ===
 
 
66
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
67
 
68
  # === BUILD AGENT ===
 
78
  ],
79
  max_steps=6,
80
  verbosity_level=1,
 
 
 
 
81
  prompt_templates=prompt_templates
82
  )
83
 
84
+ # === LAUNCH GRADIO WITH SUBMIT SUPPORT ===
85
+ GradioUI(agent, file_upload_folder="downloads", submit_fn=lambda: submit_answers(agent)).launch()