File size: 3,582 Bytes
b555fe1
 
 
b0848d8
b555fe1
 
27cc353
 
 
 
b555fe1
0b6ddc5
b555fe1
27cc353
 
 
 
 
b555fe1
 
b0848d8
b555fe1
 
b0848d8
 
b555fe1
b0848d8
 
 
 
 
 
 
 
 
 
 
 
b555fe1
5aee751
 
b555fe1
 
5aee751
b555fe1
27cc353
5aee751
 
 
 
 
 
b555fe1
5aee751
 
 
 
 
 
 
 
27cc353
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5aee751
b555fe1
27cc353
 
 
 
 
 
 
 
b555fe1
 
 
 
 
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

import streamlit as st
import pandas as pd
import requests

# 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 key (replace with your actual Gemini API key)
GEMINI_API_KEY = 'AIzaSyAGGP8I7c0YmA8xKZsEdAF9AF3ElaPoEn4'

# Set the API endpoint for Gemini
GEMINI_API_URL = "https://gemini.googleapis.com/v1/completions"  # Example URL, please check the actual URL

# 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 = df[df['State'].str.contains(location, case=False)].iloc[0]  # Get the first match
    
    if state_data is not None:
        ghi = state_data['Avg_GHI (kWh/m²/day)']
        solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
        
        # Use Gemini API to generate solar project estimate (cost, savings, payback period)
        prompt = 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
        """

        # Request to Gemini API (Adjust headers and body according to Gemini API documentation)
        response = requests.post(
            GEMINI_API_URL,
            headers={
                "Authorization": f"Bearer {GEMINI_API_KEY}",
                "Content-Type": "application/json"
            },
            json={
                "model": "gemini-model-xyz",  # Use the actual Gemini model name
                "prompt": prompt,
                "max_tokens": 250,
                "temperature": 0.7,
                "top_p": 1.0,
                "n": 1
            }
        )
        
        # Check for successful response
        if response.status_code == 200:
            result = response.json().get("choices", [])[0].get("text", "").strip()
            # Display the response from the Gemini model
            st.subheader("Estimated Solar System Details:")
            st.write(result)
        else:
            st.error(f"Error: {response.status_code}. Unable to get response from Gemini API.")
        
    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.")