Rafiea commited on
Commit
d53a94b
·
verified ·
1 Parent(s): fb12c2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -22
app.py CHANGED
@@ -5,22 +5,20 @@ import plotly.express as px
5
  from datasets import load_dataset
6
  import folium
7
  from streamlit_folium import st_folium
8
- from geopy.geocoders import Nominatim
9
- from geopy.exc import GeopyError
10
- import subprocess
11
- import sys
12
 
13
- # Ensure geopy is installed
14
- def install_and_import(package):
15
  try:
16
- __import__(package)
17
- except ImportError:
18
- subprocess.check_call([sys.executable, "-m", "pip", "install", package])
19
-
20
- install_and_import("geopy")
21
-
22
- # Initialize geolocator
23
- geolocator = Nominatim(user_agent="geoapiExercises")
 
24
 
25
  # Hugging Face Datasets
26
  @st.cache_data
@@ -77,14 +75,6 @@ def generate_terrain_data():
77
 
78
  terrain_data = generate_terrain_data()
79
 
80
- # Reverse Geocoding Function
81
- def get_location_name(lat, lon):
82
- try:
83
- location = geolocator.reverse((lat, lon), exactly_one=True)
84
- return location.address if location else "Unknown Location"
85
- except GeopyError:
86
- return "Error: Unable to fetch location"
87
-
88
  # Add Location Name to Filtered Data
89
  if include_human_readable:
90
  filtered_data = terrain_data[
 
5
  from datasets import load_dataset
6
  import folium
7
  from streamlit_folium import st_folium
8
+ import requests
 
 
 
9
 
10
+ # Function to fetch location name using OpenStreetMap Nominatim API
11
+ def get_location_name(lat, lon):
12
  try:
13
+ url = f"https://nominatim.openstreetmap.org/reverse?format=json&lat={lat}&lon={lon}&zoom=10&addressdetails=1"
14
+ response = requests.get(url)
15
+ if response.status_code == 200:
16
+ data = response.json()
17
+ return data.get("display_name", "Unknown Location")
18
+ else:
19
+ return "Error: Unable to fetch location"
20
+ except Exception as e:
21
+ return f"Error: {str(e)}"
22
 
23
  # Hugging Face Datasets
24
  @st.cache_data
 
75
 
76
  terrain_data = generate_terrain_data()
77
 
 
 
 
 
 
 
 
 
78
  # Add Location Name to Filtered Data
79
  if include_human_readable:
80
  filtered_data = terrain_data[