arsalan16 commited on
Commit
03f1aea
·
verified ·
1 Parent(s): 1d19382

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -122
app.py CHANGED
@@ -1,131 +1,93 @@
1
  import streamlit as st
 
 
2
  import pandas as pd
3
  import numpy as np
4
- from sympy import symbols, solve
5
- import pvlib
6
-
7
- # App Title
8
- st.markdown(
9
- "<h1 style='text-align: center; color: #4CAF50;'>SolarEase: Hybrid Solar System Planner</h1>",
10
- unsafe_allow_html=True,
11
- )
12
- st.write(
13
- "This app helps you calculate the total load and provides recommendations for a hybrid solar system, including solar panels, inverter size, and battery configuration."
14
- )
15
-
16
- # Sidebar for Appliance Input
17
- st.sidebar.header("Add Appliance Details")
18
-
19
- # Predefined Appliance List with Serial Numbers
20
- appliance_list = [
21
- "1. LED Bulb",
22
- "2. Fan",
23
- "3. LED TV",
24
- "4. Computer",
25
- "5. Refrigerator",
26
- "6. Washing Machine",
27
- "7. Water Pump",
28
- "8. Iron",
29
- "9. Microwave Oven",
30
- "10. Water Dispenser",
31
- "11. Geyser",
32
- "12. Heater",
33
- "13. Dishwasher",
34
- "14. Inverter AC",
35
- "15. Others",
36
- ]
37
-
38
- # Input Fields
39
- appliance_name = st.sidebar.selectbox("Select Appliance", appliance_list)
40
- if appliance_name == "15. Others":
41
- appliance_name = st.sidebar.text_input("Enter Appliance Name", "")
42
- wattage = st.sidebar.number_input("Wattage (Watts)", min_value=1, value=10)
43
- quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
44
- usage_hours = st.sidebar.number_input("Daily Usage Hours", min_value=1, value=1)
45
- add_button = st.sidebar.button("Add Appliance")
46
-
47
- # Session State for Storing Appliances
48
- if "appliances" not in st.session_state:
49
- st.session_state.appliances = []
50
-
51
- if add_button:
52
- if appliance_name:
53
- st.session_state.appliances.append(
54
- {
55
- "Appliance": appliance_name.split(". ")[-1],
56
- "Wattage (W)": wattage,
57
- "Quantity": quantity,
58
- "Usage Hours": usage_hours,
59
- }
60
- )
61
- else:
62
- st.sidebar.error("Please enter the appliance name.")
63
-
64
- # Display Appliance Table
65
- if st.session_state.appliances:
66
- st.subheader("Appliance Details")
67
- appliances_df = pd.DataFrame(st.session_state.appliances)
68
- st.table(appliances_df)
69
-
70
- # If Appliances List is Not Empty, Perform Calculations
71
- if st.session_state.appliances:
72
- # Calculations
73
- appliances_df["Daily Energy (Wh)"] = (
74
- appliances_df["Wattage (W)"] * appliances_df["Quantity"] * appliances_df["Usage Hours"]
75
- )
76
- total_load_watts = appliances_df["Wattage (W)"].sum() # Total load in watts
77
- total_energy_kwh = appliances_df["Daily Energy (Wh)"].sum() / 1000 # Convert to kWh
78
-
79
- # Solar System Inputs
80
- st.subheader("Solar System Configuration")
81
- sunlight_hours = st.slider("Average Sunlight Hours", min_value=4, max_value=10, value=6)
82
- battery_backup_hours = st.slider("Battery Backup Time (Hours)", min_value=1, max_value=24, value=4)
83
-
84
- # Accurate Solar Panel and Battery Calculations
85
- solar_panel_capacity_w = 550 # 550W solar panel
86
- energy_per_day_kwh = total_energy_kwh
87
- daily_solar_output_kwh = solar_panel_capacity_w * sunlight_hours / 1000 # in kWh
88
- number_of_solar_panels = int(np.ceil(energy_per_day_kwh / daily_solar_output_kwh))
89
-
90
- # Battery Calculation
91
- system_voltage = 48 # Assuming a 48V system for efficiency
92
- total_battery_capacity_ah = (energy_per_day_kwh * 1000) / system_voltage # in Ah
93
- number_of_batteries = int(np.ceil((total_battery_capacity_ah * battery_backup_hours) / 200)) # Assuming 200Ah batteries
94
-
95
- # Inverter Size
96
- inverter_size_kw = total_load_watts / 1000 # Convert to kW
97
-
98
- # Display Results
99
- st.markdown("<hr>", unsafe_allow_html=True)
100
- st.markdown("<h2 style='color: #FF5722;'>System Recommendations</h2>", unsafe_allow_html=True)
101
- st.write(f"**Total Load:** {total_load_watts:.2f} Watts")
102
- st.write(f"**Number of Solar Panels (550W each):** {number_of_solar_panels}")
103
- st.write(f"**Number of Batteries (200Ah each):** {number_of_batteries}")
104
- st.write(f"**Inverter Size Required:** {inverter_size_kw:.2f} kW")
105
-
106
- # Suggestions for Solar System Design
107
- st.markdown("<h3 style='color: #3F51B5;'>Design Suggestions:</h3>", unsafe_allow_html=True)
108
  suggestions = [
109
- "Use monocrystalline panels for better efficiency.",
110
- "Install a charge controller to prevent overcharging the batteries.",
111
- "Ensure the inverter size is 20-30% higher than the total load.",
112
- "Use MPPT (Maximum Power Point Tracking) technology for optimal solar output.",
113
- "Consider lithium-ion batteries for better energy density and lifespan.",
114
- "Install panels at an optimal tilt angle based on your location.",
115
- "Clean solar panels regularly to maintain performance.",
116
- "Invest in a hybrid inverter to switch between solar, grid, and battery power.",
117
- "Consult a certified solar installer for professional system design.",
118
- "Ensure proper wiring and safety measures for long-term reliability.",
119
  ]
