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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -9,18 +9,27 @@ 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
- 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,14 +39,22 @@ def get_current_time_in_timezone(timezone: str) -> str:
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,7 +65,7 @@ final_answer = FinalAnswerTool()
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,7 +79,7 @@ model = LiteLLMModel(
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,8 +95,12 @@ agent = CodeAgent(
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()
 
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 main as submit_answers # Make sure this exists and does NOT import from app.py
13
+
14
 
15
  # === TOOLS ===
16
 
17
  @tool
18
  def web_search(query: str) -> str:
19
+ """Allows search through DuckDuckGo.
20
+ Args:
21
+ query: what you want to search
22
+ """
23
  search_tool = DuckDuckGoSearchTool()
24
  results = search_tool(query)
25
  return "\n".join(results)
26
 
27
  @tool
28
  def get_current_time_in_timezone(timezone: str) -> str:
29
+ """Fetches the current local time in a specified timezone.
30
+ Args:
31
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
32
+ """
33
  try:
34
  tz = pytz.timezone(timezone)
35
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
 
39
 
40
  @tool
41
  def visit_webpage(url: str) -> str:
42
+ """Fetches raw HTML content of a web page.
43
+ Args:
44
+ url: The url of the webpage.
45
+ """
46
  try:
47
  response = requests.get(url, timeout=5)
48
+ return response.text[:5000] # Limit length
49
  except Exception as e:
50
  return f"[ERROR fetching {url}]: {str(e)}"
51
 
52
  @tool
53
  def text_splitter(text: str) -> List[str]:
54
+ """Splits text into chunks using LangChain's CharacterTextSplitter.
55
+ Args:
56
+ text: A string of text to split.
57
+ """
58
  splitter = CharacterTextSplitter(chunk_size=450, chunk_overlap=10)
59
  return splitter.split_text(text)
60
 
 
65
  with open("prompts.yaml", "r") as stream:
66
  prompt_templates = yaml.safe_load(stream)
67
 
68
+ # === LOAD agent.json CONFIG ===
69
  with open("agent.json", "r") as f:
70
  agent_config = yaml.safe_load(f)
71
 
 
79
  max_tokens=1024,
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
  ],
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 WITH SUBMIT FUNCTION ===
106
  GradioUI(agent, file_upload_folder="downloads", submit_fn=lambda: submit_answers(agent)).launch()