sascow commited on
Commit
ee214ea
·
verified ·
1 Parent(s): 3c763a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -12
app.py CHANGED
@@ -1,33 +1,63 @@
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
- import random
4
  import pytz
 
 
5
  from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
 
8
  @tool
9
- def corporate_nonsense(input_text: str, enthusiasm_level: str = "standard") -> str:
10
- """Converts normal text into ridiculous corporate buzzword-speak
11
 
12
  Args:
13
- input_text: The normal text to convert
14
- enthusiasm_level: How extreme to make it ('standard', 'synergistic', or 'full_consultant')
15
  """
16
- # [Previous corporate_nonsense implementation remains the same]
17
- # ... [keeping the same implementation for brevity]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  @tool
20
  def get_current_time_in_timezone(timezone: str) -> str:
21
  """A tool that fetches the current local time in a specified timezone.
22
 
23
  Args:
24
- timezone: A string representing a valid timezone (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo')
25
-
26
- Returns:
27
- str: A formatted string containing the current time in the specified timezone
28
  """
29
  try:
 
30
  tz = pytz.timezone(timezone)
 
31
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
@@ -42,6 +72,7 @@ model = HfApiModel(
42
  custom_role_conversions=None,
43
  )
44
 
 
45
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
46
 
47
  with open("prompts.yaml", 'r') as stream:
@@ -49,7 +80,7 @@ with open("prompts.yaml", 'r') as stream:
49
 
50
  agent = CodeAgent(
51
  model=model,
52
- tools=[get_current_time_in_timezone, corporate_nonsense, DuckDuckGoSearchTool(), final_answer],
53
  max_steps=6,
54
  verbosity_level=1,
55
  grammar=None,
 
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
+ import requests
4
  import pytz
5
+ import yaml
6
+ import random
7
  from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  @tool
11
+ def magic_8_ball(question: str, asker_name: str) -> str:
12
+ """A Magic 8 Ball tool that provides fortune-telling responses to yes/no questions
13
 
14
  Args:
15
+ question: The question being asked to the Magic 8 Ball
16
+ asker_name: The name of the person asking the question
17
  """
18
+ responses = [
19
+ # Positive responses
20
+ "It is certain.",
21
+ "It is decidedly so.",
22
+ "Without a doubt.",
23
+ "Yes definitely.",
24
+ "You may rely on it.",
25
+ "As I see it, yes.",
26
+ "Most likely.",
27
+ "Outlook good.",
28
+ "Yes.",
29
+ "Signs point to yes.",
30
+
31
+ # Non-committal responses
32
+ "Reply hazy, try again.",
33
+ "Ask again later.",
34
+ "Better not tell you now.",
35
+ "Cannot predict now.",
36
+ "Concentrate and ask again.",
37
+
38
+ # Negative responses
39
+ "Don't count on it.",
40
+ "My reply is no.",
41
+ "My sources say no.",
42
+ "Outlook not so good.",
43
+ "Very doubtful."
44
+ ]
45
+
46
+ # Get random response
47
+ answer = random.choice(responses)
48
+ return f"🎱 Dear {asker_name}, you asked: '{question}'\nThe Magic 8 Ball says: {answer}"
49
 
50
  @tool
51
  def get_current_time_in_timezone(timezone: str) -> str:
52
  """A tool that fetches the current local time in a specified timezone.
53
 
54
  Args:
55
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
56
  """
57
  try:
58
+ # Create timezone object
59
  tz = pytz.timezone(timezone)
60
+ # Get current time in that timezone
61
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
62
  return f"The current local time in {timezone} is: {local_time}"
63
  except Exception as e:
 
72
  custom_role_conversions=None,
73
  )
74
 
75
+ # Import tool from Hub
76
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
77
 
78
  with open("prompts.yaml", 'r') as stream:
 
80
 
81
  agent = CodeAgent(
82
  model=model,
83
+ tools=[get_current_time_in_timezone, magic_8_ball, DuckDuckGoSearchTool(), final_answer],
84
  max_steps=6,
85
  verbosity_level=1,
86
  grammar=None,