Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import csv
|
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
|
| 10 |
-
|
| 11 |
# Load environment variables from .env file
|
| 12 |
load_dotenv()
|
| 13 |
|
|
@@ -71,37 +70,32 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
| 71 |
|
| 72 |
prompt_text = build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw)
|
| 73 |
|
| 74 |
-
# Call Gemini API once for the batch generation
|
| 75 |
with st.spinner("Generating solar estimate with Gemini..."):
|
| 76 |
response = model.generate_content(prompt_text)
|
| 77 |
|
| 78 |
# Display structured output with only the requested points
|
| 79 |
st.subheader("Solar Project Estimate")
|
| 80 |
|
| 81 |
-
# Break down the response into structured points
|
| 82 |
estimated_data = response.text.strip().split("\n")
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
monthly_savings = ""
|
| 87 |
-
payback_period = ""
|
| 88 |
-
|
| 89 |
for point in estimated_data:
|
| 90 |
-
if "solar system size" in point.lower():
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
total_system_cost = point.split(":")[-1].strip()
|
| 94 |
-
elif "monthly savings" in point.lower():
|
| 95 |
-
monthly_savings = point.split(":")[-1].strip()
|
| 96 |
-
elif "payback period" in point.lower():
|
| 97 |
-
payback_period = point.split(":")[-1].strip()
|
| 98 |
|
| 99 |
-
# Display the
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
| 104 |
else:
|
| 105 |
st.error("Sorry, the location entered does not match any available data.")
|
| 106 |
else:
|
| 107 |
st.warning("Please fill out all fields to see your solar project estimate.")
|
|
|
|
|
|
|
|
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
|
|
|
|
| 10 |
# Load environment variables from .env file
|
| 11 |
load_dotenv()
|
| 12 |
|
|
|
|
| 70 |
|
| 71 |
prompt_text = build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw)
|
| 72 |
|
| 73 |
+
# Call Gemini API once for all the batch generation
|
| 74 |
with st.spinner("Generating solar estimate with Gemini..."):
|
| 75 |
response = model.generate_content(prompt_text)
|
| 76 |
|
| 77 |
# Display structured output with only the requested points
|
| 78 |
st.subheader("Solar Project Estimate")
|
| 79 |
|
| 80 |
+
# Break down the response into structured points
|
| 81 |
estimated_data = response.text.strip().split("\n")
|
| 82 |
|
| 83 |
+
# Extract the values for solar system size, cost, savings, and payback period
|
| 84 |
+
values = []
|
|
|
|
|
|
|
|
|
|
| 85 |
for point in estimated_data:
|
| 86 |
+
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():
|
| 87 |
+
# Extract the values and append to the list
|
| 88 |
+
values.append(point.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
# Display the values in 4 lines as requested
|
| 91 |
+
if len(values) == 4:
|
| 92 |
+
st.write(f"1. {values[0]}")
|
| 93 |
+
st.write(f"2. {values[1]}")
|
| 94 |
+
st.write(f"3. {values[2]}")
|
| 95 |
+
st.write(f"4. {values[3]}")
|
| 96 |
else:
|
| 97 |
st.error("Sorry, the location entered does not match any available data.")
|
| 98 |
else:
|
| 99 |
st.warning("Please fill out all fields to see your solar project estimate.")
|
| 100 |
+
|
| 101 |
+
|