Update app.py
Browse files9 unmodified lines101112131314151657 unmodified lines74757677787977787980818286878889909192838494959697989910010110210310410510610710810911085868788899091929394959 unmodified lines# Load environment variables from .env fileload_dotenv()
# Set page configuration# Set page configuration firstst.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
# Initialize Gemini with the API key loaded from the .env file57 unmodified lines with st.spinner("Generating solar estimate with Gemini..."): response = model.generate_content(prompt_text) # Debug: Print the raw response to see the structure st.write("Raw Response:", response.text) # 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") # Initialize values for each field system_size = None total_cost = None monthly_savings = None payback_period = None # Parse the response to find and assign the correct values # Display only the required points: system size, cost, savings, and payback period for point in estimated_data: if "solar system size" in point.lower(): system_size = point.split(":")[1].strip() elif "total system cost" in point.lower(): total_cost = point.split(":")[1].strip() elif "monthly savings" in point.lower(): monthly_savings = point.split(":")[1].strip() elif "payback period" in point.lower(): payback_period = point.split(":")[1].strip()
# Ensure that we only display numeric values for the fields if system_size and total_cost and monthly_savings and payback_period: st.write(f"1. Estimated solar system size in kW: {system_size}") st.write(f"2. Total system cost in ₹: {total_cost}") st.write(f"3. Monthly savings in ₹: {monthly_savings}") st.write(f"4. Payback period in years: {payback_period}") else: st.error("Unable to extract valid data from the response.") if ":" in point: # Only process lines with a colon try: # Extract the value after the colon key, value = point.split(":") st.write(f"{key.strip()}: {value.strip()}") except IndexError: # Handle cases where the split does not give two parts st.warning("There was an issue processing the response.") else: st.error("Sorry, the location entered does not match any available data.")else:app.py+10-28