arsalan16 commited on
Commit
13a9a81
·
verified ·
1 Parent(s): 7ae5173

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -23
app.py CHANGED
@@ -7,34 +7,34 @@ st.markdown(
7
  unsafe_allow_html=True,
8
  )
9
  st.write(
10
- "This app helps you calculate the total energy requirements and suggests a solar panel, inverter, and battery configuration for your home or office."
11
  )
12
 
13
  # Sidebar for Appliance Input
14
  st.sidebar.header("Add Appliance Details")
15
 
16
- # Predefined Appliance List
17
  appliance_list = [
18
- "LED Bulb",
19
- "Fan",
20
- "LED TV",
21
- "Computer",
22
- "Refrigerator",
23
- "Washing Machine",
24
- "Water Pump",
25
- "Iron",
26
- "Microwave Oven",
27
- "Water Dispenser",
28
- "Geyser",
29
- "Heater",
30
- "Dishwasher",
31
- "Inverter AC",
32
- "Others",
33
  ]
34
 
35
  # Input Fields
36
  appliance_name = st.sidebar.selectbox("Select Appliance", appliance_list)
37
- if appliance_name == "Others":
38
  appliance_name = st.sidebar.text_input("Enter Appliance Name", "")
39
  wattage = st.sidebar.number_input("Wattage (Watts)", min_value=1, value=10)
40
  quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
@@ -49,7 +49,7 @@ if add_button:
49
  if appliance_name:
