Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,38 @@ from tools.final_answer import FinalAnswerTool
|
|
| 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
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
|
| 12 |
+
@tool
|
| 13 |
+
def get_coordinates_osm(location_name:str) -> str:
|
| 14 |
+
|
| 15 |
+
"""A tool that fetches gps coordinates of a given place in the world
|
| 16 |
+
Args:
|
| 17 |
+
arg1: the name of the location (e.g., 'Kinshasa, Gombe').
|
| 18 |
+
"""
|
| 19 |
+
headers = {
|
| 20 |
+
'User-Agent': 'MyGeocodingApp/1.0 (youremail@example.com)'
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
location_name = location_name.replace(" ", "+")
|
| 24 |
+
base_url = "https://nominatim.openstreetmap.org/search"
|
| 25 |
+
full_url = f"{base_url}?q={requests.utils.quote(location_name)}&format=json&limit=5"
|
| 26 |
+
|
| 27 |
+
response = requests.get(full_url, headers=headers)
|
| 28 |
+
|
| 29 |
+
if response.status_code != 200:
|
| 30 |
+
raise Exception("Erreur lors de la requête à l'API OpenStreetMap")
|
| 31 |
+
|
| 32 |
+
response_list = response.json()
|
| 33 |
+
|
| 34 |
+
if len(response_list) == 0:
|
| 35 |
+
raise Exception("Aucune réponse trouvée pour cette recherche")
|
| 36 |
+
|
| 37 |
+
latitude = float(response_list[0]['lat'])
|
| 38 |
+
longitude = float(response_list[0]['lon'])
|
| 39 |
+
|
| 40 |
+
return {'latitude': latitude, 'longitude': longitude}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
@tool
|
| 44 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 45 |
#Keep this format for the description / args / args description but feel free to modify the tool
|