SmokeyBandit commited on
Commit
40d3f93
·
verified ·
1 Parent(s): 2d2e5de

Update app.py

Browse files

2nd go, removed logs, time, weather and locations

Files changed (1) hide show
  1. app.py +6 -24
app.py CHANGED
@@ -1,4 +1,3 @@
1
- import logging
2
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
3
  import datetime
4
  import requests
@@ -8,10 +7,6 @@ from tools.final_answer import FinalAnswerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
- # Configure logging to capture error level logs
12
- logging.basicConfig(level=logging.ERROR)
13
- logger = logging.getLogger(__name__)
14
-
15
  @tool
16
  def get_current_time_in_timezone(timezone: str) -> str:
17
  """A tool that fetches the current local time in a specified timezone.
@@ -23,7 +18,6 @@ def get_current_time_in_timezone(timezone: str) -> str:
23
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
24
  return f"The current local time in {timezone} is: {local_time}"
25
  except Exception as e:
26
- logger.error(f"Error fetching time for timezone '{timezone}': {e}")
27
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
28
 
29
  @tool
@@ -37,7 +31,6 @@ def duckduckgo_search(query: str) -> str:
37
  results = ddg_tool.search(query)
38
  return str(results)
39
  except Exception as e:
40
- logger.error(f"Error performing DuckDuckGo search for query '{query}': {e}")
41
  return f"Error performing DuckDuckGo search: {str(e)}"
42
 
43
  @tool
@@ -52,34 +45,27 @@ def weather_search(location: str) -> str:
52
  if response.status_code == 200:
53
  return response.text
54
  else:
55
- logger.error(f"HTTP error: Unable to fetch weather data for '{location}'. HTTP Status code: {response.status_code}")
56
  return f"Error: Unable to fetch weather data. HTTP Status code: {response.status_code}"
57
  except Exception as e:
58
- logger.error(f"Error fetching weather data for location '{location}': {e}")
59
  return f"Error fetching weather data: {str(e)}"
60
 
61
  final_answer = FinalAnswerTool()
62
  model = HfApiModel(
63
  max_tokens=2096,
64
  temperature=0.5,
65
- model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B', # it is possible that this model may be overloaded
66
  custom_role_conversions=None,
67
  )
68
 
69
  # Import tool from Hub
70
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
71
 
72
- # Load prompt templates with error handling
73
- try:
74
- with open("prompts.yaml", 'r') as stream:
75
- prompt_templates = yaml.safe_load(stream)
76
- except Exception as e:
77
- logger.error(f"Error loading prompts.yaml: {e}")
78
- prompt_templates = {}
79
-
80
  agent = CodeAgent(
81
  model=model,
82
- tools=[final_answer, duckduckgo_search, weather_search, get_current_time_in_timezone],
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,
@@ -89,8 +75,4 @@ agent = CodeAgent(
89
  prompt_templates=prompt_templates
90
  )
91
 
92
- # Launch Gradio UI with error logging
93
- try:
94
- GradioUI(agent).launch()
95
- except Exception as e:
96
- logger.error(f"Error launching GradioUI: {e}")
 
 
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
 
 
 
10
  @tool
11
  def get_current_time_in_timezone(timezone: str) -> str:
12
  """A tool that fetches the current local time in a specified timezone.
 
18
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
19
  return f"The current local time in {timezone} is: {local_time}"
20
  except Exception as e:
 
21
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
22
 
23
  @tool
 
31
  results = ddg_tool.search(query)
32
  return str(results)
33
  except Exception as e:
 
34
  return f"Error performing DuckDuckGo search: {str(e)}"
35
 
36
  @tool
 
45
  if response.status_code == 200:
46
  return response.text
47
  else:
 
48
  return f"Error: Unable to fetch weather data. HTTP Status code: {response.status_code}"
49
  except Exception as e:
 
50
  return f"Error fetching weather data: {str(e)}"
51
 
52
  final_answer = FinalAnswerTool()
53
  model = HfApiModel(
54
  max_tokens=2096,
55
  temperature=0.5,
56
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
57
  custom_role_conversions=None,
58
  )
59
 
60
  # Import tool from Hub
61
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
62
 
63
+ with open("prompts.yaml", 'r') as stream:
64
+ prompt_templates = yaml.safe_load(stream)
65
+
 
 
 
 
 
66
  agent = CodeAgent(
67
  model=model,
68
+ tools=[final_answer, get_current_time_in_timezone, duckduckgo_search, weather_search],
69
  max_steps=6,
70
  verbosity_level=1,
71
  grammar=None,
 
75
  prompt_templates=prompt_templates
76
  )
77
 
78
+ GradioUI(agent).launch()