Spaces:
Build error
Build error
| 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) | |