Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,22 @@ import google.generativeai as genai
|
|
4 |
import os
|
5 |
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 |
-
#
|
13 |
-
api_key = os.getenv("
|
14 |
-
if
|
15 |
-
|
16 |
else:
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
# Load solar data
|
22 |
@st.cache_data
|
@@ -90,7 +93,7 @@ if st.button("Generate Batch & Download CSV"):
|
|
90 |
if location and roof_size > 0 and electricity_bill >= 0:
|
91 |
csv_buffer = StringIO()
|
92 |
writer = csv.writer(csv_buffer)
|
93 |
-
writer.writerow(["Sequence_no", "Solar Estimate"]
|
94 |
|
95 |
# Call Gemini API once for the batch generation
|
96 |
with st.spinner("Generating batch estimates..."):
|
@@ -109,5 +112,3 @@ if st.button("Generate Batch & Download CSV"):
|
|
109 |
)
|
110 |
else:
|
111 |
st.warning("Please fill out all fields to generate batch estimates.")
|
112 |
-
|
113 |
-
|
|
|
4 |
import os
|
5 |
from io import StringIO
|
6 |
import csv
|
7 |
+
from dotenv import load_dotenv
|
8 |
|
9 |
+
# Load environment variables from .env file
|
10 |
+
load_dotenv()
|
11 |
|
12 |
# Set page configuration first
|
13 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
14 |
|
15 |
+
# Initialize Gemini with the API key loaded from the .env file
|
16 |
+
api_key = os.getenv("GOOGLE_API_KEY")
|
17 |
+
if api_key:
|
18 |
+
genai.configure(api_key=api_key)
|
19 |
else:
|
20 |
+
st.error("API key is missing. Please set the GOOGLE_API_KEY environment variable.")
|
21 |
+
|
22 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
23 |
|
24 |
# Load solar data
|
25 |
@st.cache_data
|
|
|
93 |
if location and roof_size > 0 and electricity_bill >= 0:
|
94 |
csv_buffer = StringIO()
|
95 |
writer = csv.writer(csv_buffer)
|
96 |
+
writer.writerow(["Sequence_no", "Solar Estimate"])
|
97 |
|
98 |
# Call Gemini API once for the batch generation
|
99 |
with st.spinner("Generating batch estimates..."):
|
|
|
112 |
)
|
113 |
else:
|
114 |
st.warning("Please fill out all fields to generate batch estimates.")
|
|
|
|