SantoshKumar1310 commited on
Commit
b743f91
·
verified ·
1 Parent(s): 7ea140d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -8,20 +8,45 @@ from Gradio_UI import GradioUI
8
 
9
  @tool
10
  def get_current_time_in_timezone(timezone: str) -> str:
11
- """Return the current time in the specified timezone."""
 
 
 
 
 
 
 
12
  try:
13
  tz = pytz.timezone(timezone)
14
- time_now = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
15
- return f"The current local time in {timezone} is: {time_now}"
16
  except Exception as e:
17
- return f"Error: {e}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  final_answer = FinalAnswerTool()
21
  search_tool = DuckDuckGoSearchTool()
22
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
23
 
24
- # Replaced InferenceClientModel → HfApiModel
25
  model = HfApiModel(
26
  max_tokens=2048,
27
  temperature=0.7,
@@ -33,7 +58,13 @@ with open("prompts.yaml", "r") as f:
33
 
34
  agent = CodeAgent(
35
  model=model,
36
- tools=[final_answer, search_tool, image_generation_tool, get_current_time_in_timezone],
 
 
 
 
 
 
37
  max_steps=6,
38
  verbosity_level=1,
39
  description="A multi-tool web chatbot and image generator",
 
8
 
9
  @tool
10
  def get_current_time_in_timezone(timezone: str) -> str:
11
+ """A tool that fetches the current local time in a specified timezone.
12
+
13
+ Args:
14
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
15
+
16
+ Returns:
17
+ The current local time as a formatted string.
18
+ """
19
  try:
20
  tz = pytz.timezone(timezone)
21
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
22
+ return f"The current local time in {timezone} is: {local_time}"
23
  except Exception as e:
24
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
25
+
26
+
27
+ @tool
28
+ def random_welcome_message(name: str) -> str:
29
+ """Generate a random welcome message for a given user.
30
+
31
+ Args:
32
+ name: The name of the user to greet.
33
+
34
+ Returns:
35
+ A personalized welcome string.
36
+ """
37
+ import random
38
+ messages = [
39
+ f"Hey {name}, hope your day’s fantastic!",
40
+ f"Welcome aboard, {name}! Ready to explore?",
41
+ f"Good to see you, {name}! Let's create some magic!"
42
+ ]
43
+ return random.choice(messages)
44
 
45
 
46
  final_answer = FinalAnswerTool()
47
  search_tool = DuckDuckGoSearchTool()
48
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
49
 
 
50
  model = HfApiModel(
51
  max_tokens=2048,
52
  temperature=0.7,
 
58
 
59
  agent = CodeAgent(
60
  model=model,
61
+ tools=[
62
+ final_answer,
63
+ search_tool,
64
+ image_generation_tool,
65
+ get_current_time_in_timezone,
66
+ random_welcome_message
67
+ ],
68
  max_steps=6,
69
  verbosity_level=1,
70
  description="A multi-tool web chatbot and image generator",