sicknick32 commited on
Commit
b50edef
·
verified ·
1 Parent(s): b3ce0be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -9,24 +9,24 @@ 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 get_location(arg1:str, arg2:int)-> str:
13
- """Retrieves the users approximate location using there ip address."""
14
- try:
15
- response = requests.get("https://ipinfo.io.json")
16
- data = response.json()
17
-
18
- location_info = {
19
- "city": data.get("city", "unknown"),
20
- "region": data.get("region", "unkown"),
21
- "country": data.get("county", "unkown"),
22
- "latitude": data.get("loc", "").split(',')[0] if data.get("loc")else "unknown",
23
- "longitude": data.get("loc", "").split(',')[1] if data.get("loc")else"unknown",
24
- "ip": data.get("ip", unknown)
25
- }
26
 
27
- return location_info
28
- except Exception as e:
29
- return{"error": str(e)}
 
30
 
31
  @tool
32
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ import geocoder
13
+
14
+ def get_location():
15
+ g = geocoder.ip('me') # Uses the public IP to determine location
16
+ if g.ok:
17
+ return {
18
+ "latitude": g.latlng[0],
19
+ "longitude": g.latlng[1],
20
+ "city": g.city,
21
+ "country": g.country
22
+ }
23
+ else:
24
+ return {"error": "Could not determine location"}
 
25
 
26
+ # Example usage
27
+ if __name__ == "__main__":
28
+ location = get_location()
29
+ print(location)
30
 
31
  @tool
32
  def get_current_time_in_timezone(timezone: str) -> str: