Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,12 +55,14 @@ appliance_name = st.sidebar.selectbox("Choose Appliance", appliance_list)
|
|
| 55 |
if appliance_name == "15. Others":
|
| 56 |
appliance_name = st.sidebar.text_input("Enter Appliance Name", "")
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
#
|
| 64 |
if appliance_name != "15. Others":
|
| 65 |
wattage = st.number_input(
|
| 66 |
translate_text(f"{appliance_name} - Wattage (W):", lang_code), min_value=0, step=1, key=f"{appliance_name}_wattage"
|
|
@@ -71,22 +73,37 @@ if appliance_name != "15. Others":
|
|
| 71 |
quantity = st.number_input(
|
| 72 |
translate_text(f"{appliance_name} - Quantity:", lang_code), min_value=0, step=1, key=f"{appliance_name}_quantity"
|
| 73 |
)
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
appliance_data = []
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Calculate recommendations
|
| 83 |
if st.button(translate_text("Calculate Recommendations", lang_code)):
|
| 84 |
-
if not appliance_data:
|
| 85 |
-
st.error(translate_text("Please
|
| 86 |
else:
|
| 87 |
-
total_load = sum(item["Wattage"] * item["Quantity"] for item in appliance_data) # in Watts
|
| 88 |
total_energy_consumption = sum(
|
| 89 |
-
item["Wattage"] * item["Hours"] * item["Quantity"] for item in appliance_data
|
| 90 |
) / 1000 # in kWh/day
|
| 91 |
|
| 92 |
# Solar panel calculation
|
|
@@ -98,6 +115,7 @@ if st.button(translate_text("Calculate Recommendations", lang_code)):
|
|
| 98 |
inverter_capacity = np.ceil(total_load * 1.2 / 1000) # in kW
|
| 99 |
|
| 100 |
# Battery requirement
|
|
|
|
| 101 |
battery_capacity_kWh = total_energy_consumption / battery_efficiency # in kWh
|
| 102 |
battery_capacity_ah = battery_capacity_kWh * 1000 / 48 # Assuming a 48V system
|
| 103 |
batteries_required = np.ceil(battery_capacity_ah / 200) # Assuming 200 Ah per battery
|
|
@@ -134,3 +152,4 @@ if st.button(translate_text("Calculate Recommendations", lang_code)):
|
|
| 134 |
|
| 135 |
|
| 136 |
|
|
|
|
|
|
| 55 |
if appliance_name == "15. Others":
|
| 56 |
appliance_name = st.sidebar.text_input("Enter Appliance Name", "")
|
| 57 |
|
| 58 |
+
# Appliance data storage
|
| 59 |
+
appliance_data = []
|
| 60 |
+
|
| 61 |
+
# Add appliance button logic
|
| 62 |
+
if "appliance_data" not in st.session_state:
|
| 63 |
+
st.session_state["appliance_data"] = appliance_data
|
| 64 |
|
| 65 |
+
# Input fields for appliances
|
| 66 |
if appliance_name != "15. Others":
|
| 67 |
wattage = st.number_input(
|
| 68 |
translate_text(f"{appliance_name} - Wattage (W):", lang_code), min_value=0, step=1, key=f"{appliance_name}_wattage"
|
|
|
|
| 73 |
quantity = st.number_input(
|
| 74 |
translate_text(f"{appliance_name} - Quantity:", lang_code), min_value=0, step=1, key=f"{appliance_name}_quantity"
|
| 75 |
)
|
| 76 |
+
|
| 77 |
+
# When the "Add Appliance" button is clicked
|
| 78 |
+
if st.button(translate_text("Add Appliance", lang_code)):
|
| 79 |
+
if wattage > 0 and hours > 0 and quantity > 0:
|
| 80 |
+
appliance_data = st.session_state["appliance_data"]
|
| 81 |
+
appliance_data.append({
|
| 82 |
+
"Appliance": appliance_name,
|
| 83 |
+
"Wattage": wattage,
|
| 84 |
+
"Hours": hours,
|
| 85 |
+
"Quantity": quantity
|
| 86 |
+
})
|
| 87 |
+
st.session_state["appliance_data"] = appliance_data # Store data in session
|
| 88 |
+
|
| 89 |
+
st.success(translate_text(f"{appliance_name} added successfully!", lang_code))
|
| 90 |
+
else:
|
| 91 |
+
st.error(translate_text("Please fill in all appliance details before adding.", lang_code))
|
| 92 |
+
|
| 93 |
+
# Display added appliances
|
| 94 |
+
if st.session_state["appliance_data"]:
|
| 95 |
+
st.subheader(translate_text("Added Appliances", lang_code))
|
| 96 |
+
for item in st.session_state["appliance_data"]:
|
| 97 |
+
st.write(f"{item['Appliance']} - {item['Wattage']} W, {item['Hours']} hours/day, {item['Quantity']} units")
|
| 98 |
|
| 99 |
# Calculate recommendations
|
| 100 |
if st.button(translate_text("Calculate Recommendations", lang_code)):
|
| 101 |
+
if not st.session_state["appliance_data"]:
|
| 102 |
+
st.error(translate_text("Please add at least one appliance.", lang_code))
|
| 103 |
else:
|
| 104 |
+
total_load = sum(item["Wattage"] * item["Quantity"] for item in st.session_state["appliance_data"]) # in Watts
|
| 105 |
total_energy_consumption = sum(
|
| 106 |
+
item["Wattage"] * item["Hours"] * item["Quantity"] for item in st.session_state["appliance_data"]
|
| 107 |
) / 1000 # in kWh/day
|
| 108 |
|
| 109 |
# Solar panel calculation
|
|
|
|
| 115 |
inverter_capacity = np.ceil(total_load * 1.2 / 1000) # in kW
|
| 116 |
|
| 117 |
# Battery requirement
|
| 118 |
+
battery_efficiency = 0.95 # Assuming Lithium-Ion battery
|
| 119 |
battery_capacity_kWh = total_energy_consumption / battery_efficiency # in kWh
|
| 120 |
battery_capacity_ah = battery_capacity_kWh * 1000 / 48 # Assuming a 48V system
|
| 121 |
batteries_required = np.ceil(battery_capacity_ah / 200) # Assuming 200 Ah per battery
|
|
|
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
+
|