TierraX commited on
Commit
7132fdb
·
verified ·
1 Parent(s): 5ad4888

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -23
app.py CHANGED
@@ -1,18 +1,59 @@
 
 
 
 
1
  import yaml
2
- import os
3
- from smolagents import GradioUI, CodeAgent, HfApiModel
4
 
5
- # Get current directory path
6
- CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
7
 
8
- from tools.web_search import DuckDuckGoSearchTool as WebSearch
9
- from tools.visit_webpage import VisitWebpageTool as VisitWebpage
10
- from tools.suggest_menu import SimpleTool as SuggestMenu
11
- from tools.catering_service_tool import SimpleTool as CateringServiceTool
12
- from tools.superhero_party_theme_generator import SuperheroPartyThemeTool as SuperheroPartyThemeGenerator
13
- from tools.final_answer import FinalAnswerTool as FinalAnswer
14
 
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  model = HfApiModel(
18
  max_tokens=2096,
@@ -21,27 +62,22 @@ model = HfApiModel(
21
  custom_role_conversions=None,
22
  )
23
 
24
- web_search = WebSearch()
25
- visit_webpage = VisitWebpage()
26
- suggest_menu = SuggestMenu()
27
- catering_service_tool = CateringServiceTool()
28
- superhero_party_theme_generator = SuperheroPartyThemeGenerator()
29
- final_answer = FinalAnswer()
30
 
31
- with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
32
  prompt_templates = yaml.safe_load(stream)
33
 
34
  agent = CodeAgent(
35
  model=model,
36
- tools=[web_search, visit_webpage, suggest_menu, catering_service_tool, superhero_party_theme_generator],
37
- managed_agents=[],
38
- max_steps=10,
39
- verbosity_level=2,
40
  grammar=None,
41
  planning_interval=None,
42
  name=None,
43
  description=None,
44
  prompt_templates=prompt_templates
45
  )
46
- if __name__ == "__main__":
47
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
+ import datetime
3
+ import requests
4
+ import pytz
5
  import yaml
6
+ from tools.final_answer import FinalAnswerTool
 
7
 
8
+ from Gradio_UI import GradioUI
 
9
 
 
 
 
 
 
 
10
 
11
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
+ @tool
13
+ def web_search(query: str) -> str: # it's import to specify the return type
14
+ # Keep this format for the description / args / args description but feel free to modify the tool
15
+ """A tool that performs web searches using DuckDuckGo
16
+ Args:
17
+ query: The search query string
18
+ """
19
+ try:
20
+ # Create instance of DuckDuckGoSearchTool
21
+ search_tool = DuckDuckGoSearchTool()
22
 
23
+ # Perform the search
24
+ results = search_tool(query)
25
+
26
+ # Print results for debugging
27
+ if not results:
28
+ return "No results found."
29
+
30
+ # Format results as a simple string
31
+ return str(results)
32
+
33
+ except Exception as e:
34
+ return f"Error performing search: {str(e)}"
35
+
36
+
37
+ @tool
38
+ def get_current_time_in_timezone(timezone: str) -> str:
39
+ """A tool that fetches the current local time in a specified timezone.
40
+ Args:
41
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
42
+ """
43
+ try:
44
+ # Create timezone object
45
+ tz = pytz.timezone(timezone)
46
+ # Get current time in that timezone
47
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
48
+ return f"The current local time in {timezone} is: {local_time}"
49
+ except Exception as e:
50
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
51
+
52
+
53
+ final_answer = FinalAnswerTool()
54
+
55
+ # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
56
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
57
 
58
  model = HfApiModel(
59
  max_tokens=2096,
 
62
  custom_role_conversions=None,
63
  )
64
 
65
+ # Import tool from Hub
66
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
 
 
 
67
 
68
+ with open("prompts.yaml", 'r') as stream:
69
  prompt_templates = yaml.safe_load(stream)
70
 
71
  agent = CodeAgent(
72
  model=model,
73
+ tools=[web_search, final_answer], ## add your tools here (don't remove final answer)
74
+ max_steps=6,
75
+ verbosity_level=1,
 
76
  grammar=None,
77
  planning_interval=None,
78
  name=None,
79
  description=None,
80
  prompt_templates=prompt_templates
81
  )
82
+
83
+ GradioUI(agent).launch()