eaglelandsonce commited on
Commit
6c5f514
·
verified ·
1 Parent(s): 5cbab5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -9
app.py CHANGED
@@ -5,6 +5,10 @@ import plotly.express as px
5
  from datasets import load_dataset
6
  import folium
7
  from streamlit_folium import st_folium
 
 
 
 
8
 
9
  # Hugging Face Datasets
10
  @st.cache_data
@@ -61,12 +65,30 @@ def generate_terrain_data():
61
 
62
  terrain_data = generate_terrain_data()
63
 
64
- # Filter Data Based on User Inputs
65
- filtered_data = terrain_data[
66
- (terrain_data["Signal Strength (dBm)"] >= signal_threshold) &
67
- (terrain_data["Cost ($1000s)"] <= budget) &
68
- (terrain_data["Priority Area"] == priority_area)
69
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  # Add Composite Score for Ranking
72
  filtered_data["Composite Score"] = (
@@ -81,9 +103,13 @@ if data_to_view == "Network Insights":
81
  st.dataframe(network_insights)
82
  elif data_to_view == "Filtered Terrain Data":
83
  st.subheader("Filtered Terrain Data")
84
- st.dataframe(filtered_data[[
 
 
 
85
  "Region", "Priority Area", "Signal Strength (dBm)", "Cost ($1000s)", "Terrain Difficulty (0-10)", "Description", "Composite Score"
86
- ]])
 
87
 
88
  # Map Visualization
89
  st.header("Geographical Map of Regions")
@@ -96,6 +122,7 @@ if not filtered_data.empty:
96
  location=[row["Latitude"], row["Longitude"]],
97
  popup=(
98
  f"<b>Region:</b> {row['Region']}<br>"
 
99
  f"<b>Description:</b> {row['Description']}<br>"
100
  f"<b>Signal Strength:</b> {row['Signal Strength (dBm)']} dBm<br>"
101
  f"<b>Cost:</b> ${row['Cost ($1000s)']}k<br>"
@@ -130,7 +157,7 @@ def recommend_deployment(data):
130
  if data.empty:
131
  return "No viable deployment regions within the specified parameters."
132
  best_region = data.loc[data["Composite Score"].idxmax()]
133
- return f"Recommended Region: {best_region['Region']} with Composite Score: {best_region['Composite Score']:.2f}, Signal Strength: {best_region['Signal Strength (dBm)']} dBm, Terrain Difficulty: {best_region['Terrain Difficulty (0-10)']}, and Estimated Cost: ${best_region['Cost ($1000s)']}k\nDescription: {best_region['Description']}"
134
 
135
  recommendation = recommend_deployment(filtered_data)
136
  st.subheader(recommendation)
 
5
  from datasets import load_dataset
6
  import folium
7
  from streamlit_folium import st_folium
8
+ from geopy.geocoders import Nominatim
9
+
10
+ # Initialize geolocator
11
+ geolocator = Nominatim(user_agent="geoapiExercises")
12
 
13
  # Hugging Face Datasets
14
  @st.cache_data
 
65
 
66
  terrain_data = generate_terrain_data()
67
 
68
+ # Reverse Geocoding Function
69
+ def get_location_name(lat, lon):
70
+ try:
71
+ location = geolocator.reverse((lat, lon), exactly_one=True)
72
+ return location.address if location else "Unknown Location"
73
+ except Exception as e:
74
+ return "Error: Unable to fetch location"
75
+
76
+ # Add Location Name to Filtered Data
77
+ if include_human_readable:
78
+ filtered_data = terrain_data[
79
+ (terrain_data["Signal Strength (dBm)"] >= signal_threshold) &
80
+ (terrain_data["Cost ($1000s)"] <= budget) &
81
+ (terrain_data["Priority Area"] == priority_area)
82
+ ]
83
+ filtered_data["Location Name"] = filtered_data.apply(
84
+ lambda row: get_location_name(row["Latitude"], row["Longitude"]), axis=1
85
+ )
86
+ else:
87
+ filtered_data = terrain_data[
88
+ (terrain_data["Signal Strength (dBm)"] >= signal_threshold) &
89
+ (terrain_data["Cost ($1000s)"] <= budget) &
90
+ (terrain_data["Priority Area"] == priority_area)
91
+ ]
92
 
93
  # Add Composite Score for Ranking
94
  filtered_data["Composite Score"] = (
 
103
  st.dataframe(network_insights)
104
  elif data_to_view == "Filtered Terrain Data":
105
  st.subheader("Filtered Terrain Data")
106
+ columns_to_display = [
107
+ "Region", "Location Name", "Priority Area", "Signal Strength (dBm)",
108
+ "Cost ($1000s)", "Terrain Difficulty (0-10)", "Description", "Composite Score"
109
+ ] if include_human_readable else [
110
  "Region", "Priority Area", "Signal Strength (dBm)", "Cost ($1000s)", "Terrain Difficulty (0-10)", "Description", "Composite Score"
111
+ ]
112
+ st.dataframe(filtered_data[columns_to_display])
113
 
114
  # Map Visualization
115
  st.header("Geographical Map of Regions")
 
122
  location=[row["Latitude"], row["Longitude"]],
123
  popup=(
124
  f"<b>Region:</b> {row['Region']}<br>"
125
+ f"<b>Location:</b> {row.get('Location Name', 'N/A')}<br>"
126
  f"<b>Description:</b> {row['Description']}<br>"
127
  f"<b>Signal Strength:</b> {row['Signal Strength (dBm)']} dBm<br>"
128
  f"<b>Cost:</b> ${row['Cost ($1000s)']}k<br>"
 
157
  if data.empty:
158
  return "No viable deployment regions within the specified parameters."
159
  best_region = data.loc[data["Composite Score"].idxmax()]
160
+ return f"Recommended Region: {best_region['Region']} with Composite Score: {best_region['Composite Score']:.2f}, Signal Strength: {best_region['Signal Strength (dBm)']} dBm, Terrain Difficulty: {best_region['Terrain Difficulty (0-10)']}, and Estimated Cost: ${best_region['Cost ($1000s)']}k\nDescription: {best_region['Description']}\nLocation Name: {best_region.get('Location Name', 'N/A')}"
161
 
162
  recommendation = recommend_deployment(filtered_data)
163
  st.subheader(recommendation)