Update app.py
Browse files
app.py
CHANGED
|
@@ -73,42 +73,18 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
| 73 |
with st.spinner("Generating solar estimate with Gemini..."):
|
| 74 |
response = model.generate_content(prompt_text)
|
| 75 |
|
| 76 |
-
# Display structured output
|
| 77 |
st.subheader("Solar Project Estimate")
|
| 78 |
|
| 79 |
# Break down the response into structured points
|
| 80 |
estimated_data = response.text.strip().split("\n")
|
|
|
|
|
|
|
| 81 |
for point in estimated_data:
|
| 82 |
-
|
|
|
|
| 83 |
else:
|
| 84 |
st.error("Sorry, the location entered does not match any available data.")
|
| 85 |
else:
|
| 86 |
st.warning("Please fill out all fields to see your solar project estimate.")
|
| 87 |
|
| 88 |
-
# Batch CSV Export
|
| 89 |
-
st.markdown("### Export Solar Estimates")
|
| 90 |
-
batch = st.number_input("How many estimates to generate?", min_value=1, max_value=100, value=5)
|
| 91 |
-
|
| 92 |
-
if st.button("Generate Batch & Download CSV"):
|
| 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..."):
|
| 100 |
-
batch_prompts = [build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw) for _ in range(batch)]
|
| 101 |
-
batch_responses = [model.generate_content(prompt) for prompt in batch_prompts]
|
| 102 |
-
|
| 103 |
-
# Process the batch responses and write to CSV
|
| 104 |
-
for i, response in enumerate(batch_responses, 1):
|
| 105 |
-
writer.writerow([i, response.text.strip()])
|
| 106 |
-
|
| 107 |
-
st.download_button(
|
| 108 |
-
label="Download Solar Estimates CSV",
|
| 109 |
-
data=csv_buffer.getvalue(),
|
| 110 |
-
file_name="solar_estimates.csv",
|
| 111 |
-
mime="text/csv"
|
| 112 |
-
)
|
| 113 |
-
else:
|
| 114 |
-
st.warning("Please fill out all fields to generate batch estimates.")
|
|
|
|
| 73 |
with st.spinner("Generating solar estimate with Gemini..."):
|
| 74 |
response = model.generate_content(prompt_text)
|
| 75 |
|
| 76 |
+
# Display structured output with only the requested points
|
| 77 |
st.subheader("Solar Project Estimate")
|
| 78 |
|
| 79 |
# Break down the response into structured points
|
| 80 |
estimated_data = response.text.strip().split("\n")
|
| 81 |
+
|
| 82 |
+
# Display only the required points: system size, cost, savings, and payback period
|
| 83 |
for point in estimated_data:
|
| 84 |
+
if "solar system size" in point.lower() or "total system cost" in point.lower() or "monthly savings" in point.lower() or "payback period" in point.lower():
|
| 85 |
+
st.write(f"{point.strip()}")
|
| 86 |
else:
|
| 87 |
st.error("Sorry, the location entered does not match any available data.")
|
| 88 |
else:
|
| 89 |
st.warning("Please fill out all fields to see your solar project estimate.")
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|