safiaa02 commited on
Commit
c31edd3
·
verified ·
1 Parent(s): e139a7a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import plotly.express as px
5
+ from prophet import Prophet
6
+
7
+ # Simulated school network traffic data
8
+ st.title("📡 Smart Network Resource Allocation")
9
+
10
+ # Load or generate synthetic data
11
+ @st.cache_data
12
+ def load_data():
13
+ schools = [f"School_{i}" for i in range(1, 6)]
14
+ time_range = pd.date_range(start="2024-02-01", periods=24, freq="H")
15
+ data = []
16
+
17
+ for school in schools:
18
+ for time in time_range:
19
+ bandwidth_usage = np.random.randint(1, 100) # Random usage in Mbps
20
+ data.append([school, time, bandwidth_usage])
21
+
22
+ df = pd.DataFrame(data, columns=["School", "Timestamp", "Bandwidth_Usage"])
23
+ return df
24
+
25
+ df = load_data()
26
+
27
+ # Display data
28
+ st.subheader("📊 Network Traffic Data")
29
+ st.write(df.tail())
30
+
31
+ # Prophet Model for Bandwidth Prediction
32
+ st.subheader("📈 Bandwidth Usage Forecasting")
33
+ df_prophet = df.groupby("Timestamp").mean().reset_index()
34
+ df_prophet.columns = ["ds", "y"]
35
+
36
+ model = Prophet()
37
+ model.fit(df_prophet)
38
+ future = model.make_future_dataframe(periods=5, freq="H")
39
+ forecast = model.predict(future)
40
+
41
+ fig = px.line(forecast, x="ds", y="yhat", title="Predicted Bandwidth Demand")
42
+ st.plotly_chart(fig)
43
+
44
+ # Dynamic Bandwidth Allocation
45
+ st.subheader("⚖️ Smart Bandwidth Allocation")
46
+
47
+ def allocate_bandwidth(predictions, total_bandwidth=500):
48
+ total_demand = sum(predictions.values())
49
+ allocation = {school: (predictions[school] / total_demand) * total_bandwidth for school in predictions}
50
+ return allocation
51
+
52
+ # Simulated allocation
53
+ predictions = {f"School_{i}": np.random.randint(30, 100) for i in range(1, 6)}
54
+ allocations = allocate_bandwidth(predictions)
55
+
56
+ st.write("📌 **Predicted Bandwidth Allocation (Mbps):**")
57
+ st.json(allocations)