File size: 3,881 Bytes
b555fe1
 
 
b0848d8
b555fe1
 
 
0b6ddc5
b555fe1
 
cd574eb
b555fe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0848d8
b555fe1
 
b0848d8
 
b555fe1
b0848d8
 
 
 
 
 
 
 
 
 
 
 
b555fe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0848d8
b555fe1
b0848d8
b555fe1
 
 
 
 
 
 
b88957c
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
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import openai

# Load the solar data CSV file
df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')

# Set up the Gemini API (replace with your actual API key)
openai.api_key = 'your_openai.api_key_here'

# Function to get solar radiation and tariff based on user input location
def get_state_data(state_name):
    state_data = df[df['State'].str.contains(state_name, case=False)]
    if state_data.empty:
        return None
    return state_data.iloc[0]

# Function to estimate solar system size (in kW)
def estimate_system_size(roof_size, ghi):
    # Simple formula: 1 kW system needs about 10-12 sq meters of roof space
    system_size = roof_size / 10  # in kW (assuming 10 sq meters = 1 kW)
    estimated_output = ghi * system_size  # kWh per day
    return system_size, estimated_output

# Function to calculate cost, savings, and payback period
def estimate_cost_and_savings(system_size, state_data, electricity_bill):
    # Cost per kW (₹)
    solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
    # Total solar system cost
    system_cost = system_size * solar_cost_per_kw
    # Savings per month assuming 100% replacement of electricity bill
    savings_per_month = electricity_bill
    # Payback period in months
    payback_period = system_cost / (savings_per_month * 12)
    
    return system_cost, savings_per_month, payback_period

# Streamlit UI
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
st.title("AI-based Solar Project Estimation Tool")

# Center all input widgets
st.write("### Enter Your Details Below:")

with st.form("solar_form"):
    # Get the list of unique states from the dataset
    state_options = df['State'].dropna().unique()
    
    # Input widgets
    location = st.selectbox("Select your State", options=sorted(state_options))
    roof_size = st.number_input("Enter your roof size (in sq meters)", min_value=1)
    electricity_bill = st.number_input("Enter your monthly electricity bill (₹)", min_value=0)
    
    submitted = st.form_submit_button("Get Estimate")

if submitted and location and roof_size > 0 and electricity_bill >= 0:
    # Fetch state data from the dataset
    state_data = get_state_data(location)
    if state_data is not None:
        ghi = state_data['Avg_GHI (kWh/m²/day)']
        
        # Estimate solar system size and output
        system_size, estimated_output = estimate_system_size(roof_size, ghi)
        
        # Estimate cost, savings, and payback period
        system_cost, savings_per_month, payback_period = estimate_cost_and_savings(system_size, state_data, electricity_bill)
        
        # Display results
        st.subheader("Estimated Solar System Details:")
        st.write(f"**Location**: {location}")
        st.write(f"**System Size**: {system_size:.2f} kW")
        st.write(f"**Estimated Daily Output**: {estimated_output:.2f} kWh/day")
        st.write(f"**Total System Cost**: ₹{system_cost:,.2f}")
        st.write(f"**Monthly Savings**: ₹{savings_per_month:,.2f}")
        st.write(f"**Payback Period**: {payback_period:.2f} years")
        
        # Plot savings and payback period
        fig, ax = plt.subplots()
        ax.bar(['Total System Cost', 'Monthly Savings', 'Payback Period (months)'], 
               [system_cost, savings_per_month, payback_period*12], color=['blue', 'green', 'orange'])
        ax.set_ylabel("Amount (₹) / Time (Months)")
        ax.set_title("Solar System Estimation Breakdown")
        st.pyplot(fig)
        
    else:
        st.error("Sorry, the location entered does not match any available data.")
else:
    st.warning("Please fill out all fields to see your solar project estimate.")