SimpleSam commited on
Commit
d1c14dc
·
verified ·
1 Parent(s): 438ddeb

Create miradi.py

Browse files

the first clone from app.py

Files changed (1) hide show
  1. miradi.py +75 -0
miradi.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # a tool to search for property within a location
12
+ @tool
13
+ def property_search_tool(property_type:str, location:str, price:int)-> 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 searches for property in a given location at a given price
16
+ Args:
17
+ property_type: the type of propert whether its an apartment, a bungalow, farm
18
+ location: the location of the property
19
+ price: the price of the rent or sale price
20
+ """
21
+ try:
22
+ property_list = DuckDuckGoSearchTool.forward("{property_type} at {location}")
23
+ return "What magic will you build ?"
24
+ except Exception as e:
25
+ return f"Error fetching property located at '{location}' at a price of '{property_type}' : {str(e)}"
26
+
27
+ @tool
28
+ def get_current_time_in_timezone(timezone: str) -> str:
29
+ """A tool that fetches the current local time in a specified timezone.
30
+ Args:
31
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
32
+ """
33
+ try:
34
+ # Create timezone object
35
+ tz = pytz.timezone(timezone)
36
+ # Get current time in that timezone
37
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
38
+ return f"The current local time in {timezone} is: {local_time}"
39
+ except Exception as e:
40
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
41
+
42
+
43
+ final_answer = FinalAnswerTool()
44
+
45
+ # 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:
46
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
47
+
48
+ model = HfApiModel(
49
+ max_tokens=2096,
50
+ temperature=0.5,
51
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
52
+ custom_role_conversions=None,
53
+ )
54
+
55
+
56
+ # Import tool from Hub
57
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
58
+
59
+ with open("prompts.yaml", 'r') as stream:
60
+ prompt_templates = yaml.safe_load(stream)
61
+
62
+ agent = CodeAgent(
63
+ model=model,
64
+ tools=[final_answer], ## add your tools here (don't remove final answer)
65
+ max_steps=6,
66
+ verbosity_level=1,
67
+ grammar=None,
68
+ planning_interval=None,
69
+ name=None,
70
+ description=None,
71
+ prompt_templates=prompt_templates
72
+ )
73
+
74
+
75
+ GradioUI(agent).launch()