Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,116 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
-
# App Title
|
| 5 |
-
st.
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
# Input
|
| 11 |
st.sidebar.header("Add Appliance Details")
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
wattage = st.sidebar.number_input("Wattage (Watts)", min_value=1, value=10)
|
| 14 |
quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
|
| 15 |
usage_hours = st.sidebar.number_input("Daily Usage Hours", min_value=1, value=1)
|
| 16 |
add_button = st.sidebar.button("Add Appliance")
|
| 17 |
|
| 18 |
-
# Session
|
| 19 |
if "appliances" not in st.session_state:
|
| 20 |
st.session_state.appliances = []
|
| 21 |
|
| 22 |
if add_button:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
if st.session_state.appliances:
|
| 32 |
st.subheader("Appliance Details")
|
| 33 |
appliances_df = pd.DataFrame(st.session_state.appliances)
|
| 34 |
st.table(appliances_df)
|
| 35 |
|
| 36 |
-
#
|
| 37 |
appliances_df["Daily Energy (Wh)"] = (
|
| 38 |
-
appliances_df["Wattage"] * appliances_df["Quantity"] * appliances_df["Usage Hours"]
|
| 39 |
)
|
| 40 |
total_energy_kwh = appliances_df["Daily Energy (Wh)"].sum() / 1000 # Convert to kWh
|
|
|
|
| 41 |
|
| 42 |
-
#
|
| 43 |
st.subheader("Solar System Configuration")
|
| 44 |
sunlight_hours = st.slider("Average Sunlight Hours", min_value=4, max_value=10, value=6)
|
| 45 |
panel_efficiency = st.slider("Solar Panel Efficiency (%)", min_value=15, max_value=25, value=20) / 100
|
|
|
|
| 46 |
|
| 47 |
-
#
|
| 48 |
total_panel_wattage = total_energy_kwh / (sunlight_hours * panel_efficiency)
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Display Results
|
| 52 |
-
st.
|
|
|
|
|
|
|
| 53 |
st.write(f"**Required Solar Panel Capacity:** {total_panel_wattage:.2f} W")
|
| 54 |
-
st.write(f"**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
st.markdown("---")
|
| 57 |
-
st.markdown("**Developed by Engr. Muhammad Arsalan**")
|
| 58 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
# App Title with Styling
|
| 5 |
+
st.markdown(
|
| 6 |
+
"<h1 style='text-align: center; color: #4CAF50;'>SolarEase: Solar System Planner</h1>",
|
| 7 |
+
unsafe_allow_html=True,
|
| 8 |
+
)
|
| 9 |
+
st.write(
|
| 10 |
+
"This app helps you calculate the total energy requirements and suggests a solar panel, inverter, and battery configuration for your home or office."
|
| 11 |
+
)
|
| 12 |
|
| 13 |
+
# Sidebar for Appliance Input
|
| 14 |
st.sidebar.header("Add Appliance Details")
|
| 15 |
+
|
| 16 |
+
# Predefined Appliance List
|
| 17 |
+
appliance_list = [
|
| 18 |
+
"LED Bulb",
|
| 19 |
+
"Fan",
|
| 20 |
+
"LED TV",
|
| 21 |
+
"Computer",
|
| 22 |
+
"Refrigerator",
|
| 23 |
+
"Washing Machine",
|
| 24 |
+
"Water Pump",
|
| 25 |
+
"Iron",
|
| 26 |
+
"Microwave Oven",
|
| 27 |
+
"Water Dispenser",
|
| 28 |
+
"Geyser",
|
| 29 |
+
"Heater",
|
| 30 |
+
"Dishwasher",
|
| 31 |
+
"Inverter AC",
|
| 32 |
+
"Others",
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
# Input Fields
|
| 36 |
+
appliance_name = st.sidebar.selectbox("Select Appliance", appliance_list)
|
| 37 |
+
if appliance_name == "Others":
|
| 38 |
+
appliance_name = st.sidebar.text_input("Enter Appliance Name", "")
|
| 39 |
wattage = st.sidebar.number_input("Wattage (Watts)", min_value=1, value=10)
|
| 40 |
quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
|
| 41 |
usage_hours = st.sidebar.number_input("Daily Usage Hours", min_value=1, value=1)
|
| 42 |
add_button = st.sidebar.button("Add Appliance")
|
| 43 |
|
| 44 |
+
# Session State for Storing Appliances
|
| 45 |
if "appliances" not in st.session_state:
|
| 46 |
st.session_state.appliances = []
|
| 47 |
|
| 48 |
if add_button:
|
| 49 |
+
if appliance_name:
|
| 50 |
+
st.session_state.appliances.append(
|
| 51 |
+
{
|
| 52 |
+
"Appliance": appliance_name,
|
| 53 |
+
"Wattage (W)": wattage,
|
| 54 |
+
"Quantity": quantity,
|
| 55 |
+
"Usage Hours": usage_hours,
|
| 56 |
+
}
|
| 57 |
+
)
|
| 58 |
+
else:
|
| 59 |
+
st.sidebar.error("Please enter the appliance name.")
|
| 60 |
+
|
| 61 |
+
# Display Appliance Table
|
| 62 |
if st.session_state.appliances:
|
| 63 |
st.subheader("Appliance Details")
|
| 64 |
appliances_df = pd.DataFrame(st.session_state.appliances)
|
| 65 |
st.table(appliances_df)
|
| 66 |
|
| 67 |
+
# Calculations
|
| 68 |
appliances_df["Daily Energy (Wh)"] = (
|
| 69 |
+
appliances_df["Wattage (W)"] * appliances_df["Quantity"] * appliances_df["Usage Hours"]
|
| 70 |
)
|
| 71 |
total_energy_kwh = appliances_df["Daily Energy (Wh)"].sum() / 1000 # Convert to kWh
|
| 72 |
+
peak_load_watts = appliances_df["Wattage (W)"].sum() # Peak load in watts
|
| 73 |
|
| 74 |
+
# Solar System Inputs
|
| 75 |
st.subheader("Solar System Configuration")
|
| 76 |
sunlight_hours = st.slider("Average Sunlight Hours", min_value=4, max_value=10, value=6)
|
| 77 |
panel_efficiency = st.slider("Solar Panel Efficiency (%)", min_value=15, max_value=25, value=20) / 100
|
| 78 |
+
battery_backup_hours = st.slider("Battery Backup Time (Hours)", min_value=1, max_value=24, value=4)
|
| 79 |
|
| 80 |
+
# Solar Panel Calculation
|
| 81 |
total_panel_wattage = total_energy_kwh / (sunlight_hours * panel_efficiency)
|
| 82 |
+
number_of_panels = int(total_panel_wattage / 400) # Assuming 400W panels
|
| 83 |
+
|
| 84 |
+
# Battery Calculation
|
| 85 |
+
battery_capacity_ah = (total_energy_kwh * battery_backup_hours * 1000) / 12 # Assuming 12V batteries
|
| 86 |
+
number_of_batteries = int(battery_capacity_ah / 200) # Assuming 200Ah batteries
|
| 87 |
+
|
| 88 |
+
# Inverter Calculation
|
| 89 |
+
inverter_size_kw = peak_load_watts / 1000 # Convert to kW
|
| 90 |
|
| 91 |
# Display Results
|
| 92 |
+
st.markdown("<hr>", unsafe_allow_html=True)
|
| 93 |
+
st.markdown("<h2 style='color: #FF5722;'>System Recommendations</h2>", unsafe_allow_html=True)
|
| 94 |
+
st.write(f"**Total Energy Consumption:** {total_energy_kwh:.2f} kWh/day")
|
| 95 |
st.write(f"**Required Solar Panel Capacity:** {total_panel_wattage:.2f} W")
|
| 96 |
+
st.write(f"**Number of Solar Panels (550W each):** {number_of_panels}")
|
| 97 |
+
st.write(f"**Battery Capacity Needed:** {battery_capacity_ah:.2f} Ah")
|
| 98 |
+
st.write(f"**Number of Batteries (200Ah each):** {number_of_batteries}")
|
| 99 |
+
st.write(f"**Inverter Size Required:** {inverter_size_kw:.2f} kW")
|
| 100 |
+
|
| 101 |
+
# Additional Suggestions
|
| 102 |
+
st.markdown("<h3 style='color: #3F51B5;'>Suggestions:</h3>", unsafe_allow_html=True)
|
| 103 |
+
st.write(
|
| 104 |
+
"- Choose high-efficiency solar panels for better performance.\n"
|
| 105 |
+
"- Ensure your inverter has at least 20% extra capacity to handle peak loads.\n"
|
| 106 |
+
"- Use lithium-ion batteries for longer life and better efficiency."
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
# Footer
|
| 110 |
+
st.markdown("<hr>", unsafe_allow_html=True)
|
| 111 |
+
st.markdown(
|
| 112 |
+
"<p style='text-align: center; color: #9C27B0;'>Developed by <strong>Engr. Muhammad Arsalan</strong></p>",
|
| 113 |
+
unsafe_allow_html=True,
|
| 114 |
+
)
|
| 115 |
|
|
|
|
|
|
|
| 116 |
|