eaglelandsonce commited on
Commit
58edc10
Β·
verified Β·
1 Parent(s): a629488

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +203 -167
app.py CHANGED
@@ -7,178 +7,214 @@ 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
15
- def load_data():
16
- network_insights = load_dataset("infinite-dataset-hub/5GNetworkOptimization", split="train")
17
- return network_insights.to_pandas()
18
-
19
- # Load Datasets
20
- network_insights = load_data()
21
-
22
- # Title Section with Styling
23
- st.markdown("""
24
- # 🌍 **Smart Network Infrastructure Planner**
25
- Effortlessly optimize network infrastructure while accounting for budget, signal strength, terrain challenges, and climate risks.
26
- """)
27
- st.sidebar.header("πŸ”§ Input Parameters")
28
-
29
- # User Inputs from Sidebar
30
- with st.sidebar:
31
- budget = st.number_input("πŸ’° Total Budget (in $1000s):", min_value=10, max_value=1000, step=10)
32
- priority_area = st.selectbox("🌎 Priority Area:", ["Rural", "Urban", "Suburban"])
33
- signal_threshold = st.slider("πŸ“Ά Signal Strength Threshold (dBm):", min_value=-120, max_value=-30, value=-80)
34
- terrain_weight = st.slider("πŸŒ„ Terrain Difficulty Weight:", min_value=0.0, max_value=1.0, value=0.5)
35
- cost_weight = st.slider("πŸ’΅ Cost Weight:", min_value=0.0, max_value=1.0, value=0.5)
36
- climate_risk_weight = st.slider("🌑️ Climate Risk Weight:", min_value=0.0, max_value=1.0, value=0.5)
37
- include_human_readable = st.checkbox("πŸ—ΊοΈ Include Human-Readable Info", value=True)
38
-
39
- # Tabs for Data Display and Analysis
40
- st.markdown("## πŸš€ Insights & Recommendations")
41
- tabs = st.tabs(["Terrain Analysis", "Filtered Data", "Geographical Map"])
42
-
43
- # Simulate Terrain and Climate Risk Data
44
- def generate_terrain_data():
45
- np.random.seed(42)
46
- data = {
47
- "Region": [f"Region-{i}" for i in range(1, 11)],
48
- "Latitude": np.random.uniform(30.0, 50.0, size=10),
49
- "Longitude": np.random.uniform(-120.0, -70.0, size=10),
50
- "Terrain Difficulty (0-10)": np.random.randint(1, 10, size=10),
51
- "Signal Strength (dBm)": np.random.randint(-120, -30, size=10),
52
- "Cost ($1000s)": np.random.randint(50, 200, size=10),
53
- "Priority Area": np.random.choice(["Rural", "Urban", "Suburban"], size=10),
54
- "Climate Risk (0-10)": np.random.randint(0, 10, size=10),
55
- "Description": [
56
- "Flat area with minimal obstacles",
57
- "Hilly terrain, moderate construction difficulty",
58
- "Dense urban area with high costs",
59
- "Suburban area, balanced terrain",
60
- "Mountainous region, challenging setup",
61
- "Remote rural area, sparse population",
62
- "Coastal area, potential for high signal interference",
63
- "Industrial zone, requires robust infrastructure",
64
- "Dense forest region, significant signal attenuation",
65
- "Open plains, optimal for cost-effective deployment"
66
- ]
67
- }
68
- return pd.DataFrame(data)
69
-
70
- terrain_data = generate_terrain_data()
71
-
72
- # Reverse Geocoding Function
73
- def get_location_name(lat, lon):
74
- try:
75
- location = geolocator.reverse((lat, lon), exactly_one=True)
76
- return location.address if location else "Unknown Location"
77
- except Exception as e:
78
- return "Error: Unable to fetch location"
79
-
80
- # Add Location Name to Filtered Data
81
- if include_human_readable:
82
- filtered_data = terrain_data[
83
- (terrain_data["Signal Strength (dBm)"] >= signal_threshold) &
84
- (terrain_data["Cost ($1000s)"] <= budget) &
85
- (terrain_data["Priority Area"] == priority_area)
86
- ]
87
- filtered_data["Location Name"] = filtered_data.apply(
88
- lambda row: get_location_name(row["Latitude"], row["Longitude"]), axis=1
89
- )
90
- else:
91
- filtered_data = terrain_data[
92
- (terrain_data["Signal Strength (dBm)"] >= signal_threshold) &
93
- (terrain_data["Cost ($1000s)"] <= budget) &
94
- (terrain_data["Priority Area"] == priority_area)
95
- ]
96
-
97
- # Add Composite Score for Ranking
98
- filtered_data["Composite Score"] = (
99
- (1 - terrain_weight) * filtered_data["Signal Strength (dBm)"] +
100
- (terrain_weight) * (10 - filtered_data["Terrain Difficulty (0-10)"]) -
101
- (cost_weight) * filtered_data["Cost ($1000s)"] -
102
- (climate_risk_weight) * filtered_data["Climate Risk (0-10)"]
103
  )