120
  for suggestion in suggestions:
121
- st.write(f"- {suggestion}")
122
-
123
- # Footer
124
- st.markdown("<hr>", unsafe_allow_html=True)
125
- st.markdown(
126
- "<p style='text-align: center; color: #9C27B0;'>Developed by <strong>Engr. Muhammad Arsalan</strong></p>",
127
- unsafe_allow_html=True,
128
- )
129
 
130
 
131
 
 
1
  import streamlit as st
2
+ from grooq import Translator # Grooq translation API
3
+ from pvlib import location
4
  import pandas as pd
5
  import numpy as np
6
+
7
+ # Grooq Translator setup
8
+ translator = Translator(api_key="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") # Replace with your actual API key
9
+
10
+ # Function to handle translation
11
+ def translate(text, language):
12
+ return translator.translate(text, target_language=language)
13
+
14
+ # Set up the app
15
+ st.set_page_config(page_title="Solar System Designer", layout="centered", initial_sidebar_state="expanded")
16
+
17
+ # Language selection
18
+ languages = {"English": "en", "French": "fr", "Spanish": "es", "German": "de", "Chinese": "zh"}
19
+ selected_language = st.sidebar.selectbox("Select Language", options=list(languages.keys()))
20
+ lang_code = languages[selected_language]
21
+
22
+ # Title
23
+ st.title(translate("Solar System Designer", lang_code))
24
+
25
+ # Solar panel options
26
+ solar_panels = {
27
+ "300W": 300,
28
+ "400W": 400,
29
+ "550W": 550
30
+ }
31
+ selected_panel = st.selectbox(translate("Select Solar Panel Capacity", lang_code), options=list(solar_panels.keys()))
32
+ panel_capacity = solar_panels[selected_panel]
33
+
34
+ # Battery options
35
+ battery_types = {"Lithium-Ion": 95, "Lead-Acid": 80} # Efficiency ratings
36
+ selected_battery = st.selectbox(translate("Select Battery Type", lang_code), options=list(battery_types.keys()))
37
+ battery_efficiency = battery_types[selected_battery]
38
+
39
+ battery_voltages = [12, 24, 48]
40
+ selected_voltage = st.selectbox(translate("Select Battery Voltage", lang_code), options=battery_voltages)
41
+
42
+ # Appliance data input
43
+ st.subheader(translate("Enter Appliance Details", lang_code))
44
+ appliances = []
45
+
46
+ if "appliance_list" not in st.session_state:
47
+ st.session_state["appliance_list"] = []
48
+
49
+ appliance_name = st.text_input(translate("Appliance Name", lang_code))
50
+ appliance_power = st.number_input(translate("Power (Watts)", lang_code), min_value=1)
51
+ appliance_hours = st.number_input(translate("Usage Hours per Day", lang_code), min_value=1)
52
+
53
+ if st.button(translate("Add Appliance", lang_code)):
54
+ st.session_state["appliance_list"].append({
55
+ "name": appliance_name,
56
+ "power": appliance_power,
57
+ "hours": appliance_hours
58
+ })
59
+
60
+ if st.session_state["appliance_list"]:
61
+ st.table(st.session_state["appliance_list"])
62
+
63
+ # Calculate system recommendations
64
+ if st.button(translate("Calculate Recommendations", lang_code)):
65
+ total_load = sum([a["power"] * a["hours"] for a in st.session_state["appliance_list"]])
66
+ st.write(translate(f"Total Load in Watts: {total_load}", lang_code))
67
+
68
+ # Solar panels required
69
+ panels_required = np.ceil(total_load / (panel_capacity * 5)) # Assuming 5 peak sunlight hours
70
+ st.write(translate(f"Solar Panels Required: {panels_required}", lang_code))
71
+
72
+ # Battery capacity required
73
+ battery_capacity = np.ceil((total_load / battery_efficiency) / selected_voltage)
74
+ st.write(translate(f"Batteries Required: {battery_capacity} (Ah)", lang_code))
75
+
76
+ # Suggestions
77
+ st.subheader(translate("System Design Suggestions", lang_code))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  suggestions = [
79
+ "Consider using MPPT charge controllers for better efficiency.",
80
+ "Ensure panels are installed at the optimal tilt angle for your location.",
81
+ "Use high-quality cables to minimize energy losses.",
82
+ "Regularly clean solar panels to maintain performance.",
83
+ "Consider hybrid inverters for grid and off-grid compatibility.",
84
+ "Allow space for future system expansion.",
85
+ "Invest in reliable surge protection devices.",
86
+ "Ensure batteries are stored in a cool, ventilated area.",
 
 
87
  ]
88
  for suggestion in suggestions:
89
+ st.write(translate(suggestion, lang_code))
90
+
 
 
 
 
 
 
91
 
92
 
93