priyar84 commited on
Commit
9fde278
·
verified ·
1 Parent(s): 1425a88

create app1.py

Browse files
Files changed (1) hide show
  1. app1.py +61 -0
app1.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from Gradio_UI import GradioUI
8
+
9
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
10
+
11
+ @tool
12
+ def get_current_time_in_timezone(timezone: str) -> str:
13
+ """A tool that fetches the current local time in a specified timezone.
14
+ Args:
15
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
16
+ """
17
+ try:
18
+ # Create timezone object
19
+ tz = pytz.timezone(timezone)
20
+ # Get current time in that 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
+ final_answer = FinalAnswerTool()
28
+
29
+ # 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:
30
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
31
+
32
+ # Define the AI model
33
+ model = HfApiModel(
34
+ max_tokens=2096,
35
+ temperature=0.5,
36
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
37
+ custom_role_conversions=None,
38
+ )
39
+
40
+ # Import tool from Hub
41
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
42
+
43
+ # Load prompt templates
44
+ with open("prompts.yaml", 'r') as stream:
45
+ prompt_templates = yaml.safe_load(stream)
46
+
47
+ # Create the AI agent with tools
48
+ agent = CodeAgent(
49
+ model=model,
50
+ tools=[final_answer,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
51
+ max_steps=6,
52
+ verbosity_level=1,
53
+ grammar=None,
54
+ planning_interval=None,
55
+ name=None,
56
+ description=None,
57
+ prompt_templates=prompt_templates
58
+ )
59
+
60
+ # Launch the AI agent with Gradio
61
+ GradioUI(agent).launch()