Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,18 @@ 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('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')
|
| 9 |
|
| 10 |
-
# Set up the
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Streamlit UI
|
| 14 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
|
@@ -36,7 +43,7 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
| 36 |
ghi = state_data['Avg_GHI (kWh/m²/day)']
|
| 37 |
solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
|
| 38 |
|
| 39 |
-
# Use
|
| 40 |
prompt = f"""
|
| 41 |
Estimate the solar system for the location '{location}' based on the following details:
|
| 42 |
Roof size: {roof_size} sq meters
|
|
@@ -52,22 +59,31 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
| 52 |
5. Payback period in years
|
| 53 |
"""
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
response =
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
else:
|
| 73 |
st.error("Sorry, the location entered does not match any available data.")
|
|
|
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import openai
|
| 6 |
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import requests
|
| 10 |
+
|
| 11 |
# Load the solar data CSV file
|
| 12 |
df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')
|
| 13 |
|
| 14 |
+
# Set up the Gemini API key (replace with your actual Gemini API key)
|
| 15 |
+
GEMINI_API_KEY = 'AIzaSyAGGP8I7c0YmA8xKZsEdAF9AF3ElaPoEn4'
|
| 16 |
+
|
| 17 |
+
# Set the API endpoint for Gemini
|
| 18 |
+
GEMINI_API_URL = "https://gemini.googleapis.com/v1/completions" # Example URL, please check the actual URL
|
| 19 |
|
| 20 |
# Streamlit UI
|
| 21 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
|
|
|
| 43 |
ghi = state_data['Avg_GHI (kWh/m²/day)']
|
| 44 |
solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
|
| 45 |
|
| 46 |
+
# Use Gemini API to generate solar project estimate (cost, savings, payback period)
|
| 47 |
prompt = f"""
|
| 48 |
Estimate the solar system for the location '{location}' based on the following details:
|
| 49 |
Roof size: {roof_size} sq meters
|
|
|
|
| 59 |
5. Payback period in years
|
| 60 |
"""
|
| 61 |
|
| 62 |
+
# Request to Gemini API (Adjust headers and body according to Gemini API documentation)
|
| 63 |
+
response = requests.post(
|
| 64 |
+
GEMINI_API_URL,
|
| 65 |
+
headers={
|
| 66 |
+
"Authorization": f"Bearer {GEMINI_API_KEY}",
|
| 67 |
+
"Content-Type": "application/json"
|
| 68 |
+
},
|
| 69 |
+
json={
|
| 70 |
+
"model": "gemini-model-xyz", # Use the actual Gemini model name
|
| 71 |
+
"prompt": prompt,
|
| 72 |
+
"max_tokens": 250,
|
| 73 |
+
"temperature": 0.7,
|
| 74 |
+
"top_p": 1.0,
|
| 75 |
+
"n": 1
|
| 76 |
+
}
|
| 77 |
)
|
| 78 |
|
| 79 |
+
# Check for successful response
|
| 80 |
+
if response.status_code == 200:
|
| 81 |
+
result = response.json().get("choices", [])[0].get("text", "").strip()
|
| 82 |
+
# Display the response from the Gemini model
|
| 83 |
+
st.subheader("Estimated Solar System Details:")
|
| 84 |
+
st.write(result)
|
| 85 |
+
else:
|
| 86 |
+
st.error(f"Error: {response.status_code}. Unable to get response from Gemini API.")
|
| 87 |
|
| 88 |
else:
|
| 89 |
st.error("Sorry, the location entered does not match any available data.")
|