50
  st.session_state.appliances.append(
51
  {
52
- "Appliance": appliance_name,
53
  "Wattage (W)": wattage,
54
  "Quantity": quantity,
55
  "Usage Hours": usage_hours,
@@ -64,12 +64,26 @@ if st.session_state.appliances:
64
  appliances_df = pd.DataFrame(st.session_state.appliances)
65
  st.table(appliances_df)
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  # Calculations
68
  appliances_df["Daily Energy (Wh)"] = (
69
  appliances_df["Wattage (W)"] * appliances_df["Quantity"] * appliances_df["Usage Hours"]
70
  )
 
71
  total_energy_kwh = appliances_df["Daily Energy (Wh)"].sum() / 1000 # Convert to kWh
72
- peak_load_watts = appliances_df["Wattage (W)"].sum() # Peak load in watts
73
 
74
  # Solar System Inputs
75
  st.subheader("Solar System Configuration")
@@ -79,19 +93,19 @@ if st.session_state.appliances:
79
 
80
  # Solar Panel Calculation
81
  total_panel_wattage = total_energy_kwh / (sunlight_hours * panel_efficiency)
82
- number_of_panels = int(total_panel_wattage / 400) # Assuming 400W panels
83
 
84
  # Battery Calculation
85
  battery_capacity_ah = (total_energy_kwh * battery_backup_hours * 1000) / 12 # Assuming 12V batteries
86
  number_of_batteries = int(battery_capacity_ah / 200) # Assuming 200Ah batteries
87
 
88
  # Inverter Calculation
89
- inverter_size_kw = peak_load_watts / 1000 # Convert to kW
90
 
91
  # Display Results
92
  st.markdown("<hr>", unsafe_allow_html=True)
93
  st.markdown("<h2 style='color: #FF5722;'>System Recommendations</h2>", unsafe_allow_html=True)
94
- st.write(f"**Total Energy Consumption:** {total_energy_kwh:.2f} kWh/day")
95
  st.write(f"**Required Solar Panel Capacity:** {total_panel_wattage:.2f} W")
96
  st.write(f"**Number of Solar Panels (550W each):** {number_of_panels}")
97
  st.write(f"**Battery Capacity Needed:** {battery_capacity_ah:.2f} Ah")
@@ -114,3 +128,4 @@ st.markdown(
114
  )
115
 
116
 
 
 
7
  unsafe_allow_html=True,
8
  )
9
  st.write(
10
+ "This app helps you calculate the total load and suggests a solar panel, inverter, and battery configuration for your home or office."
11
  )
12
 
13
  # Sidebar for Appliance Input
14
  st.sidebar.header("Add Appliance Details")
15
 
16
+ # Predefined Appliance List with Serial Numbers
17
  appliance_list = [
18
+ "1. LED Bulb",
19
+ "2. Fan",
20
+ "3. LED TV",
21
+ "4. Computer",
22
+ "5. Refrigerator",
23
+ "6. Washing Machine",
24
+ "7. Water Pump",
25
+ "8. Iron",
26
+ "9. Microwave Oven",
27
+ "10. Water Dispenser",
28
+ "11. Geyser",
29
+ "12. Heater",
30
+ "13. Dishwasher",
31
+ "14. Inverter AC",
32
+ "15. Others",
33
  ]
34
 
35
  # Input Fields
36
  appliance_name = st.sidebar.selectbox("Select Appliance", appliance_list)
37
+ if appliance_name == "15. Others":
38
  appliance_name = st.sidebar.text_input("Enter Appliance Name", "")
39
  wattage = st.sidebar.number_input("Wattage (Watts)", min_value=1, value=10)
40
  quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
 
49
  if appliance_name:
50
  st.session_state.appliances.append(
51
  {
52
+ "Appliance": appliance_name.split(". ")[-1],
53
  "Wattage (W)": wattage,
54
  "Quantity": quantity,
55
  "Usage Hours": usage_hours,
 
64
  appliances_df = pd.DataFrame(st.session_state.appliances)
65
  st.table(appliances_df)
66
 
67
+ # Remove Appliance Option
68
+ remove_index = st.number_input(
69
+ "Enter the row number to remove an appliance (starting from 0):", min_value=0, max_value=len(appliances_df)-1, step=1
70
+ )
71
+ remove_button = st.button("Remove Appliance")
72
+ if remove_button:
73
+ if 0 <= remove_index < len(st.session_state.appliances):
74
+ del st.session_state.appliances[remove_index]
75
+ st.success("Appliance removed successfully!")
76
+ else:
77
+ st.error("Invalid row number.")
78
+
79
+ # If Appliances List is Not Empty, Perform Calculations
80
+ if st.session_state.appliances:
81
  # Calculations
82
  appliances_df["Daily Energy (Wh)"] = (
83
  appliances_df["Wattage (W)"] * appliances_df["Quantity"] * appliances_df["Usage Hours"]
84
  )
85
+ total_load_watts = appliances_df["Wattage (W)"].sum() # Total load in watts
86
  total_energy_kwh = appliances_df["Daily Energy (Wh)"].sum() / 1000 # Convert to kWh
 
87
 
88
  # Solar System Inputs
89
  st.subheader("Solar System Configuration")
 
93
 
94
  # Solar Panel Calculation
95
  total_panel_wattage = total_energy_kwh / (sunlight_hours * panel_efficiency)
96
+ number_of_panels = int(total_panel_wattage / 550) # Assuming 550W panels
97
 
98
  # Battery Calculation
99
  battery_capacity_ah = (total_energy_kwh * battery_backup_hours * 1000) / 12 # Assuming 12V batteries
100
  number_of_batteries = int(battery_capacity_ah / 200) # Assuming 200Ah batteries
101
 
102
  # Inverter Calculation
103
+ inverter_size_kw = total_load_watts / 1000 # Convert to kW
104
 
105
  # Display Results
106
  st.markdown("<hr>", unsafe_allow_html=True)
107
  st.markdown("<h2 style='color: #FF5722;'>System Recommendations</h2>", unsafe_allow_html=True)
108
+ st.write(f"**Total Load:** {total_load_watts:.2f} Watts")
109
  st.write(f"**Required Solar Panel Capacity:** {total_panel_wattage:.2f} W")
110
  st.write(f"**Number of Solar Panels (550W each):** {number_of_panels}")
111
  st.write(f"**Battery Capacity Needed:** {battery_capacity_ah:.2f} Ah")
 
128
  )
129
 
130
 
131
+