rehanafzal commited on
Commit
5cb69b8
·
verified ·
1 Parent(s): ad4e38e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "New York"
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
22
+ st.title("Real-Time Smart Grid Dashboard")
23
+
24
+ # Generate synthetic data
25
+ data = generate_synthetic_data()
26
+
27
+ # Plot load demand
28
+ fig = px.line(data, x="timestamp", y="load_demand_kwh", title="Load Demand Over Time")
29
+ st.plotly_chart(fig)
30
+
31
+ # Renewable energy contribution
32
+ fig = px.bar(
33
+ data,
34
+ x="timestamp",
35
+ y=["solar_output_kw", "wind_output_kw"],
36
+ title="Renewable Energy Contributions",
37
+ labels={"value": "Power (kW)", "variable": "Energy Source"}
38
+ )
39
+ st.plotly_chart(fig)
40
+
41
+ # Grid health
42
+ st.subheader("Grid Health Overview")
43
+ grid_health_counts = data["grid_health"].value_counts()
44
+ st.bar_chart(grid_health_counts)
45
+
46
+ # Optimization recommendations
47
+ current_demand = data["load_demand_kwh"].iloc[-1]
48
+ current_solar = data["solar_output_kw"].iloc[-1]
49
+ current_wind = data["wind_output_kw"].iloc[-1]
50
+ recommendation = optimize_load(current_demand, current_solar, current_wind)
51
+
52
+ st.subheader("Recommendations")
53
+ st.write(f"Current Load Demand: {current_demand} kWh")
54
+ st.write(f"Solar Output: {current_solar} kW")
55
+ st.write(f"Wind Output: {current_wind} kW")
56
+ st.write(f"Recommendation: {recommendation}")