104
 
105
- # Display Filtered Data in Tab
106
- with tabs[1]:
107
- st.subheader("Filtered Terrain Data")
108
- columns_to_display = [
109
- "Region", "Location Name", "Priority Area", "Signal Strength (dBm)",
110
- "Cost ($1000s)", "Terrain Difficulty (0-10)", "Climate Risk (0-10)", "Description", "Composite Score"
111
- ] if include_human_readable else [
112
- "Region", "Priority Area", "Signal Strength (dBm)", "Cost ($1000s)", "Terrain Difficulty (0-10)", "Climate Risk (0-10)", "Description", "Composite Score"
113
- ]
114
- st.dataframe(filtered_data[columns_to_display])
115
-
116
- # Map Visualization in Tab
117
- with tabs[2]:
118
- st.subheader("Geographical Map of Regions")
119
- if not filtered_data.empty:
120
- map_center = [filtered_data["Latitude"].mean(), filtered_data["Longitude"].mean()]
121
- region_map = folium.Map(location=map_center, zoom_start=6)
122
-
123
- for _, row in filtered_data.iterrows():
124
- folium.Marker(
125
- location=[row["Latitude"], row["Longitude"]],
126
- popup=(
127
- f"<b>Region:</b> {row['Region']}<br>"
128
- f"<b>Location:</b> {row.get('Location Name', 'N/A')}<br>"
129
- f"<b>Description:</b> {row['Description']}<br>"
130
- f"<b>Signal Strength:</b> {row['Signal Strength (dBm)']} dBm<br>"
131
- f"<b>Cost:</b> ${row['Cost ($1000s)']}k<br>"
132
- f"<b>Terrain Difficulty:</b> {row['Terrain Difficulty (0-10)']}<br>"
133
- f"<b>Climate Risk:</b> {row['Climate Risk (0-10)']}"
134
- ),
135
- icon=folium.Icon(color="blue", icon="info-sign")
136
- ).add_to(region_map)
137
-
138
- st_folium(region_map, width=700, height=500)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  else:
140
- st.write("No regions match the selected criteria.")
141
-
142
- # Visualization Tab
143
- with tabs[0]:
144
- st.subheader("Signal Strength vs. Cost")
145
- fig = px.scatter(
146
- filtered_data,
147
- x="Cost ($1000s)",
148
- y="Signal Strength (dBm)",
149
- size="Terrain Difficulty (0-10)",
150
- color="Region",
151
- title="Signal Strength vs. Cost",
152
- labels={
153
- "Cost ($1000s)": "Cost in $1000s",
154
- "Signal Strength (dBm)": "Signal Strength in dBm",
155
- },
156
  )
