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