MLDeveloper commited on
Commit
0cdc019
·
verified ·
1 Parent(s): 7bac6b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
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
- # Get API key from environment variable
13
- api_key = os.getenv("AIzaSyCVRGVxIe1vESoAgykgHWOej-jZxiU-RKE")
14
- if not api_key:
15
- st.error("Google API Key not set. Please set the GOOGLE_API_KEY environment variable.")
16
  else:
17
- # Initialize Gemini with the API key
18
- genai.configure(api_key=api_key) # Ensure your Gemini API key is set correctly
19
- model = genai.GenerativeModel("gemini-1.5-flash")
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.")