Update app.py
Browse files72 unmodified lines737475767677787980818283828485868788899088899091929394959697989910010110210310410510610710810911011111211311472 unmodified lines with st.spinner("Generating solar estimate with Gemini..."): response = model.generate_content(prompt_text) # Display structured output # Display structured output with only the requested points st.subheader("Solar Project Estimate") # Break down the response into structured points estimated_data = response.text.strip().split("\n") # Display only the required points: system size, cost, savings, and payback period for point in estimated_data: st.write(f"- {point}") 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(): st.write(f"{point.strip()}") else: st.error("Sorry, the location entered does not match any available data.")else: st.warning("Please fill out all fields to see your solar project estimate.")
# Batch CSV Exportst.markdown("### Export Solar Estimates")batch = st.number_input("How many estimates to generate?", min_value=1, max_value=100, value=5)
if st.button("Generate Batch & Download CSV"): if location and roof_size > 0 and electricity_bill >= 0: csv_buffer = StringIO() writer = csv.writer(csv_buffer) writer.writerow(["Sequence_no", "Solar Estimate"]) # Call Gemini API once for the batch generation with st.spinner("Generating batch estimates..."): batch_prompts = [build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw) for _ in range(batch)] batch_responses = [model.generate_content(prompt) for prompt in batch_prompts] # Process the batch responses and write to CSV for i, response in enumerate(batch_responses, 1): writer.writerow([i, response.text.strip()]) st.download_button( label="Download Solar Estimates CSV", data=csv_buffer.getvalue(), file_name="solar_estimates.csv", mime="text/csv" ) else: st.warning("Please fill out all fields to generate batch estimates.")app.py+5-29