File size: 1,871 Bytes
cb23aba 86d2f2e 3ae828c 21dae66 3ae828c 21dae66 3ae828c 21dae66 3ae828c 21dae66 3ae828c baec762 3ae828c 21dae66 baec762 21dae66 cb23aba 21dae66 cb23aba 21dae66 cb23aba 8f0e835 3ae828c baec762 8f0e835 21dae66 cb23aba 21dae66 baec762 21dae66 3ae828c 21dae66 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
from geopy.geocoders import Nominatim
import gradio as gr
from validation_submission.utils_individual import add_data_to_individual
from geolocalisation.class_geolocalisation import Geolocalisation
def create_geolocalisation_object(lat, long, name):
try:
geolocalisation = Geolocalisation(
longitude={"type": "longitude", "value": long},
latitude={"type": "latitude", "value": lat},
name=name,
)
except:
print("Pydantic Error for Geolocalisation")
return geolocalisation
def save_geolocalisation_to_json(geolocalisation, individual):
geo_dict = geolocalisation.dict()
individual = add_data_to_individual("geolocalisation", geo_dict, individual)
return individual
def get_location(address, individual):
try:
# calling the Nominatim tool
loc = Nominatim(user_agent="GetLoc")
# entering the location name
getLoc = loc.geocode(address)
# latitude and longitude
lat = getLoc.latitude
lon = getLoc.longitude
# Save values
geolocalisation = create_geolocalisation_object(lat, lon, address)
individual = save_geolocalisation_to_json(geolocalisation, individual)
# display location processing
value = "Latitude = " + str(lat) + "\n" + "Longitude = " + str(lon)
identified_location = gr.Textbox(
visible=True,
interactive=False,
label="Identified GPS Location",
value=value,
)
return identified_location, individual
except:
error = "Please try another less precise location."
identified_location = gr.Textbox(
visible=True,
interactive=False,
label="Identified GPS Location",
value=error,
)
return identified_location, individual
|