import streamlit as st import pandas as pd import numpy as np import plotly.express as px from datasets import load_dataset import folium from streamlit_folium import st_folium from geopy.geocoders import Nominatim # Initialize geolocator geolocator = Nominatim(user_agent="geoapiExercises") # Hugging Face Datasets @st.cache_data def load_data(): network_insights = load_dataset("infinite-dataset-hub/5GNetworkOptimization", split="train") return network_insights.to_pandas() # Load Datasets network_insights = load_data() # Title st.title("Smart Network Infrastructure Planner") st.sidebar.header("Input Parameters") # User Inputs from Sidebar budget = st.sidebar.number_input("Total Budget (in $1000s):", min_value=10, max_value=1000, step=10) priority_area = st.sidebar.selectbox("Priority Area:", ["Rural", "Urban", "Suburban"]) signal_threshold = st.sidebar.slider("Signal Strength Threshold (dBm):", min_value=-120, max_value=-30, value=-80) terrain_weight = st.sidebar.slider("Terrain Difficulty Weight:", min_value=0.0, max_value=1.0, value=0.5) cost_weight = st.sidebar.slider("Cost Weight:", min_value=0.0, max_value=1.0, value=0.5) include_human_readable = st.sidebar.checkbox("Include Human-Readable Info", value=True) # Display Dataset Options data_to_view = st.sidebar.selectbox("Select Dataset to View:", ["Network Insights", "Filtered Terrain Data"]) # Terrain and Connectivity Analysis Section st.header("Terrain and Connectivity Analysis") # Simulate Terrain Data def generate_terrain_data(): np.random.seed(42) data = { "Region": [f"Region-{i}" for i in range(1, 11)], "Latitude": np.random.uniform(30.0, 50.0, size=10), "Longitude": np.random.uniform(-120.0, -70.0, size=10), "Terrain Difficulty (0-10)": np.random.randint(1, 10, size=10), "Signal Strength (dBm)": np.random.randint(-120, -30, size=10), "Cost ($1000s)": np.random.randint(50, 200, size=10), "Priority Area": np.random.choice(["Rural", "Urban", "Suburban"], size=10), "Description": [ "Flat area with minimal obstacles", "Hilly terrain, moderate construction difficulty", "Dense urban area with high costs", "Suburban area, balanced terrain", "Mountainous region, challenging setup", "Remote rural area, sparse population", "Coastal area, potential for high signal interference", "Industrial zone, requires robust infrastructure", "Dense forest region, significant signal attenuation", "Open plains, optimal for cost-effective deployment" ] } return pd.DataFrame(data) terrain_data = generate_terrain_data() # Reverse Geocoding Function def get_location_name(lat, lon): try: location = geolocator.reverse((lat, lon), exactly_one=True) return location.address if location else "Unknown Location" except Exception as e: return "Error: Unable to fetch location" # Add Location Name to Filtered Data if include_human_readable: filtered_data = terrain_data[ (terrain_data["Signal Strength (dBm)"] >= signal_threshold) & (terrain_data["Cost ($1000s)"] <= budget) & (terrain_data["Priority Area"] == priority_area) ] filtered_data["Location Name"] = filtered_data.apply( lambda row: get_location_name(row["Latitude"], row["Longitude"]), axis=1 ) else: filtered_data = terrain_data[ (terrain_data["Signal Strength (dBm)"] >= signal_threshold) & (terrain_data["Cost ($1000s)"] <= budget) & (terrain_data["Priority Area"] == priority_area) ] # Add Composite Score for Ranking filtered_data["Composite Score"] = ( (1 - terrain_weight) * filtered_data["Signal Strength (dBm)"] + (terrain_weight) * (10 - filtered_data["Terrain Difficulty (0-10)"]) - (cost_weight) * filtered_data["Cost ($1000s)"] ) # Display Selected Dataset if data_to_view == "Network Insights": st.subheader("Network Insights Dataset") st.dataframe(network_insights) elif data_to_view == "Filtered Terrain Data": st.subheader("Filtered Terrain Data") columns_to_display = [ "Region", "Location Name", "Priority Area", "Signal Strength (dBm)", "Cost ($1000s)", "Terrain Difficulty (0-10)", "Description", "Composite Score" ] if include_human_readable else [ "Region", "Priority Area", "Signal Strength (dBm)", "Cost ($1000s)", "Terrain Difficulty (0-10)", "Description", "Composite Score" ] st.dataframe(filtered_data[columns_to_display]) # Map Visualization st.header("Geographical Map of Regions") if not filtered_data.empty: map_center = [filtered_data["Latitude"].mean(), filtered_data["Longitude"].mean()] region_map = folium.Map(location=map_center, zoom_start=6) for _, row in filtered_data.iterrows(): folium.Marker( location=[row["Latitude"], row["Longitude"]], popup=( f"Region: {row['Region']}
" f"Location: {row.get('Location Name', 'N/A')}
" f"Description: {row['Description']}
" f"Signal Strength: {row['Signal Strength (dBm)']} dBm
" f"Cost: ${row['Cost ($1000s)']}k
" f"Terrain Difficulty: {row['Terrain Difficulty (0-10)']}" ), icon=folium.Icon(color="blue", icon="info-sign") ).add_to(region_map) st_folium(region_map, width=700, height=500) else: st.write("No regions match the selected criteria.") # Visualization fig = px.scatter( filtered_data, x="Cost ($1000s)", y="Signal Strength (dBm)", size="Terrain Difficulty (0-10)", color="Region", title="Signal Strength vs. Cost", labels={ "Cost ($1000s)": "Cost in $1000s", "Signal Strength (dBm)": "Signal Strength in dBm", }, ) st.plotly_chart(fig) # Recommendation Engine st.header("Deployment Recommendations") def recommend_deployment(data): if data.empty: return "No viable deployment regions within the specified parameters." best_region = data.loc[data["Composite Score"].idxmax()] 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')}" recommendation = recommend_deployment(filtered_data) st.subheader(recommendation) # Footer st.sidebar.markdown("---") st.sidebar.markdown( "**Developed for Hackathon using Hugging Face Infinite Dataset Hub**\n\n[Visit Hugging Face](https://huggingface.co)")