Spaces:
Build error
Build error
File size: 5,743 Bytes
f0d9b0c 8d4019f abbfa74 5bc3747 03f1aea 0c85c81 1297f51 1d4cce7 1297f51 1d4cce7 0c85c81 03f1aea 0c85c81 1d4cce7 0c85c81 1d4cce7 1297f51 1d4cce7 0c85c81 747d88e 0c85c81 747d88e 03f1aea 0c85c81 1297f51 03f1aea 747d88e cc686c8 03f1aea cc686c8 747d88e 5962009 747d88e 5962009 747d88e 5962009 747d88e 5962009 cc686c8 abbfa74 cc686c8 abbfa74 cc686c8 abbfa74 03f1aea 5962009 1297f51 cc686c8 5962009 abbfa74 5962009 abbfa74 5962009 cc686c8 5962009 b076256 1297f51 03f1aea f0d9b0c b9c42db 13a9a81 8d4019f 1d19382 0c85c81 4137359 f61b459 5bc3747 747d88e cc686c8 abbfa74 | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | import streamlit as st
import numpy as np
import pandas as pd
from translate import Translator
# Translator setup
def translate_text(text, lang_code):
try:
translator = Translator(to_lang=lang_code)
return translator.translate(text)
except Exception:
return text # Fallback to original text
# Multi-language setup
languages = {
"English": "en",
"Spanish": "es",
"French": "fr",
"German": "de",
"Chinese": "zh"
}
# Appliance list
appliance_list = [
"1. LED Bulb",
"2. Fan",
"3. LED TV",
"4. Computer",
"5. Refrigerator",
"6. Washing Machine",
"7. Water Pump",
"8. Iron",
"9. Microwave Oven",
"10. Water Dispenser",
"11. Geyser",
"12. Heater",
"13. Dishwasher",
"14. Inverter AC",
"15. Others",
]
# Streamlit app configuration
st.set_page_config(page_title="International Solar Designer", layout="centered")
# Sidebar language selection
selected_language = st.sidebar.selectbox("Select Language", options=list(languages.keys()))
lang_code = languages[selected_language]
# App title
st.title(translate_text("Solar System Designer", lang_code))
# Sidebar appliance selection
st.sidebar.subheader(translate_text("Select Appliances", lang_code))
appliance_name = st.sidebar.selectbox("Choose Appliance", appliance_list)
if appliance_name == "15. Others":
appliance_name = st.sidebar.text_input("Enter Appliance Name", "")
# Appliance data storage
appliance_data = []
# Add appliance button logic
if "appliance_data" not in st.session_state:
st.session_state["appliance_data"] = appliance_data
# Input fields for appliances
if appliance_name != "15. Others":
wattage = st.number_input(
translate_text(f"{appliance_name} - Wattage (W):", lang_code), min_value=0, step=1, key=f"{appliance_name}_wattage"
)
hours = st.number_input(
translate_text(f"{appliance_name} - Daily Usage (hours):", lang_code), min_value=0, step=1, key=f"{appliance_name}_hours"
)
quantity = st.number_input(
translate_text(f"{appliance_name} - Quantity:", lang_code), min_value=0, step=1, key=f"{appliance_name}_quantity"
)
# When the "Add Appliance" button is clicked
if st.button(translate_text("Add Appliance", lang_code)):
if wattage > 0 and hours > 0 and quantity > 0:
appliance_data = st.session_state["appliance_data"]
appliance_data.append({
"Appliance": appliance_name,
"Wattage (W)": wattage,
"Daily Usage (hours)": hours,
"Quantity": quantity
})
st.session_state["appliance_data"] = appliance_data # Store data in session
st.success(translate_text(f"{appliance_name} added successfully!", lang_code))
else:
st.error(translate_text("Please fill in all appliance details before adding.", lang_code))
# Display added appliances in a table format
if st.session_state["appliance_data"]:
st.subheader(translate_text("Added Appliances", lang_code))
appliance_df = pd.DataFrame(st.session_state["appliance_data"])
st.dataframe(appliance_df)
# Calculate recommendations
if st.button(translate_text("Calculate Recommendations", lang_code)):
if not st.session_state["appliance_data"]:
st.error(translate_text("Please add at least one appliance.", lang_code))
else:
total_load = sum(item["Wattage (W)"] * item["Quantity"] for item in st.session_state["appliance_data"]) # in Watts
total_energy_consumption = sum(
item["Wattage (W)"] * item["Daily Usage (hours)"] * item["Quantity"] for item in st.session_state["appliance_data"]
) / 1000 # in kWh/day
# Solar panel calculation
solar_panel_capacity = 550 # Fixed capacity of a solar panel in Watts
sunlight_hours = 5 # Average peak sunlight hours
panels_required = np.ceil(total_energy_consumption / (solar_panel_capacity / 1000 * sunlight_hours))
# Inverter calculation (20% buffer added)
inverter_capacity = np.ceil(total_load * 1.2 / 1000) # in kW
# Battery requirement
battery_efficiency = 0.95 # Assuming Lithium-Ion battery
battery_capacity_kWh = total_energy_consumption / battery_efficiency # in kWh
battery_capacity_ah = battery_capacity_kWh * 1000 / 48 # Assuming a 48V system
batteries_required = np.ceil(battery_capacity_ah / 200) # Assuming 200 Ah per battery
# Output
st.subheader(translate_text("System Recommendations", lang_code))
st.write(translate_text(f"Total Load: {total_load} Watts", lang_code))
st.write(translate_text(f"Inverter Required: {inverter_capacity} kW", lang_code))
st.write(translate_text(f"Solar Panels Required: {int(panels_required)} (550W each)", lang_code))
st.write(translate_text(f"Batteries Required: {int(batteries_required)} (200 Ah, 48V system)", lang_code))
# Suggestions
st.subheader(translate_text("System Design Suggestions", lang_code))
suggestions = [
"Ensure panels are installed at the optimal tilt angle.",
"Consider a hybrid system for grid integration.",
"Use MPPT charge controllers for efficiency.",
"Plan for future system expansion.",
"Choose high-quality and reliable components.",
"Consult a certified solar installer for best practices."
]
for suggestion in suggestions:
st.write(translate_text(suggestion, lang_code))
# Footer: Developed by
st.markdown(f"<br><hr><p style='text-align: center;'>Developed by Engr Muhammad Arsalan</p>", unsafe_allow_html=True)
|