Update app.py
Browse files9 unmodified lines1011121314151657 unmodified lines74757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121139 unmodified lines# Load environment variables from .env fileload_dotenv()# Set page configurationst.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 lineswith st.spinner("Generating solar estimate with Gemini..."):response = model.generate_content(prompt_text)# Debug: Print the raw response to see the structurest.write("Raw Response:", response.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")# Initialize values for each fieldsystem_size = Nonetotal_cost = Nonemonthly_savings = Nonepayback_period = None# Parse the response to find and assign the correct valuesfor 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 fieldsif 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.")else:st.error("Sorry, the location entered does not match any available data.")else:9 unmodified lines1011121314151657 unmodified lines747576777879808182838485868788899091929394959 unmodified lines# Load environment variables from .env fileload_dotenv()# 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 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 ":" in point: # Only process lines with a colontry:# Extract the value after the colonkey, value = point.split(":")st.write(f"{key.strip()}: {value.strip()}")except IndexError:# Handle cases where the split does not give two partsst.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