157
- st.plotly_chart(fig)
158
-
159
- # Recommendation Engine
160
- st.header("✨ Deployment Recommendations")
161
-
162
- def recommend_deployment(data):
163
- if data.empty:
164
- return "No viable deployment regions within the specified parameters."
165
- best_region = data.loc[data["Composite Score"].idxmax()]
166
- return f"**Recommended Region:** {best_region['Region']} \n" \
167
- f"**Composite Score:** {best_region['Composite Score']:.2f} \n" \
168
- f"**Signal Strength:** {best_region['Signal Strength (dBm)']} dBm \n" \
169
- f"**Terrain Difficulty:** {best_region['Terrain Difficulty (0-10)']} \n" \
170
- f"**Climate Risk:** {best_region['Climate Risk (0-10)']} \n" \
171
- f"**Estimated Cost:** ${best_region['Cost ($1000s)']}k \n" \
172
- f"**Description:** {best_region['Description']} \n" \
173
- f"**Location Name:** {best_region.get('Location Name', 'N/A')}"
174
-
175
- recommendation = recommend_deployment(filtered_data)
176
-
177
- # Display Recommendation
178
- st.markdown("### 🌟 Final Recommendation")
179
- st.markdown(recommendation)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
 
181
  # Footer
182
  st.sidebar.markdown("---")
183
  st.sidebar.markdown(
184
- "**Developed for Hackathon using Hugging Face Infinite Dataset Hub**\n\n[Visit Hugging Face](https://huggingface.co)")
 
 
7
  from streamlit_folium import st_folium
8
  from geopy.geocoders import Nominatim
9
 
