ydeniz commited on
Commit
fa2948e
·
verified ·
1 Parent(s): ec8ad17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -7
app.py CHANGED
@@ -4,19 +4,63 @@ 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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -34,6 +78,8 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
37
  final_answer = FinalAnswerTool()
38
 
39
  # 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:
@@ -55,7 +101,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import os
8
+ from dotenv import load_dotenv
9
  from Gradio_UI import GradioUI
10
+ import requests
11
+ import json
12
+ from IPython.display import JSON
13
 
14
+ api_key = os.getenv("google_key")
15
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
16
  @tool
17
+ def get_location_coordinates(query:str)-> str: #it's import to specify the return type
18
  #Keep this format for the description / args / args description but feel free to modify the tool
19
+ """A tool that gets the given location name's coordinates as latitude and longitude"
20
+ Args:
21
+ query : Location name that is going to be search for its coordinate system
22
+ """
23
+ url = "https://places.googleapis.com/v1/places:searchText"
24
+ # Replace with your actual API key
25
+
26
+
27
+ headers = {
28
+ "Content-Type" : "application/json",
29
+ "X-Goog-Api-Key" : api_key,
30
+ "X-Goog-FieldMask": "places.displayName,places.formattedAddress,places.priceLevel,places.location"
31
+ }
32
+
33
+ data = {
34
+ "textQuery": f"{query}"
35
+ }
36
+
37
+ response = requests.post(url=url, headers=headers, data=json.dumps(data))
38
+
39
+ latitude = response.json()["places"][0]["location"]["latitude"]
40
+ longitude = response.json()["places"][0]["location"]["longitude"]
41
+ return f"Location coordinates is Latitude : {latitude}, Longitude : {longitude} "
42
+
43
+ @tool
44
+ def get_weather_from_coordinate_system (latitude:float, longitude:float) -> str:
45
+ """ A tool that gets weather information such as temperature from the given latitude and longitude coordinate system
46
  Args:
47
+ latitude: Coordinate system from given location
48
+ longitude:Coordinate system from given location
49
  """
50
+ url = "https://weather.googleapis.com/v1/currentConditions:lookup"
51
+ params = {
52
+ "key" : api_key,
53
+ "location.latitude" : latitude,
54
+ "location.longitude" : longitude
55
+ }
56
+ response = requests.get(url=url, params=params)
57
+ temp = response.json()["temperature"]["degrees"]
58
+ if response.status_code == 200:
59
+ return f"Weather is {temp} degree. "
60
+ else:
61
+ return f"Couldn't get temperature."
62
+
63
+
64
 
65
  @tool
66
  def get_current_time_in_timezone(timezone: str) -> str:
 
78
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
79
 
80
 
81
+ os.environ['HF_TOKEN']=os.getenv("HF_TOKEN")
82
+
83
  final_answer = FinalAnswerTool()
84
 
85
  # 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:
 
101
 
102
  agent = CodeAgent(
103
  model=model,
104
+ tools=[final_answer, get_location_coordinates, get_weather_from_coordinate_system], ## add your tools here (don't remove final answer)
105
  max_steps=6,
106
  verbosity_level=1,
107
  grammar=None,