Update app.py
Browse files72 unmodified lines73747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311472 unmodified lineswith st.spinner("Generating solar estimate with Gemini..."):response = model.generate_content(prompt_text)# Display structured outputst.subheader("Solar Project Estimate")# Break down the response into structured pointsestimated_data = response.text.strip().split("\n")for point in estimated_data:st.write(f"- {point}")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 generationwith 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 CSVfor 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.")72 unmodified lines73747576777879808182838485868788899072 unmodified lineswith st.spinner("Generating solar estimate with Gemini..."):response = model.generate_content(prompt_text)# Display structured output with only the requested pointsst.subheader("Solar Project Estimate")# Break down the response into structured pointsestimated_data = response.text.strip().split("\n")# Display only the required points: system size, cost, savings, and payback periodfor point in estimated_data: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.")
app.py+5-29