Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,95 +1,86 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from googletrans import Translator
|
| 3 |
-
from pvlib import location
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
-
#
|
| 8 |
translator = Translator()
|
| 9 |
|
| 10 |
# Function to handle translation
|
| 11 |
-
def translate(text,
|
| 12 |
try:
|
| 13 |
-
|
| 14 |
-
return
|
| 15 |
except Exception:
|
| 16 |
-
return text #
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
st.set_page_config(page_title="Solar System Designer", layout="centered", initial_sidebar_state="expanded")
|
| 20 |
-
|
| 21 |
-
# Language selection
|
| 22 |
languages = {
|
| 23 |
"English": "en",
|
| 24 |
-
"French": "fr",
|
| 25 |
"Spanish": "es",
|
|
|
|
| 26 |
"German": "de",
|
| 27 |
"Chinese": "zh-cn"
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
| 29 |
selected_language = st.sidebar.selectbox("Select Language", options=list(languages.keys()))
|
| 30 |
lang_code = languages[selected_language]
|
| 31 |
|
| 32 |
-
#
|
| 33 |
st.title(translate("Solar System Designer", lang_code))
|
| 34 |
|
| 35 |
-
# Solar panel
|
| 36 |
-
|
| 37 |
"300W": 300,
|
| 38 |
"400W": 400,
|
| 39 |
"550W": 550
|
| 40 |
}
|
| 41 |
-
|
| 42 |
-
panel_capacity =
|
| 43 |
|
| 44 |
# Battery options
|
| 45 |
-
battery_types = {"Lithium-Ion": 95, "Lead-Acid":
|
| 46 |
-
|
| 47 |
-
battery_efficiency = battery_types[
|
| 48 |
-
|
| 49 |
-
battery_voltages = [12, 24, 48]
|
| 50 |
-
selected_voltage = st.selectbox(translate("Select Battery Voltage", lang_code), options=battery_voltages)
|
| 51 |
|
| 52 |
-
# Appliance
|
| 53 |
-
st.subheader(translate("
|
| 54 |
appliances = []
|
| 55 |
|
| 56 |
-
if "
|
| 57 |
-
st.session_state["
|
| 58 |
|
| 59 |
appliance_name = st.text_input(translate("Appliance Name", lang_code))
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
if st.button(translate("Add Appliance", lang_code)):
|
| 64 |
-
st.session_state["
|
| 65 |
-
"name": appliance_name,
|
| 66 |
-
"power": appliance_power,
|
| 67 |
-
"hours": appliance_hours
|
| 68 |
-
})
|
| 69 |
|
| 70 |
-
if st.session_state["
|
| 71 |
-
st.table(st.session_state["
|
| 72 |
|
| 73 |
-
# Calculate
|
| 74 |
if st.button(translate("Calculate Recommendations", lang_code)):
|
| 75 |
-
total_load = sum(
|
| 76 |
-
st.write(translate(f"Total Load
|
| 77 |
|
| 78 |
-
# Solar
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
# Suggestions
|
| 83 |
st.subheader(translate("System Design Suggestions", lang_code))
|
| 84 |
suggestions = [
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
-
"Use high-quality
|
| 88 |
-
"
|
| 89 |
-
"
|
| 90 |
-
"Allow space for future system expansion.",
|
| 91 |
-
"Invest in reliable surge protection devices.",
|
| 92 |
-
"Ensure batteries are stored in a cool, ventilated area.",
|
| 93 |
]
|
| 94 |
for suggestion in suggestions:
|
| 95 |
st.write(translate(suggestion, lang_code))
|
|
@@ -99,3 +90,4 @@ if st.button(translate("Calculate Recommendations", lang_code)):
|
|
| 99 |
|
| 100 |
|
| 101 |
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from googletrans import Translator
|
| 3 |
+
from pvlib import pvsystem, location
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
+
# Translator setup
|
| 8 |
translator = Translator()
|
| 9 |
|
| 10 |
# Function to handle translation
|
| 11 |
+
def translate(text, lang_code):
|
| 12 |
try:
|
| 13 |
+
translated = translator.translate(text, dest=lang_code)
|
| 14 |
+
return translated.text
|
| 15 |
except Exception:
|
| 16 |
+
return text # Fallback to original text
|
| 17 |
|
| 18 |
+
# Multi-language setup
|
|
|
|
|
|
|
|
|
|
| 19 |
languages = {
|
| 20 |
"English": "en",
|
|
|
|
| 21 |
"Spanish": "es",
|
| 22 |
+
"French": "fr",
|
| 23 |
"German": "de",
|
| 24 |
"Chinese": "zh-cn"
|
| 25 |
}
|
| 26 |
+
|
| 27 |
+
# Streamlit app configuration
|
| 28 |
+
st.set_page_config(page_title="International Solar Designer", layout="centered")
|
| 29 |
selected_language = st.sidebar.selectbox("Select Language", options=list(languages.keys()))
|
| 30 |
lang_code = languages[selected_language]
|
| 31 |
|
| 32 |
+
# App title
|
| 33 |
st.title(translate("Solar System Designer", lang_code))
|
| 34 |
|
| 35 |
+
# Solar panel selection
|
| 36 |
+
solar_panel_options = {
|
| 37 |
"300W": 300,
|
| 38 |
"400W": 400,
|
| 39 |
"550W": 550
|
| 40 |
}
|
| 41 |
+
panel_choice = st.selectbox(translate("Select Solar Panel Capacity", lang_code), options=list(solar_panel_options.keys()))
|
| 42 |
+
panel_capacity = solar_panel_options[panel_choice]
|
| 43 |
|
| 44 |
# Battery options
|
| 45 |
+
battery_types = {"Lithium-Ion": 0.95, "Lead-Acid": 0.8}
|
| 46 |
+
battery_choice = st.selectbox(translate("Select Battery Type", lang_code), options=battery_types.keys())
|
| 47 |
+
battery_efficiency = battery_types[battery_choice]
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# Appliance entry
|
| 50 |
+
st.subheader(translate("Add Your Appliances", lang_code))
|
| 51 |
appliances = []
|
| 52 |
|
| 53 |
+
if "appliances" not in st.session_state:
|
| 54 |
+
st.session_state["appliances"] = []
|
| 55 |
|
| 56 |
appliance_name = st.text_input(translate("Appliance Name", lang_code))
|
| 57 |
+
power = st.number_input(translate("Power (Watts)", lang_code), min_value=1)
|
| 58 |
+
usage_hours = st.number_input(translate("Usage Hours per Day", lang_code), min_value=1)
|
| 59 |
|
| 60 |
if st.button(translate("Add Appliance", lang_code)):
|
| 61 |
+
st.session_state["appliances"].append({"name": appliance_name, "power": power, "hours": usage_hours})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
if st.session_state["appliances"]:
|
| 64 |
+
st.table(st.session_state["appliances"])
|
| 65 |
|
| 66 |
+
# Calculate recommendations
|
| 67 |
if st.button(translate("Calculate Recommendations", lang_code)):
|
| 68 |
+
total_load = sum(a["power"] * a["hours"] for a in st.session_state["appliances"])
|
| 69 |
+
st.write(translate(f"Total Load (Watts): {total_load}", lang_code))
|
| 70 |
|
| 71 |
+
# Solar panel calculation
|
| 72 |
+
sunlight_hours = 5 # Average peak sunlight hours
|
| 73 |
+
panels_required = np.ceil(total_load / (panel_capacity * sunlight_hours))
|
| 74 |
+
st.write(translate(f"Solar Panels Required: {int(panels_required)}", lang_code))
|
| 75 |
|
| 76 |
# Suggestions
|
| 77 |
st.subheader(translate("System Design Suggestions", lang_code))
|
| 78 |
suggestions = [
|
| 79 |
+
"Ensure panels are installed at the optimal tilt angle.",
|
| 80 |
+
"Consider a hybrid system for backup and grid integration.",
|
| 81 |
+
"Use high-quality MPPT charge controllers.",
|
| 82 |
+
"Plan for system expansion in future.",
|
| 83 |
+
"Maintain batteries regularly for longevity."
|
|
|
|
|
|
|
|
|
|
| 84 |
]
|
| 85 |
for suggestion in suggestions:
|
| 86 |
st.write(translate(suggestion, lang_code))
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
+
|