Talha812 commited on
Commit
201a226
ยท
verified ยท
1 Parent(s): 4afe70a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +154 -0
app.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ from fpdf import FPDF
6
+
7
+ # --- Appliance power ratings (in watts) ---
8
+ appliance_power = {
9
+ "Fan": 75,
10
+ "LED Light": 15,
11
+ "Refrigerator": 150,
12
+ "TV": 100,
13
+ "Air Conditioner": 1000,
14
+ "Washing Machine": 500,
15
+ "Computer": 200
16
+ }
17
+
18
+ st.set_page_config(page_title="Solar Energy Planner", layout="wide")
19
+
20
+ st.title("โ˜€๏ธ Solar Energy Consumption & Planning App")
21
+
22
+ # --- Sidebar: User Inputs ---
23
+ st.sidebar.header("๐Ÿ”Œ Appliance Load Input")
24
+
25
+ appliance_data = []
26
+ for appliance, watt in appliance_power.items():
27
+ qty = st.sidebar.number_input(f"{appliance} Quantity", 0, 20, 0, key=f"{appliance}_qty")
28
+ hours = st.sidebar.number_input(f"{appliance} Daily Hours", 0, 24, 0, key=f"{appliance}_hours")
29
+ if qty > 0 and hours > 0:
30
+ appliance_data.append({
31
+ "Appliance": appliance,
32
+ "Qty": qty,
33
+ "Hours": hours,
34
+ "Watt": watt,
35
+ "Daily kWh": round(qty * hours * watt / 1000, 2)
36
+ })
37
+
38
+ # Default values
39
+ total_daily_kwh = 0
40
+ total_monthly_kwh = 0
41
+ num_panels = 0
42
+
43
+ # --- Show appliance usage table ---
44
+ if appliance_data:
45
+ st.subheader("๐Ÿงฎ Appliance-wise Energy Consumption")
46
+ df = pd.DataFrame(appliance_data)
47
+ df["Monthly kWh"] = df["Daily kWh"] * 30
48
+ st.dataframe(df, use_container_width=True)
49
+
50
+ total_daily_kwh = df["Daily kWh"].sum()
51
+ total_monthly_kwh = df["Monthly kWh"].sum()
52
+
53
+ st.metric("๐Ÿ”‹ Total Daily Consumption (kWh)", round(total_daily_kwh, 2))
54
+ st.metric("๐Ÿ“… Total Monthly Consumption (kWh)", round(total_monthly_kwh, 2))
55
+ else:
56
+ st.info("Please enter appliance details in the sidebar to start.")
57
+
58
+ # --- Solar Panel Calculator ---
59
+ st.subheader("โ˜€๏ธ Solar Panel Requirement Calculator")
60
+ avg_sunlight_hours = st.number_input("Average Sunlight Hours/Day", 1.0, 12.0, 5.5)
61
+ panel_watt = st.number_input("Panel Wattage (W)", 100, 600, 300)
62
+
63
+ if total_daily_kwh > 0:
64
+ kwh_per_panel = round((panel_watt * avg_sunlight_hours) / 1000, 2)
65
+ num_panels = int(np.ceil(total_daily_kwh / kwh_per_panel))
66
+ st.success(f"You need approximately **{num_panels}** panels of {panel_watt}W to cover {round(total_daily_kwh, 2)} kWh/day.")
67
+ st.caption(f"Each panel generates approx. {kwh_per_panel} kWh/day.")
68
+
69
+ # --- Tilt Angle Calculator ---
70
+ st.subheader("๐Ÿ“ Recommended Tilt Angle")
71
+ latitude = st.number_input("Enter Latitude of Your Location", -90.0, 90.0, 30.0)
72
+ tilt_year = round(latitude * 0.9, 1)
73
+ tilt_summer = round(latitude * 0.7, 1)
74
+ tilt_winter = round(latitude * 1.1, 1)
75
+
76
+ st.markdown(f"""
77
+ - ๐Ÿ“Œ **Year-round Tilt Angle**: `{tilt_year}ยฐ`
78
+ - ๐ŸŒž **Summer Tilt**: `{tilt_summer}ยฐ`
79
+ - โ„๏ธ **Winter Tilt**: `{tilt_winter}ยฐ`
80
+ """)
81
+
82
+ # --- Graphs: Weekly and Monthly Consumption ---
83
+ if total_daily_kwh > 0:
84
+ st.subheader("๐Ÿ“Š Energy Consumption Overview")
85
+
86
+ week_days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
87
+ weekly_kwh = [round(total_daily_kwh + np.random.uniform(-0.3, 0.3), 2) for _ in range(7)]
88
+
89
+ fig1, ax1 = plt.subplots()
90
+ ax1.bar(week_days, weekly_kwh, color='skyblue')
91
+ ax1.set_ylabel("kWh")
92
+ ax1.set_title("Weekly Consumption")
93
+ st.pyplot(fig1)
94
+
95
+ months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
96
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
97
+ monthly_kwh = [round(total_daily_kwh * 30 + np.random.uniform(-5, 5), 2) for _ in range(12)]
98
+
99
+ fig2, ax2 = plt.subplots()
100
+ ax2.plot(months, monthly_kwh, marker='o', color='green')
101
+ ax2.set_ylabel("kWh")
102
+ ax2.set_title("Monthly Consumption")
103
+ st.pyplot(fig2)
104
+
105
+ # --- Roof Area Estimator ---
106
+ st.subheader("๐Ÿ  Roof Area & Panel Capacity")
107
+ roof_area = st.number_input("Enter Available Roof Area (sq. ft)", 0, 1000, 200)
108
+ panel_area = 18 # Average panel size (sq. ft)
109
+ max_panels_fit = int(roof_area / panel_area)
110
+ max_capacity_kw = round((max_panels_fit * panel_watt) / 1000, 2)
111
+
112
+ st.markdown(f"""
113
+ - Max panels installable: `{max_panels_fit}`
114
+ - Max capacity: `{max_capacity_kw} kW`
115
+ """)
116
+
117
+ # --- Battery Estimator ---
118
+ st.subheader("๐Ÿ”‹ Battery Backup Estimator")
119
+ if total_daily_kwh > 0:
120
+ backup_hours = st.slider("Backup Hours Required", 1, 24, 6)
121
+ avg_load_kw = total_daily_kwh / 24
122
+ battery_size_kwh = round(avg_load_kw * backup_hours, 2)
123
+ battery_ah_12v = round((battery_size_kwh * 1000) / 12, 0)
124
+
125
+ st.markdown(f"""
126
+ - Required Battery Size: **{battery_size_kwh} kWh**
127
+ - Battery (12V): **{battery_ah_12v} Ah**
128
+ """)
129
+ else:
130
+ st.info("Add appliance details first to calculate battery backup.")
131
+
132
+ # --- Cost and ROI Estimator ---
133
+ st.subheader("๐Ÿ’ฐ Cost & ROI Estimator")
134
+ unit_cost = st.number_input("Grid Cost per Unit (kWh)", 5.0, 50.0, 20.0)
135
+ panel_cost = st.number_input("Cost per Panel (PKR)", 10000, 100000, 40000)
136
+ installation_cost = st.number_input("Installation Cost (PKR)", 0, 100000, 20000)
137
+
138
+ if num_panels > 0:
139
+ total_cost = int(num_panels) * panel_cost + installation_cost
140
+ monthly_saving = round(total_daily_kwh * 30 * unit_cost, 0)
141
+ roi_months = round(total_cost / monthly_saving, 1)
142
+
143
+ st.markdown(f"""
144
+ - ๐Ÿ’ธ Total System Cost: **PKR {total_cost:,}**
145
+ - ๐Ÿ’ต Estimated Monthly Savings: **PKR {monthly_saving:,}**
146
+ - ๐Ÿ“ˆ ROI / Break-even in: **{roi_months} months**
147
+ """)
148
+ else:
149
+ st.info("Add appliances and sunlight hours to calculate panel requirements.")
150
+
151
+ # --- Footer ---
152
+ st.markdown("---")
153
+ st.caption("Developed with โค๏ธ using Streamlit | Ready for Hugging Face Deployment")
154
+