File size: 4,220 Bytes
b555fe1 a851214 372b3f3 0cdc019 23fc541 bd3fb72 0cdc019 618f85b bd3fb72 c565f89 27cc353 bd3fb72 0cdc019 618f85b 0cdc019 372b3f3 a851214 b555fe1 a851214 27cc353 bd3fb72 b555fe1 bd3fb72 b555fe1 b0848d8 2d29e28 b0848d8 bd3fb72 b0848d8 bd3fb72 2d29e28 5aee751 54c70ee b555fe1 822b684 bd3fb72 b555fe1 bd3fb72 d36a0d6 bd3fb72 e799f84 bd3fb72 e799f84 bd3fb72 b555fe1 bd3fb72 b555fe1 bd3fb72 |
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 |
import streamlit as st
import pandas as pd
import google.generativeai as genai
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Set page configuration
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
# Initialize Gemini
api_key = os.getenv("GOOGLE_API_KEY")
if api_key:
genai.configure(api_key=api_key)
else:
st.error("API key is missing. Please set the GOOGLE_API_KEY environment variable.")
model = genai.GenerativeModel("gemini-1.5-flash")
# Load solar data
@st.cache_data
def load_data():
df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')
return df
df = load_data()
# Solar Calculation Function (not relying on Gemini for calculation)
def calculate_solar_estimate(roof_size, monthly_bill, electricity_price, ghi, cost_per_kw):
daily_consumption_inr = monthly_bill / 30
daily_consumption_kwh = daily_consumption_inr / electricity_price
# Assume system size based on consumption
estimated_system_size_kw = 3 # Fixed for now as realistic estimate
peak_sun_hours = ghi # Use GHI as sun hours (approximation)
daily_solar_output_kwh = estimated_system_size_kw * peak_sun_hours * 0.75 # considering derating factor
total_system_cost = estimated_system_size_kw * cost_per_kw
monthly_generation_kwh = daily_solar_output_kwh * 30
monthly_savings_inr = monthly_generation_kwh * electricity_price
annual_savings_inr = monthly_savings_inr * 12
payback_period_years = total_system_cost / annual_savings_inr
return {
"Estimated solar system size in kW": round(estimated_system_size_kw, 2),
"Estimated daily solar output in kWh": round(daily_solar_output_kwh, 2),
"Total system cost in ₹": int(total_system_cost),
"Monthly savings in ₹": int(monthly_savings_inr),
"Payback period in years": round(payback_period_years, 2)
}
# UI - Form
st.title("AI-based Solar Project Estimation Tool")
st.write("### Enter Your Details:")
with st.form("solar_form"):
state_options = df['State'].dropna().unique()
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)
monthly_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 monthly_bill >= 0:
state_data = df[df['State'].str.contains(location, case=False)].iloc[0]
if state_data is not None:
ghi = state_data['Avg_GHI (kWh/m²/day)']
solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
electricity_price = 8 # Assume ₹8/kWh
# Calculate estimates
estimates = calculate_solar_estimate(roof_size, monthly_bill, electricity_price, ghi, solar_cost_per_kw)
# Build clean prompt for Gemini to verify the calculation
prompt = f"""
ONLY output these 5 points based on inputs:
1. Estimated solar system size in kW
2. Estimated daily solar output in kWh
3. Total system cost in ₹
4. Monthly savings in ₹
5. Payback period in years
Roof size = {roof_size} sq meters
Monthly bill = ₹{monthly_bill}
GHI = {ghi} kWh/m²/day
Solar system cost per kW = ₹{solar_cost_per_kw}
Use no description. Only numeric values clearly.
"""
# Call Gemini API (just to double-check/validate if you want)
with st.spinner("Generating final estimate..."):
gemini_response = model.generate_content(prompt)
final_response = gemini_response.text.strip()
# Display calculated values directly (without trusting Gemini text output)
st.subheader("Solar Project Estimate")
for key, value in estimates.items():
st.write(f"{key}: {value}")
else:
st.error("Location data not found. Please select a valid state.")
else:
st.warning("Please fill all the fields.")
|