TierraX commited on
Commit
23a99d2
·
verified ·
1 Parent(s): 7132fdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -63
app.py CHANGED
@@ -1,83 +1,46 @@
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,
60
- temperature=0.5,
61
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
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()
 
 
 
 
 
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
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
19
+ provider=None,
 
 
20
  )
21
 
22
+ web_search = WebSearch()
23
+ visit_webpage = VisitWebpage()
24
+ suggest_menu = SuggestMenu()
25
+ catering_service_tool = CateringServiceTool()
26
+ superhero_party_theme_generator = SuperheroPartyThemeGenerator()
27
+ final_answer = FinalAnswer()
28
 
29
+
30
+ with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
31
  prompt_templates = yaml.safe_load(stream)
32
 
33
  agent = CodeAgent(
34
  model=model,
35
+ tools=[web_search, visit_webpage, suggest_menu, catering_service_tool, superhero_party_theme_generator],
36
+ managed_agents=[],
37
+ max_steps=10,
38
+ verbosity_level=2,
39
  grammar=None,
40
  planning_interval=None,
41
  name=None,
42
  description=None,
43
  prompt_templates=prompt_templates
44
  )
45
+ if __name__ == "__main__":
46
+ GradioUI(agent).launch()