Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,103 +1,103 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
# # Constants
|
7 |
-
# API_KEY = "84e26811a314599e940f343b4d5894a7"
|
8 |
-
# LOCATION = "Pakistan"
|
9 |
-
|
10 |
-
# # Sidebar
|
11 |
-
# st.sidebar.title("Smart Grid Dashboard")
|
12 |
-
# location = st.sidebar.text_input("Enter Location", LOCATION)
|
13 |
-
|
14 |
-
# # Fetch and display weather data
|
15 |
-
# weather = fetch_weather(API_KEY, location)
|
16 |
-
# if weather:
|
17 |
-
# st.sidebar.write(f"Temperature: {weather['temperature']} °C")
|
18 |
-
# st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
|
19 |
-
# st.sidebar.write(f"Weather: {weather['weather']}")
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
23 |
|
24 |
-
#
|
25 |
-
|
|
|
26 |
|
27 |
-
#
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
# title="Energy Consumption, Generation, and Storage Usage Over Time",
|
33 |
-
# labels={"value": "Energy (kWh)", "variable": "Energy Source"})
|
34 |
-
# st.plotly_chart(fig)
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
# grid_health_counts = data["grid_health"].value_counts()
|
39 |
-
# st.bar_chart(grid_health_counts)
|
40 |
|
41 |
-
#
|
42 |
-
|
43 |
-
# current_solar = data["solar_output_kw"].iloc[-1]
|
44 |
-
# current_wind = data["wind_output_kw"].iloc[-1]
|
45 |
-
# recommendation = optimize_load(current_demand, current_solar, current_wind)
|
46 |
|
47 |
-
#
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
#
|
54 |
-
|
|
|
|
|
55 |
|
56 |
-
#
|
57 |
-
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
# })
|
66 |
-
# st.bar_chart(energy_sources.set_index("Source"))
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
# st.markdown("Energy storage is a combination of contributions from different renewable sources.")
|
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 |
# code 2
|
@@ -476,108 +476,108 @@
|
|
476 |
# code 5
|
477 |
|
478 |
|
479 |
-
import streamlit as st
|
480 |
-
import pandas as pd
|
481 |
-
import plotly.express as px
|
482 |
-
from app_backend import fetch_weather, generate_synthetic_data, optimize_load
|
483 |
|
484 |
-
# Constants
|
485 |
-
API_KEY = "84e26811a314599e940f343b4d5894a7"
|
486 |
-
LOCATION = "Pakistan"
|
487 |
|
488 |
-
# Sidebar
|
489 |
-
st.sidebar.title("Smart Grid Dashboard")
|
490 |
-
location = st.sidebar.text_input("Enter Location", LOCATION)
|
491 |
|
492 |
-
# Fetch and display weather data
|
493 |
-
weather = fetch_weather(API_KEY, location)
|
494 |
-
if weather:
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
|
499 |
|
500 |
|
501 |
-
# Tabs
|
502 |
-
tab_home, tab_storage, tab_trading = st.tabs(["Home", "Power Storage", "Electricity Trade Management"])
|
503 |
|
504 |
-
# Home Tab
|
505 |
-
with tab_home:
|
506 |
-
|
507 |
|
508 |
-
|
509 |
-
|
510 |
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
|
528 |
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
|
541 |
-
# Storage Tab
|
542 |
-
with tab_storage:
|
543 |
-
|
544 |
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
# Trading Tab
|
565 |
-
with tab_trading:
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
|
579 |
-
|
580 |
-
|
581 |
|
582 |
# code 6
|
583 |
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.express as px
|
4 |
+
from app_backend import fetch_weather, generate_synthetic_data, optimize_load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
# Constants
|
7 |
+
API_KEY = "84e26811a314599e940f343b4d5894a7"
|
8 |
+
LOCATION = "Pakistan"
|
9 |
|
10 |
+
# Sidebar
|
11 |
+
st.sidebar.title("Smart Grid Dashboard")
|
12 |
+
location = st.sidebar.text_input("Enter Location", LOCATION)
|
13 |
|
14 |
+
# Fetch and display weather data
|
15 |
+
weather = fetch_weather(API_KEY, location)
|
16 |
+
if weather:
|
17 |
+
st.sidebar.write(f"Temperature: {weather['temperature']} °C")
|
18 |
+
st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
|
19 |
+
st.sidebar.write(f"Weather: {weather['weather']}")
|
20 |
|
21 |
+
# Main dashboard with tabs
|
22 |
+
tabs = st.tabs(["Home", "Electricity Storage", "Electricity Trading"])
|
|
|
|
|
|
|
23 |
|
24 |
+
with tabs[0]:
|
25 |
+
st.title("Real-Time Smart Grid Dashboard")
|
|
|
|
|
26 |
|
27 |
+
# Generate synthetic data
|
28 |
+
data = generate_synthetic_data()
|
|
|
|
|
|
|
29 |
|
30 |
+
# Plot total consumption, grid generation, and storage usage
|
31 |
+
fig = px.line(data, x="timestamp", y=["total_consumption_kwh", "grid_generation_kwh", "storage_usage_kwh"],
|
32 |
+
title="Energy Consumption, Generation, and Storage Usage Over Time",
|
33 |
+
labels={"value": "Energy (kWh)", "variable": "Energy Source"})
|
34 |
+
st.plotly_chart(fig)
|
35 |
|
36 |
+
# Grid health overview
|
37 |
+
st.subheader("Grid Health Overview")
|
38 |
+
grid_health_counts = data["grid_health"].value_counts()
|
39 |
+
st.bar_chart(grid_health_counts)
|
40 |
|
41 |
+
# Optimization recommendations
|
42 |
+
current_demand = data["total_consumption_kwh"].iloc[-1]
|
43 |
+
current_solar = data["solar_output_kw"].iloc[-1]
|
44 |
+
current_wind = data["wind_output_kw"].iloc[-1]
|
45 |
+
recommendation = optimize_load(current_demand, current_solar, current_wind)
|
46 |
|
47 |
+
st.subheader("Recommendations")
|
48 |
+
st.write(f"Current Load Demand: {current_demand} kWh")
|
49 |
+
st.write(f"Solar Output: {current_solar} kW")
|
50 |
+
st.write(f"Wind Output: {current_wind} kW")
|
51 |
+
st.write(f"Recommendation: {recommendation}")
|
|
|
|
|
52 |
|
53 |
+
with tabs[1]:
|
54 |
+
st.title("Energy Storage Overview")
|
|
|
55 |
|
56 |
+
# Total energy stored
|
57 |
+
total_storage = 500 # Example of total energy storage
|
58 |
+
st.subheader(f"Total Energy Stored: {total_storage} kWh")
|
59 |
+
|
60 |
+
# Energy storage contribution from different sources
|
61 |
+
st.subheader("Energy Storage Contributions")
|
62 |
+
energy_sources = pd.DataFrame({
|
63 |
+
"Source": ["Wind", "Solar", "Turbine"],
|
64 |
+
"Energy (kW/min)": [5, 7, 10]
|
65 |
+
})
|
66 |
+
st.bar_chart(energy_sources.set_index("Source"))
|
67 |
+
|
68 |
+
# Show energy storage status with a rounded circle
|
69 |
+
st.subheader("Energy Storage Circle")
|
70 |
+
st.markdown("Energy storage is a combination of contributions from different renewable sources.")
|
71 |
+
|
72 |
+
# Visualization of energy storage circle using Plotly
|
73 |
+
storage_data = {
|
74 |
+
"Source": ["Wind", "Solar", "Turbine"],
|
75 |
+
"Energy": [5, 7, 10],
|
76 |
+
}
|
77 |
+
storage_df = pd.DataFrame(storage_data)
|
78 |
+
fig = px.pie(storage_df, names="Source", values="Energy", title="Energy Storage Sources")
|
79 |
+
st.plotly_chart(fig)
|
80 |
|
81 |
+
with tabs[2]:
|
82 |
+
st.title("Energy Trading Overview")
|
83 |
|
84 |
+
# Energy cubes
|
85 |
+
st.subheader("Energy Cubes Stored")
|
86 |
+
energy_cubes = pd.DataFrame({
|
87 |
+
"Country": ["China", "Sri Lanka", "Bangladesh"],
|
88 |
+
"Energy (kWh)": [100, 200, 300],
|
89 |
+
"Shareable": [True, True, False]
|
90 |
+
})
|
91 |
|
92 |
+
# Displaying the energy cubes in a grid
|
93 |
+
st.write("Stored energy can be shared with other countries.")
|
94 |
+
st.dataframe(energy_cubes)
|
95 |
|
96 |
+
# Visualization of energy that can be shared
|
97 |
+
st.subheader("Energy Trading Visualization")
|
98 |
+
st.markdown("The following energy amounts are available for sharing with different countries.")
|
99 |
+
trading_fig = px.bar(energy_cubes, x="Country", y="Energy (kWh)", color="Shareable", title="Energy Trading")
|
100 |
+
st.plotly_chart(trading_fig)
|
101 |
|
102 |
|
103 |
# code 2
|
|
|
476 |
# code 5
|
477 |
|
478 |
|
479 |
+
# import streamlit as st
|
480 |
+
# import pandas as pd
|
481 |
+
# import plotly.express as px
|
482 |
+
# from app_backend import fetch_weather, generate_synthetic_data, optimize_load
|
483 |
|
484 |
+
# # Constants
|
485 |
+
# API_KEY = "84e26811a314599e940f343b4d5894a7"
|
486 |
+
# LOCATION = "Pakistan"
|
487 |
|
488 |
+
# # Sidebar
|
489 |
+
# st.sidebar.title("Smart Grid Dashboard")
|
490 |
+
# location = st.sidebar.text_input("Enter Location", LOCATION)
|
491 |
|
492 |
+
# # Fetch and display weather data
|
493 |
+
# weather = fetch_weather(API_KEY, location)
|
494 |
+
# if weather:
|
495 |
+
# st.sidebar.write(f"Temperature: {weather['temperature']} °C")
|
496 |
+
# st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
|
497 |
+
# st.sidebar.write(f"Weather: {weather['weather']}")
|
498 |
|
499 |
|
500 |
|
501 |
+
# # Tabs
|
502 |
+
# tab_home, tab_storage, tab_trading = st.tabs(["Home", "Power Storage", "Electricity Trade Management"])
|
503 |
|
504 |
+
# # Home Tab
|
505 |
+
# with tab_home:
|
506 |
+
# st.title("Real-Time Smart Grid Dashboard")
|
507 |
|
508 |
+
# # Generate synthetic data
|
509 |
+
# data = generate_synthetic_data()
|
510 |
|
511 |
+
# # Grid Health
|
512 |
+
# # st.subheader("Grid Health Overview")
|
513 |
+
# # grid_health_counts = data["grid_health"].value_counts()
|
514 |
+
# # st.bar_chart(grid_health_counts)
|
515 |
|
516 |
+
# # Power Consumption, Generation & Storage Graph
|
517 |
+
# st.subheader("Power Consumption, Generation & Storage")
|
518 |
+
# fig = px.line(data, x="timestamp", y=["load_demand_kwh", "solar_output_kw", "wind_output_kw"],
|
519 |
+
# title="Power Consumption, Generation & Storage", labels={"value": "Power (MW)"})
|
520 |
+
# fig.update_traces(line=dict(width=2))
|
521 |
+
# st.plotly_chart(fig)
|
522 |
|
523 |
+
# # Grid Health
|
524 |
+
# st.subheader("Grid Health Overview")
|
525 |
+
# grid_health_counts = data["grid_health"].value_counts()
|
526 |
+
# st.bar_chart(grid_health_counts)
|
527 |
|
528 |
|
529 |
+
# # Optimization Recommendations
|
530 |
+
# current_demand = data["load_demand_kwh"].iloc[-1]
|
531 |
+
# current_solar = data["solar_output_kw"].iloc[-1]
|
532 |
+
# current_wind = data["wind_output_kw"].iloc[-1]
|
533 |
+
# recommendation = optimize_load(current_demand, current_solar, current_wind)
|
534 |
|
535 |
+
# st.subheader("Recommendations")
|
536 |
+
# st.write(f"Current Load Demand: {current_demand} MW")
|
537 |
+
# st.write(f"Solar Output: {current_solar} MW")
|
538 |
+
# st.write(f"Wind Output: {current_wind} MW")
|
539 |
+
# st.write(f"Recommendation: {recommendation}")
|
540 |
|
541 |
+
# # Storage Tab
|
542 |
+
# with tab_storage:
|
543 |
+
# st.title("Energy Storage Overview")
|
544 |
|
545 |
+
# # Energy Contribution by Resources
|
546 |
+
# st.subheader("Energy Contribution Percentage by Resources")
|
547 |
+
# energy_data = {
|
548 |
+
# "Wind": 5,
|
549 |
+
# "Solar": 7,
|
550 |
+
# "Turbine": 10
|
551 |
+
# }
|
552 |
+
# energy_df = pd.DataFrame(list(energy_data.items()), columns=["Source", "Energy (MW)"])
|
553 |
+
# fig = px.pie(energy_df, values="Energy (MW)", names="Source", title="Energy Contribution by Resources")
|
554 |
+
# st.plotly_chart(fig)
|
555 |
|
556 |
+
# # Energy Storage Merge
|
557 |
+
# st.subheader("Total Energy Stored")
|
558 |
+
# st.write("Energy stored from all sources:")
|
559 |
+
# energy_stored = sum(energy_data.values())
|
560 |
+
# st.write(f"Total Energy Stored: {energy_stored} MW")
|
561 |
+
# st.write("Energy sources merged into total energy storage:")
|
562 |
+
# st.write(f"Total Energy Stored in Grid: {energy_stored} MW")
|
563 |
+
|
564 |
+
# # Trading Tab
|
565 |
+
# with tab_trading:
|
566 |
+
# st.title("Electricity Trade Management")
|
567 |
+
|
568 |
+
# # Simulating Electricity Trade (Energy cubes & trading)
|
569 |
+
# st.subheader("Energy Trade Overview")
|
570 |
+
# energy_trade = {
|
571 |
+
# "USA": 50,
|
572 |
+
# "Germany": 40,
|
573 |
+
# "India": 30
|
574 |
+
# }
|
575 |
+
# trade_df = pd.DataFrame(list(energy_trade.items()), columns=["Country", "Energy (MW)"])
|
576 |
+
# fig = px.bar(trade_df, x="Country", y="Energy (MW)", title="Energy Trading Overview")
|
577 |
+
# st.plotly_chart(fig)
|
578 |
|
579 |
+
# st.write("Energy cubes available for trading:")
|
580 |
+
# st.write("The system can trade energy with other countries.")
|
581 |
|
582 |
# code 6
|
583 |
|