Download func.py from Yinxing/LLM_Dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/datasets/Yinxing/LLM_Dataset/resolve/b4584ea2c37e0055aca42bbfd6515230381561ae/func.py
- Command line
-
hf download hf://datasets/Yinxing/LLM_Dataset@b4584ea2c37e0055aca42bbfd6515230381561ae/func.py
-
curl -L -o func.py https://huggingface.co/datasets/Yinxing/LLM_Dataset/resolve/b4584ea2c37e0055aca42bbfd6515230381561ae/func.py
1.28 kB
| from geopy.geocoders import Nominatim | |
| from geopy import geocoders | |
| from geopy.distance import geodesic | |
| import pandas as pd | |
| import streamlit as st | |
| def find_nearby_places(lat, lon, place_type, radius): | |
| geolocator = Nominatim(user_agent="nearby_search") | |
| location = geolocator.reverse((lat, lon)) | |
| st.write(f"\n検索した場所: {location}\n") | |
| query = f"{place_type} near {lat}, {lon}" | |
| df = [] | |
| try: | |
| places = geolocator.geocode(query, exactly_one=False, limit=None) | |
| if places: | |
| for place in places: | |
| place_coords = (place.latitude, place.longitude) | |
| place_distance = geodesic((lat, lon), place_coords).kilometers | |
| if place_distance <= radius: | |
| df.append((place.address,) + place_coords + (place_distance,)) | |
| #print(f"{place.address} ({place_distance:.2f} km)") | |
| else: | |
| st.write("No nearby places found for the given type.") | |
| except: | |
| st.write("Error: Unable to fetch nearby places.") | |
| return pd.DataFrame(df, columns = ['場所', 'lat', 'lon', '距離(km)']) | |
| def get_place(x): | |
| loc = Nominatim(user_agent="GetLoc") | |
| getLoc = loc.geocode(x,country_codes='jp') | |
| return getLoc.latitude, getLoc.longitude, getLoc |