Update app.py
Browse files3 unmodified lines4567891011121314151617121819202156 unmodified lines78798075818283848586878889909192939495969798991001011021031041051061071081093 unmodified linesimport osfrom io import StringIOimport csvimport streamlit as stimport pandas as pdimport google.generativeai as genaiimport osimport csvfrom io import StringIO
# Set page configuration firstst.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
# Initialize Geminigenai.configure(api_key=("AIzaSyCaEws3xYpyImgujlI6q4KYsNb3pLcKQ3Y"))genai.configure(api_key=os.getenv("GEMINI_API_KEY"))model = genai.GenerativeModel("gemini-1.5-flash")
# Load solar data56 unmodified lines 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.") 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+36-2