Spaces:
Sleeping
Sleeping
File size: 4,791 Bytes
2be0feb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | import streamlit as st
import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
import numpy_financial as npf
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import getSampleStyleSheet
# ===============================
# PAGE CONFIG
# ===============================
st.set_page_config(layout="wide")
st.title("π΅π° AI Solar Intelligence Platform (Ultra Premium)")
# ===============================
# ADVANCED CONFIG
# ===============================
SYSTEM_LOSSES = 0.20
DEMAND_FACTOR_INDUSTRIAL = 0.75
CITY_IRRADIANCE_INDEX = {
"Karachi": 6.2,
"Lahore": 5.5,
"Islamabad": 5.2,
"Peshawar": 5.6,
"Quetta": 6.5,
}
# Pricing
PANEL_COST_PER_WATT = 55
INSTALLATION_COST_PER_WATT = 35
BATTERY_COST_5KWH = 95000
# Appliance Database (Expanded)
LOAD_LIBRARY = {
"Home": {
"Lighting": 60,
"Fans": 400,
"Fridge": 200,
"AC": 1500
},
"Industrial": {
"Motors": 5000,
"Compressors": 8000,
"CNC Machines": 2000
}
}
# ===============================
# AI RECOMMENDATION ENGINE
# ===============================
def ai_solar_recommendation(load_kw, sunlight):
optimal_system = (load_kw / sunlight) * 1.2
return round(optimal_system, 2)
def financial_projection(cost, daily_kwh):
cashflows = []
for year in range(1, 26):
price_escalation = (1 + 0.07) ** year
savings = daily_kwh * 30 * 55 * price_escalation
cashflows.append(savings * 12)
npv = npf.npv(0.05, [-cost] + cashflows)
irr = npf.irr([-cost] + cashflows)
payback = next((i for i, cf in enumerate(np.cumsum(cashflows), 1)
if cf >= cost), None)
return cashflows, npv, irr, payback, np.cumsum(cashflows)
# ===============================
# USER INPUT LAYER
# ===============================
user_type = st.selectbox(
"Select Client Type",
["Homeowner", "Commercial Business", "Industrial Investor"]
)
city = st.selectbox("Select City", list(CITY_IRRADIANCE_INDEX.keys()))
sunlight = CITY_IRRADIANCE_INDEX[city]
# Load Selection
if user_type == "Homeowner":
load_choice = st.multiselect(
"Select Home Loads",
["Lighting", "Fans", "Fridge", "AC"]
)
elif user_type == "Commercial Business":
load_choice = st.multiselect(
"Select Business Loads",
["Lighting", "Computers", "AC", "Machinery"]
)
else:
load_choice = st.multiselect(
"Select Industrial Loads",
["Motors", "Compressors", "CNC Machines"]
)
hours = st.slider("Daily Usage Hours", 1, 24, 8)
# ===============================
# CALCULATIONS
# ===============================
if st.button("π Run AI Solar Analysis"):
if len(load_choice) == 0:
st.error("Please select at least one load")
else:
# Load estimation
load_watts = 0
for item in load_choice:
if item in ["Lighting", "Fans"]:
load_watts += 200
elif item == "Fridge":
load_watts += 200
elif item == "AC":
load_watts += 1500
elif item in ["Motors", "Compressors", "CNC Machines"]:
load_watts += 3000
daily_kwh = (load_watts * hours) / 1000
daily_kwh = daily_kwh / (1 - SYSTEM_LOSSES)
# AI Recommendation
system_kw = ai_solar_recommendation(daily_kwh, sunlight)
system_cost = system_kw * 1000 * (PANEL_COST_PER_WATT + INSTALLATION_COST_PER_WATT)
# Financials
cashflows, npv, irr, payback, cumulative = financial_projection(system_cost, daily_kwh)
# Results Display
st.subheader("π AI Analysis Results")
st.write(f"Recommended Solar System Size: {system_kw} kW")
st.write(f"Daily Energy Consumption: {round(daily_kwh,2)} kWh")
st.write(f"Estimated Installation Cost: PKR {round(system_cost):,}")
st.write(f"NPV (25 Years): PKR {round(npv,2):,}")
st.write(f"IRR: {round(irr*100,2)} %")
st.write(f"Payback Period: {payback} Years")
# Charts
st.subheader("π Investment Growth Projection")
plt.figure(figsize=(10,4))
plt.plot(range(1,26), cumulative)
plt.axhline(system_cost, linestyle="--")
st.pyplot(plt)
# WhatsApp Style Summary
st.subheader("π± Proposal Summary")
summary_text = f"""
Solar Proposal Summary
City: {city}
Recommended System: {system_kw} kW
Cost Estimate: PKR {round(system_cost):,}
Payback Period: {payback} Years
IRR: {round(irr*100,2)}%
"""
st.text_area("Copy for WhatsApp / Proposal", summary_text, height=200) |