| | import streamlit as st |
| | import pandas as pd |
| | import numpy as np |
| | import matplotlib.pyplot as plt |
| | import os |
| | import requests |
| | from dotenv import load_dotenv |
| |
|
| | |
| | load_dotenv() |
| |
|
| | |
| | GEMINI_API_KEY = os.getenv("GEMINI_API_KEY") |
| |
|
| | |
| | GEMINI_API_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent" |
| |
|
| | |
| | df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv') |
| |
|
| | |
| | st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered") |
| | st.title("AI-based Solar Project Estimation Tool") |
| |
|
| | st.write("### Enter Your Details Below:") |
| |
|
| | 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) |
| | 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: |
| | 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 (₹)'] |
| | |
| | prompt_text = f""" |
| | Estimate the solar system for the location '{location}' based on the following details: |
| | - Roof size: {roof_size} sq meters |
| | - Monthly electricity bill: ₹{electricity_bill} |
| | - Average GHI (solar radiation) for {location}: {ghi} kWh/m²/day |
| | - Solar system cost per kW in {location}: ₹{solar_cost_per_kw} |
| | |
| | Provide: |
| | 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 |
| | """ |
| |
|
| | |
| | headers = { |
| | "Authorization": f"Bearer {GEMINI_API_KEY}", |
| | "Content-Type": "application/json" |
| | } |
| |
|
| | |
| | payload = { |
| | "model": "gemini-1.5-flash", |
| | "messages": [{"role": "system", "content": "You are a helpful assistant."}, |
| | {"role": "user", "content": prompt_text}], |
| | "temperature": 0.7 |
| | } |
| |
|
| | |
| | response = requests.post(GEMINI_API_URL, json=payload, headers=headers) |
| |
|
| | |
| | if response.status_code == 200: |
| | result = response.json() |
| | generated_content = result['choices'][0]['message']['content'] |
| | |
| | |
| | st.subheader("Solar Project Estimate") |
| | st.write(generated_content) |
| | else: |
| | st.error(f"Error: {response.status_code} - {response.text}") |
| | |
| | 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.") |
| |
|