Spaces:
Sleeping
Sleeping
| # Install necessary libraries before running | |
| # !pip install geopandas pycaret prophet matplotlib streamlit folium requests streamlit-folium | |
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import geopandas as gpd | |
| import matplotlib.pyplot as plt | |
| from prophet import Prophet | |
| from streamlit_folium import folium_static | |
| import folium | |
| import os | |
| # Function to download the naturalearth_lowres dataset | |
| def download_naturalearth_lowres(): | |
| url = "https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_countries.zip" | |
| zip_path = "ne_110m_admin_0_countries.zip" | |
| extracted_folder = "ne_110m_admin_0_countries" | |
| shapefile_path = os.path.join(extracted_folder, "ne_110m_admin_0_countries.shp") | |
| if not os.path.exists(shapefile_path): | |
| import requests | |
| import zipfile | |
| # Download the zip file | |
| r = requests.get(url) | |
| with open(zip_path, "wb") as f: | |
| f.write(r.content) | |
| # Extract the zip file | |
| with zipfile.ZipFile(zip_path, "r") as zip_ref: | |
| zip_ref.extractall(extracted_folder) | |
| return shapefile_path | |
| # Load Geospatial Data | |
| def load_geospatial_data(): | |
| shapefile_path = download_naturalearth_lowres() | |
| world = gpd.read_file(shapefile_path) | |
| underserved_region = world[world['CONTINENT'] == 'Africa'] # Updated column name for compatibility | |
| underserved_locations = gpd.GeoDataFrame({ | |
| "Location": ["Region A", "Region B", "Region C"], | |
| "Latitude": [-1.2921, 1.2921, -3.2921], | |
| "Longitude": [36.8219, 37.8219, 38.8219] | |
| }, geometry=gpd.points_from_xy([36.8219, 37.8219, 38.8219], [-1.2921, 1.2921, -3.2921])) | |
| return underserved_region, underserved_locations | |
| def load_demand_data(): | |
| data = { | |
| "date": pd.date_range(start="2022-01-01", periods=24, freq="M"), | |
| "demand": np.random.randint(50, 200, size=24) | |
| } | |
| demand_df = pd.DataFrame(data) | |
| return demand_df | |
| underserved_region, underserved_locations = load_geospatial_data() | |
| demand_df = load_demand_data() | |
| # Streamlit App Title | |
| st.title("AI-Driven Network Management for Underserved Regions") | |
| # Sidebar for Navigation | |
| st.sidebar.title("Navigation") | |
| module = st.sidebar.radio("Choose a Module:", ["Overview", "Demand Forecasting", "Underserved Regions"]) | |
| # Overview | |
| if module == "Overview": | |
| st.subheader("Welcome to the AI-Driven Network Management App!") | |
| st.write(""" | |
| This app provides AI-powered tools to optimize network planning and management for underserved regions. | |
| Modules: | |
| - **Demand Forecasting:** Predict demand for internet services over time. | |
| - **Underserved Regions:** Identify underserved regions and visualize their locations. | |
| """) | |
| # Demand Forecasting Module | |
| elif module == "Demand Forecasting": | |
| st.subheader("Demand Forecasting") | |
| # Prepare data for Prophet | |
| demand_df.rename(columns={"date": "ds", "demand": "y"}, inplace=True) | |
| # Initialize and fit Prophet model | |
| model = Prophet() | |
| model.fit(demand_df) | |
| # Forecast future demand | |
| future = model.make_future_dataframe(periods=12, freq='M') | |
| forecast = model.predict(future) | |
| # Plot forecast | |
| st.write("### Historical and Forecasted Demand") | |
| fig = model.plot(forecast) | |
| st.pyplot(fig) | |
| st.write("### Forecast Data") | |
| st.dataframe(forecast[["ds", "yhat", "yhat_lower", "yhat_upper"]].tail(12)) | |
| # Underserved Regions Module | |
| elif module == "Underserved Regions": | |
| st.subheader("Underserved Regions") | |
| # Show map with underserved regions | |
| m = folium.Map(location=[0, 20], zoom_start=3) | |
| # Add underserved regions | |
| for _, row in underserved_locations.iterrows(): | |
| folium.Marker( | |
| location=[row["Latitude"], row["Longitude"]], | |
| popup=f"Location: {row['Location']}", | |
| icon=folium.Icon(color="red") | |
| ).add_to(m) | |
| st.write("### Geospatial Visualization") | |
| folium_static(m, width=700, height=500) | |
| # Show region data | |
| st.write("### Region Details") | |
| st.dataframe(underserved_locations.drop(columns="geometry")) | |