Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,18 @@ from io import StringIO
|
|
6 |
import csv
|
7 |
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Set page configuration first
|
10 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
11 |
|
12 |
# Initialize Gemini
|
13 |
-
genai.configure(api_key=os.getenv("
|
14 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
15 |
|
16 |
# Load solar data
|
@@ -42,8 +49,7 @@ def build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw):
|
|
42 |
- Monthly electricity bill: ₹{electricity_bill}
|
43 |
- Average GHI (solar radiation) for {location}: {ghi} kWh/m²/day
|
44 |
- Solar system cost per kW in {location}: ₹{solar_cost_per_kw}
|
45 |
-
|
46 |
-
Provide:
|
47 |
1. Estimated solar system size in kW
|
48 |
2. Estimated daily solar output in kWh
|
49 |
3. Total system cost in ₹
|
@@ -63,13 +69,16 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
63 |
prompt_text = build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw)
|
64 |
|
65 |
# Call Gemini API once for all the batch generation
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
else:
|
74 |
st.error("Sorry, the location entered does not match any available data.")
|
75 |
else:
|
|
|
6 |
import csv
|
7 |
|
8 |
|
9 |
+
import streamlit as st
|
10 |
+
import pandas as pd
|
11 |
+
import google.generativeai as genai
|
12 |
+
import os
|
13 |
+
from io import StringIO
|
14 |
+
import csv
|
15 |
+
|
16 |
# Set page configuration first
|
17 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
18 |
|
19 |
# Initialize Gemini
|
20 |
+
genai.configure(api_key=os.getenv("GEMINI_API_KEY")) # Ensure your Gemini API key is set as an environment variable
|
21 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
22 |
|
23 |
# Load solar data
|
|
|
49 |
- Monthly electricity bill: ₹{electricity_bill}
|
50 |
- Average GHI (solar radiation) for {location}: {ghi} kWh/m²/day
|
51 |
- Solar system cost per kW in {location}: ₹{solar_cost_per_kw}
|
52 |
+
Provide the following:
|
|
|
53 |
1. Estimated solar system size in kW
|
54 |
2. Estimated daily solar output in kWh
|
55 |
3. Total system cost in ₹
|
|
|
69 |
prompt_text = build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw)
|
70 |
|
71 |
# Call Gemini API once for all the batch generation
|
72 |
+
with st.spinner("Generating solar estimate with Gemini..."):
|
73 |
+
response = model.generate_content(prompt_text)
|
74 |
+
|
75 |
+
# Display structured output
|
76 |
+
st.subheader("Solar Project Estimate")
|
77 |
+
|
78 |
+
# Break down the response into structured points
|
79 |
+
estimated_data = response.text.strip().split("\n")
|
80 |
+
for point in estimated_data:
|
81 |
+
st.write(f"- {point}")
|
82 |
else:
|
83 |
st.error("Sorry, the location entered does not match any available data.")
|
84 |
else:
|