10
+ # Top-level menu
11
+ menu = st.sidebar.selectbox(
12
+ "Select a Section",
13
+ ["Introduction", "Funding", "Networking", "Content Delivery", "Maintenance"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  )
15
 
16
+ # Introduction Section
17
+ if menu == "Introduction":
18
+ st.title("Welcome to the Smart Network Infrastructure Planner")
19
+ st.markdown("""
20
+ This application provides tools and insights to optimize network infrastructure
21
+ based on various criteria such as budget, signal strength, terrain challenges, and climate risks.
22
+ """)
23
+
24
+ # Funding Section
25
+ elif menu == "Funding":
26
+ st.title("Funding Overview")
27
+ st.markdown("""
28
+ Explore various funding strategies and options to support the development of
29
+ smart network infrastructures.
30
+ """)
31
+
32
+ # Networking Section
33
+ elif menu == "Networking":
34
+ # Initialize geolocator
35
+ geolocator = Nominatim(user_agent="geoapiExercises")
36
+
37
+ # Hugging Face Datasets
38
+ @st.cache_data
39
+ def load_data():
40
+ network_insights = load_dataset("infinite-dataset-hub/5GNetworkOptimization", split="train")
41
+ return network_insights.to_pandas()
42
+
43
+ # Load Datasets
44
+ network_insights = load_data()
45
+
46
+ # Title Section with Styling
47
+ st.markdown("""
48
+ # 🌍 **Smart Network Infrastructure Planner**
49
+ Effortlessly optimize network infrastructure while accounting for budget, signal strength, terrain challenges, and climate risks.
50
+ """)
51
+ st.sidebar.header("πŸ”§ Input Parameters")
52
+
53
+ # User Inputs from Sidebar
54
+ with st.sidebar:
55
+ budget = st.number_input("πŸ’° Total Budget (in $1000s):", min_value=10, max_value=1000, step=10)
56
+ priority_area = st.selectbox("🌎 Priority Area:", ["Rural", "Urban", "Suburban"])
57
+ signal_threshold = st.slider("πŸ“Ά Signal Strength Threshold (dBm):", min_value=-120, max_value=-30, value=-80)
58
+ terrain_weight = st.slider("πŸŒ„ Terrain Difficulty Weight:", min_value=0.0, max_value=1.0, value=0.5)
59
+ cost_weight = st.slider("πŸ’΅ Cost Weight:", min_value=0.0, max_value=1.0, value=0.5)
60
+ climate_risk_weight = st.slider("🌑️ Climate Risk Weight:", min_value=0.0, max_value=1.0, value=0.5)
61
+ include_human_readable = st.checkbox("πŸ—ΊοΈ Include Human-Readable Info", value=True)
62
+
63
+ # Tabs for Data Display and Analysis
64
+ st.markdown("## πŸš€ Insights & Recommendations")
65
+ tabs = st.tabs(["Terrain Analysis", "Filtered Data", "Geographical Map"])
66
+
67
+ # Simulate Terrain and Climate Risk Data
68
+ def generate_terrain_data():
69
+ np.random.seed(42)
70
+ data = {
71
+ "Region": [f"Region-{i}" for i in range(1, 11)],
72
+ "Latitude": np.random.uniform(30.0, 50.0, size=10),
73
+ "Longitude": np.random.uniform(-120.0, -70.0, size=10),
74
+ "Terrain Difficulty (0-10)": np.random.randint(1, 10, size=10),
75
+ "Signal Strength (dBm)": np.random.randint(-120, -30, size=10),
76
+ "Cost ($1000s)": np.random.randint(50, 200, size=10),
77
+ "Priority Area": np.random.choice(["Rural", "Urban", "Suburban"], size=10),
78
+ "Climate Risk (0-10)": np.random.randint(0, 10, size=10),
79
+ "Description": [
80
+ "Flat area with minimal obstacles",
81
+ "Hilly terrain, moderate construction difficulty",
82
+ "Dense urban area with high costs",
83
+ "Suburban area, balanced terrain",
84
+ "Mountainous region, challenging setup",
85
+ "Remote rural area, sparse population",
86
+ "Coastal area, potential for high signal interference",
87
+ "Industrial zone, requires robust infrastructure",
88
+ "Dense forest region, significant signal attenuation",
89
+ "Open plains, optimal for cost-effective deployment"
90
+ ]
91
+ }
92
+ return pd.DataFrame(data)
93
+
94
+ terrain_data = generate_terrain_data()
95
+
96
+ # Reverse Geocoding Function
97
+ def get_location_name(lat, lon):
98
+ try:
99
+ location = geolocator.reverse((lat, lon), exactly_one=True)
100
+ return location.address if location else "Unknown Location"
101
+ except Exception as e:
102
+ return "Error: Unable to fetch location"
103
+
104
+ # Add Location Name to Filtered Data
105
+ if include_human_readable:
106
+ filtered_data = terrain_data[
107
+ (terrain_data["Signal Strength (dBm)"] >= signal_threshold) &
108
+ (terrain_data["Cost ($1000s)"] <= budget) &
109
+ (terrain_data["Priority Area"] == priority_area)
110
+ ]
111
+ filtered_data["Location Name"] = filtered_data.apply(
112
+ lambda row: get_location_name(row["Latitude"], row["Longitude"]), axis=1
113
+ )
114
  else:
115
+ filtered_data = terrain_data[
116
+ (terrain_data["Signal Strength (dBm)"] >= signal_threshold) &
117
+ (terrain_data["Cost ($1000s)"] <= budget) &
118
+ (terrain_data["Priority Area"] == priority_area)
119
+ ]
120
+
121
+ # Add Composite Score for Ranking
122
+ filtered_data["Composite Score"] = (
123
+ (1 - terrain_weight) * filtered_data["Signal Strength (dBm)"] +
124
+ (terrain_weight) * (10 - filtered_data["Terrain Difficulty (0-10)"]) -
125
+ (cost_weight) * filtered_data["Cost ($1000s)"] -
126
+ (climate_risk_weight) * filtered_data["Climate Risk (0-10)"]
 
 
 
 
127
  )
128
+
129
+ # Display Filtered Data in Tab
130
+ with tabs[1]:
131
+ st.subheader("Filtered Terrain Data")
132
+ columns_to_display = [
133
+ "Region", "Location Name", "Priority Area", "Signal Strength (dBm)",
134
+ "Cost ($1000s)", "Terrain Difficulty (0-10)", "Climate Risk (0-10)", "Description", "Composite Score"
135
+ ] if include_human_readable else [
136
+ "Region", "Priority Area", "Signal Strength (dBm)", "Cost ($1000s)", "Terrain Difficulty (0-10)", "Climate Risk (0-10)", "Description", "Composite Score"
137
+ ]
138
+ st.dataframe(filtered_data[columns_to_display])
139
+
140
+ # Map Visualization in Tab
141
+ with tabs[2]:
142
+ st.subheader("Geographical Map of Regions")
143
+ if not filtered_data.empty:
144
+ map_center = [filtered_data["Latitude"].mean(), filtered_data["Longitude"].mean()]
145
+ region_map = folium.Map(location=map_center, zoom_start=6)
146
+
147
+ for _, row in filtered_data.iterrows():
148
+ folium.Marker(
149
+ location=[row["Latitude"], row["Longitude"]],
150
+ popup=(f"<b>Region:</b> {row['Region']}<br>"
151
+ f"<b>Location:</b> {row.get('Location Name', 'N/A')}<br>"
152
+ f"<b>Description:</b> {row['Description']}<br>"
153
+ f"<b>Signal Strength:</b> {row['Signal Strength (dBm)']} dBm<br>"
154
+ f"<b>Cost:</b> ${row['Cost ($1000s)']}k<br>"
155
+ f"<b>Terrain Difficulty:</b> {row['Terrain Difficulty (0-10)']}<br>"
156
+ f"<b>Climate Risk:</b> {row['Climate Risk (0-10)']}")
157
+ ).add_to(region_map)
158
+
159
+ st_folium(region_map, width=700, height=500)
160
+ else:
161
+ st.write("No regions match the selected criteria.")
162
+
163
+ # Visualization Tab
164
+ with tabs[0]:
165
+ st.subheader("Signal Strength vs. Cost")
166
+ fig = px.scatter(
167
+ filtered_data,
168
+ x="Cost ($1000s)",
169
+ y="Signal Strength (dBm)",
170
+ size="Terrain Difficulty (0-10)",
171
+ color="Region",
172
+ title="Signal Strength vs. Cost",
173
+ labels={
174
+ "Cost ($1000s)": "Cost in $1000s",
175
+ "Signal Strength (dBm)": "Signal Strength in dBm",
176
+ },
177
+ )
178
+ st.plotly_chart(fig)
179
+
180
+ # Recommendation Engine
181
+ st.header("✨ Deployment Recommendations")
182
+
183
+ def recommend_deployment(data):
184
+ if data.empty:
185
+ return "No viable deployment regions within the specified parameters."
186
+ best_region = data.loc[data["Composite Score"].idxmax()]
187
+ return f"**Recommended Region:** {best_region['Region']} \n" \
188
+ f"**Composite Score:** {best_region['Composite Score']:.2f} \n" \
189
+ f"**Signal Strength:** {best_region['Signal Strength (dBm)']} dBm \n" \
190
+ f"**Terrain Difficulty:** {best_region['Terrain Difficulty (0-10)']} \n" \
191
+ f"**Climate Risk:** {best_region['Climate Risk (0-10)']} \n" \
192
+ f"**Estimated Cost:** ${best_region['Cost ($1000s)']}k \n" \
193
+ f"**Description:** {best_region['Description']} \n" \
194
+ f"**Location Name:** {best_region.get('Location Name', 'N/A')}"
195
+
196
+ recommendation = recommend_deployment(filtered_data)
197
+
198
+ # Display Recommendation
199
+ st.markdown("### 🌟 Final Recommendation")
200
+ st.markdown(recommendation)
201
+
202
+ # Content Delivery Section
203
+ elif menu == "Content Delivery":
204
+ st.title("Content Delivery Strategies")
205
+ st.markdown("""
206
+ Learn how to effectively deliver content to enhance user engagement and ensure seamless communication.
207
+ """)
208
+
209
+ # Maintenance Section
210
+ elif menu == "Maintenance":
211
+ st.title("System Maintenance")
212
+ st.markdown("""
213
+ Discover best practices for maintaining your smart network infrastructure to ensure reliability and longevity.
214
+ """)
215
 
216
  # Footer
217
  st.sidebar.markdown("---")
218
  st.sidebar.markdown(
219
+ "**Developed for Hackathon using Hugging Face Infinite Dataset Hub**\n\n[Visit Hugging Face](https://huggingface.co)"
220
+ )