File size: 4,112 Bytes
cf353e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 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
@st.cache_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

@st.cache_data
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"))