Update app.py
Browse files
app.py
CHANGED
@@ -4,12 +4,18 @@ import google.generativeai as genai
|
|
4 |
import os
|
5 |
from io import StringIO
|
6 |
import csv
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Set page configuration first
|
9 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
10 |
|
11 |
# Initialize Gemini
|
12 |
-
genai.configure(api_key=("
|
13 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
14 |
|
15 |
# Load solar data
|
@@ -72,4 +78,32 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
72 |
else:
|
73 |
st.error("Sorry, the location entered does not match any available data.")
|
74 |
else:
|
75 |
-
st.warning("Please fill out all fields to see your solar project estimate.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import os
|
5 |
from io import StringIO
|
6 |
import csv
|
7 |
+
import streamlit as st
|
8 |
+
import pandas as pd
|
9 |
+
import google.generativeai as genai
|
10 |
+
import os
|
11 |
+
import csv
|
12 |
+
from io import StringIO
|
13 |
|
14 |
# Set page configuration first
|
15 |
st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
|
16 |
|
17 |
# Initialize Gemini
|
18 |
+
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
19 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
20 |
|
21 |
# Load solar data
|
|
|
78 |
else:
|
79 |
st.error("Sorry, the location entered does not match any available data.")
|
80 |
else:
|
81 |
+
st.warning("Please fill out all fields to see your solar project estimate.")
|
82 |
+
|
83 |
+
# Batch CSV Export
|
84 |
+
st.markdown("### Export Solar Estimates")
|
85 |
+
batch = st.number_input("How many estimates to generate?", min_value=1, max_value=100, value=5)
|
86 |
+
|
87 |
+
if st.button("Generate Batch & Download CSV"):
|
88 |
+
if location and roof_size > 0 and electricity_bill >= 0:
|
89 |
+
csv_buffer = StringIO()
|
90 |
+
writer = csv.writer(csv_buffer)
|
91 |
+
writer.writerow(["Sequence_no", "Solar Estimate"])
|
92 |
+
|
93 |
+
# Call Gemini API once for the batch generation
|
94 |
+
with st.spinner("Generating batch estimates..."):
|
95 |
+
batch_prompts = [build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw) for _ in range(batch)]
|
96 |
+
batch_responses = [model.generate_content(prompt) for prompt in batch_prompts]
|
97 |
+
|
98 |
+
# Process the batch responses and write to CSV
|
99 |
+
for i, response in enumerate(batch_responses, 1):
|
100 |
+
writer.writerow([i, response.text.strip()])
|
101 |
+
|
102 |
+
st.download_button(
|
103 |
+
label="Download Solar Estimates CSV",
|
104 |
+
data=csv_buffer.getvalue(),
|
105 |
+
file_name="solar_estimates.csv",
|
106 |
+
mime="text/csv"
|
107 |
+
)
|
108 |
+
else:
|
109 |
+
st.warning("Please fill out all fields to generate batch estimates.")
|