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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -16
app.py CHANGED
@@ -9,24 +9,32 @@ 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
- 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:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ async function getLocation() {
13
+ return new Promise((resolve, reject) => {
14
+ if ("geolocation" in navigator) {
15
+ navigator.geolocation.getCurrentPosition(
16
+ (position) => {
17
+ resolve({
18
+ latitude: position.coords.latitude,
19
+ longitude: position.coords.longitude,
20
+ accuracy: position.coords.accuracy
21
+ });
22
+ },
23
+ (error) => {
24
+ reject({ error: "Location access denied or unavailable." });
25
+ }
26
+ );
27
+ } else {
28
+ reject({ error: "Geolocation is not supported by this browser." });
29
  }
30
+ });
31
+ }
32
+
33
+ // Example Usage
34
+ getLocation()
35
+ .then(location => console.log("User Location:", location))
36
+ .catch(error => console.error("Error:", error));
37
 
 
 
 
 
38
 
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str: