Spaces:
Sleeping
Sleeping
File size: 1,737 Bytes
5cb69b8 |
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 |
import streamlit as st
import pandas as pd
import plotly.express as px
from app_backend import fetch_weather, generate_synthetic_data, optimize_load
# Constants
API_KEY = "84e26811a314599e940f343b4d5894a7"
LOCATION = "New York"
# Sidebar
st.sidebar.title("Smart Grid Dashboard")
location = st.sidebar.text_input("Enter Location", LOCATION)
# Fetch and display weather data
weather = fetch_weather(API_KEY, location)
if weather:
st.sidebar.write(f"Temperature: {weather['temperature']} °C")
st.sidebar.write(f"Wind Speed: {weather['wind_speed']} m/s")
st.sidebar.write(f"Weather: {weather['weather']}")
# Main dashboard
st.title("Real-Time Smart Grid Dashboard")
# Generate synthetic data
data = generate_synthetic_data()
# Plot load demand
fig = px.line(data, x="timestamp", y="load_demand_kwh", title="Load Demand Over Time")
st.plotly_chart(fig)
# Renewable energy contribution
fig = px.bar(
data,
x="timestamp",
y=["solar_output_kw", "wind_output_kw"],
title="Renewable Energy Contributions",
labels={"value": "Power (kW)", "variable": "Energy Source"}
)
st.plotly_chart(fig)
# Grid health
st.subheader("Grid Health Overview")
grid_health_counts = data["grid_health"].value_counts()
st.bar_chart(grid_health_counts)
# Optimization recommendations
current_demand = data["load_demand_kwh"].iloc[-1]
current_solar = data["solar_output_kw"].iloc[-1]
current_wind = data["wind_output_kw"].iloc[-1]
recommendation = optimize_load(current_demand, current_solar, current_wind)
st.subheader("Recommendations")
st.write(f"Current Load Demand: {current_demand} kWh")
st.write(f"Solar Output: {current_solar} kW")
st.write(f"Wind Output: {current_wind} kW")
st.write(f"Recommendation: {recommendation}") |