erdikent commited on
Commit
7ff58ad
·
verified ·
1 Parent(s): 5baead4

Update.app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -53
app.py CHANGED
@@ -1,66 +1,78 @@
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
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
- @tool
12
- def calculator(a;int, b;int)-> int: """"Multiply two integers"""
13
-
14
-
15
-
16
- return "a * b"
17
-
18
- @tool
19
- def get_current_time_in_timezone(timezone: str) -> str:
20
- """A tool that fetches the current local time in a specified timezone.
21
  Args:
22
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
23
  """
24
- try:
25
- # Create timezone object
26
- tz = pytz.timezone(timezone)
27
- # Get current time in that timezone
28
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
29
- return f"The current local time in {timezone} is: {local_time}"
30
- except Exception as e:
31
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
32
 
33
 
34
- final_answer = FinalAnswerTool()
35
-
36
- # 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:
37
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- model = HfApiModel(
40
- max_tokens=2096,
41
- temperature=0.5,
42
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
43
- custom_role_conversions=None,
44
- )
 
 
 
 
 
 
 
 
45
 
 
 
 
 
 
 
 
 
46
 
47
- # Import tool from Hub
48
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
49
 
50
- with open("prompts.yaml", 'r') as stream:
51
- prompt_templates = yaml.safe_load(stream)
52
-
53
  agent = CodeAgent(
54
- model=model,
55
- tools=[final_answer], ## add your tools here (don't remove final answer)
56
- max_steps=6,
57
- verbosity_level=1,
58
- grammar=None,
59
- planning_interval=None,
60
- name=None,
61
- description=None,
62
- prompt_templates=prompt_templates
 
63
  )
64
 
65
-
66
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, Tool, tool, VisitWebpageTool
 
 
 
 
 
2
 
 
3
 
4
+ def suggest_menu(occasion: str) -> str:
5
+ """
6
+ Suggests a menu based on the occasion.
 
 
 
 
 
 
 
 
7
  Args:
8
+ occasion: The type of occasion for the party.
9
  """
10
+ if occasion == "casual":
11
+ return "Pizza, snacks, and drinks."
12
+ elif occasion == "formal":
13
+ return "3-course dinner with wine and dessert."
14
+ elif occasion == "superhero":
15
+ return "Buffet with high-energy and healthy food."
16
+ else:
17
+ return "Custom menu for the butler."
18
 
19
 
20
+ def catering_service_tool(query: str) -> str:
21
+ """
22
+ This tool returns the highest-rated catering service in Gotham City.
23
+
24
+ Args:
25
+ query: A search term for finding catering services.
26
+ """
27
+ # Example list of catering services and their ratings
28
+ services = {
29
+ "Gotham Catering Co.": 4.9,
30
+ "Wayne Manor Catering": 4.8,
31
+ "Gotham City Events": 4.7,
32
+ }
33
+
34
+ # Find the highest rated catering service (simulating search query filtering)
35
+ best_service = max(services, key=services.get)
36
+
37
+ return best_service
38
 
39
+ class SuperheroPartyThemeTool(Tool):
40
+ name = "superhero_party_theme_generator"
41
+ description = """
42
+ This tool suggests creative superhero-themed party ideas based on a category.
43
+ It returns a unique party theme idea."""
44
+
45
+ inputs = {
46
+ "category": {
47
+ "type": "string",
48
+ "description": "The type of superhero party (e.g., 'classic heroes', 'villain masquerade', 'futuristic Gotham').",
49
+ }
50
+ }
51
+
52
+ output_type = "string"
53
 
54
+ def forward(self, category: str):
55
+ themes = {
56
+ "classic heroes": "Justice League Gala: Guests come dressed as their favorite DC heroes with themed cocktails like 'The Kryptonite Punch'.",
57
+ "villain masquerade": "Gotham Rogues' Ball: A mysterious masquerade where guests dress as classic Batman villains.",
58
+ "futuristic Gotham": "Neo-Gotham Night: A cyberpunk-style party inspired by Batman Beyond, with neon decorations and futuristic gadgets."
59
+ }
60
+
61
+ return themes.get(category.lower(), "Themed party idea not found. Try 'classic heroes', 'villain masquerade', or 'futuristic Gotham'.")
62
 
 
 
63
 
64
+ # Alfred, the butler, preparing the menu for the party
 
 
65
  agent = CodeAgent(
66
+ tools=[
67
+ DuckDuckGoSearchTool(),
68
+ VisitWebpageTool(),
69
+ suggest_menu,
70
+ catering_service_tool,
71
+ SuperheroPartyThemeTool()
72
+ ],
73
+ model=HfApiModel(),
74
+ max_steps=10,
75
+ verbosity_level=2
76
  )
77
 
78
+ agent.run("Give me the best playlist for a party at the Wayne's mansion. The party idea is a 'villain masquerade' theme")