Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import openai
|
6 |
+
|
7 |
+
# Load the solar data CSV file
|
8 |
+
df = pd.read_csv('solar_data_india_2024.csv')
|
9 |
+
|
10 |
+
# Set up the Gemini API (replace with your actual API key)
|
11 |
+
openai.api_key = 'your_gemini_api_key_here'
|
12 |
+
|
13 |
+
# Function to get solar radiation and tariff based on user input location
|
14 |
+
def get_state_data(state_name):
|
15 |
+
state_data = df[df['State'].str.contains(state_name, case=False)]
|
16 |
+
if state_data.empty:
|
17 |
+
return None
|
18 |
+
return state_data.iloc[0]
|
19 |
+
|
20 |
+
# Function to estimate solar system size (in kW)
|
21 |
+
def estimate_system_size(roof_size, ghi):
|
22 |
+
# Simple formula: 1 kW system needs about 10-12 sq meters of roof space
|
23 |
+
system_size = roof_size / 10 # in kW (assuming 10 sq meters = 1 kW)
|
24 |
+
estimated_output = ghi * system_size # kWh per day
|
25 |
+
return system_size, estimated_output
|
26 |
+
|
27 |
+
# Function to calculate cost, savings, and payback period
|
28 |
+
def estimate_cost_and_savings(system_size, state_data, electricity_bill):
|
29 |
+
# Cost per kW (₹)
|
30 |
+
solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
|
31 |
+
# Total solar system cost
|
32 |
+
system_cost = system_size * solar_cost_per_kw
|
33 |
+
# Savings per month assuming 100% replacement of electricity bill
|
34 |
+
savings_per_month = electricity_bill
|
35 |
+
# Payback period in months
|
36 |
+
payback_period = system_cost / (savings_per_month * 12)
|
37 |
+
|
38 |
+
return system_cost, savings_per_month, payback_period
|
39 |
+
|
40 |
+
# Streamlit UI
|
41 |
+
st.title("AI-based Solar Project Estimation Tool")
|
42 |
+
|
43 |
+
# User input form
|
44 |
+
st.sidebar.header("Enter Your Details")
|
45 |
+
location = st.sidebar.text_input("Enter your city or state", "")
|
46 |
+
roof_size = st.sidebar.number_input("Enter your roof size (in sq meters)", min_value=1)
|
47 |
+
electricity_bill = st.sidebar.number_input("Enter your monthly electricity bill (₹)", min_value=0)
|
48 |
+
|
49 |
+
if location and roof_size > 0 and electricity_bill >= 0:
|
50 |
+
# Fetch state data from the dataset
|
51 |
+
state_data = get_state_data(location)
|
52 |
+
if state_data is not None:
|
53 |
+
ghi = state_data['Avg_GHI (kWh/m²/day)']
|
54 |
+
|
55 |
+
# Estimate solar system size and output
|
56 |
+
system_size, estimated_output = estimate_system_size(roof_size, ghi)
|
57 |
+
|
58 |
+
# Estimate cost, savings, and payback period
|
59 |
+
system_cost, savings_per_month, payback_period = estimate_cost_and_savings(system_size, state_data, electricity_bill)
|
60 |
+
|
61 |
+
# Display results
|
62 |
+
st.subheader("Estimated Solar System Details:")
|
63 |
+
st.write(f"**Location**: {location}")
|
64 |
+
st.write(f"**System Size**: {system_size:.2f} kW")
|
65 |
+
st.write(f"**Estimated Daily Output**: {estimated_output:.2f} kWh/day")
|
66 |
+
st.write(f"**Total System Cost**: ₹{system_cost:,.2f}")
|
67 |
+
st.write(f"**Monthly Savings**: ₹{savings_per_month:,.2f}")
|
68 |
+
st.write(f"**Payback Period**: {payback_period:.2f} years")
|
69 |
+
|
70 |
+
# Plot savings and payback period
|
71 |
+
fig, ax = plt.subplots()
|
72 |
+
ax.bar(['Total System Cost', 'Monthly Savings', 'Payback Period'],
|
73 |
+
[system_cost, savings_per_month, payback_period*12], color=['blue', 'green', 'orange'])
|
74 |
+
ax.set_ylabel("Amount (₹) / Time (years)")
|
75 |
+
ax.set_title("Solar System Estimation Breakdown")
|
76 |
+
st.pyplot(fig)
|
77 |
+
|
78 |
+
else:
|
79 |
+
st.error("Sorry, the location entered does not match any available data.")
|
80 |
+
else:
|
81 |
+
st.warning("Please fill out all fields to see your solar project estimate.")
|