Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
from geopy.geocoders import OpenCageGeocode
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
@@ -6,10 +5,22 @@ import plotly.express as px
|
|
6 |
from datasets import load_dataset
|
7 |
import folium
|
8 |
from streamlit_folium import st_folium
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Hugging Face Datasets
|
15 |
@st.cache_data
|
@@ -69,12 +80,10 @@ terrain_data = generate_terrain_data()
|
|
69 |
# Reverse Geocoding Function
|
70 |
def get_location_name(lat, lon):
|
71 |
try:
|
72 |
-
location = geolocator.reverse((lat, lon),
|
73 |
-
if location
|
74 |
-
|
75 |
-
return "
|
76 |
-
except Exception as e:
|
77 |
-
return f"Error: {str(e)}"
|
78 |
|
79 |
# Add Location Name to Filtered Data
|
80 |
if include_human_readable:
|
@@ -123,12 +132,14 @@ if not filtered_data.empty:
|
|
123 |
for _, row in filtered_data.iterrows():
|
124 |
folium.Marker(
|
125 |
location=[row["Latitude"], row["Longitude"]],
|
126 |
-
popup=(
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
132 |
icon=folium.Icon(color="blue", icon="info-sign")
|
133 |
).add_to(region_map)
|
134 |
|
@@ -166,5 +177,4 @@ st.subheader(recommendation)
|
|
166 |
# Footer
|
167 |
st.sidebar.markdown("---")
|
168 |
st.sidebar.markdown(
|
169 |
-
"**Developed for Hackathon using Hugging Face Infinite Dataset Hub**\n\n[Visit Hugging Face](https://huggingface.co)"
|
170 |
-
)
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
|
|
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
|
|
|
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:
|
|
|
132 |
for _, row in filtered_data.iterrows():
|
133 |
folium.Marker(
|
134 |
location=[row["Latitude"], row["Longitude"]],
|
135 |
+
popup=(
|
136 |
+
f"<b>Region:</b> {row['Region']}<br>"
|
137 |
+
f"<b>Location:</b> {row.get('Location Name', 'N/A')}<br>"
|
138 |
+
f"<b>Description:</b> {row['Description']}<br>"
|
139 |
+
f"<b>Signal Strength:</b> {row['Signal Strength (dBm)']} dBm<br>"
|
140 |
+
f"<b>Cost:</b> ${row['Cost ($1000s)']}k<br>"
|
141 |
+
f"<b>Terrain Difficulty:</b> {row['Terrain Difficulty (0-10)']}"
|
142 |
+
),
|
143 |
icon=folium.Icon(color="blue", icon="info-sign")
|
144 |
).add_to(region_map)
|
145 |
|
|
|
177 |
# Footer
|
178 |
st.sidebar.markdown("---")
|
179 |
st.sidebar.markdown(
|
180 |
+
"**Developed for Hackathon using Hugging Face Infinite Dataset Hub**\n\n[Visit Hugging Face](https://huggingface.co)")
|
|