Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ from io import StringIO
|
|
6 |
import csv
|
7 |
from dotenv import load_dotenv
|
8 |
|
|
|
|
|
9 |
# Load environment variables from .env file
|
10 |
load_dotenv()
|
11 |
|
@@ -65,26 +67,41 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
65 |
|
66 |
if state_data is not None:
|
67 |
ghi = state_data['Avg_GHI (kWh/m²/day)']
|
68 |
-
solar_cost_per_kw = state_data['
|
69 |
|
70 |
prompt_text = build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw)
|
71 |
|
72 |
-
# Call Gemini API once for
|
73 |
with st.spinner("Generating solar estimate with Gemini..."):
|
74 |
response = model.generate_content(prompt_text)
|
75 |
|
76 |
# Display structured output with only the requested points
|
77 |
st.subheader("Solar Project Estimate")
|
78 |
|
79 |
-
# Break down the response into structured points
|
80 |
estimated_data = response.text.strip().split("\n")
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
for point in estimated_data:
|
84 |
-
if "solar system size" in point.lower()
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
else:
|
87 |
st.error("Sorry, the location entered does not match any available data.")
|
88 |
else:
|
89 |
st.warning("Please fill out all fields to see your solar project estimate.")
|
90 |
-
|
|
|
6 |
import csv
|
7 |
from dotenv import load_dotenv
|
8 |
|
9 |
+
|
10 |
+
|
11 |
# Load environment variables from .env file
|
12 |
load_dotenv()
|
13 |
|
|
|
67 |
|
68 |
if state_data is not None:
|
69 |
ghi = state_data['Avg_GHI (kWh/m²/day)']
|
70 |
+
solar_cost_per_kw = state_data['Solar_Cost_per_KW (₹)']
|
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 and display directly
|
82 |
estimated_data = response.text.strip().split("\n")
|
83 |
|
84 |
+
solar_system_size = ""
|
85 |
+
total_system_cost = ""
|
86 |
+
monthly_savings = ""
|
87 |
+
payback_period = ""
|
88 |
+
|
89 |
for point in estimated_data:
|
90 |
+
if "solar system size" in point.lower():
|
91 |
+
solar_system_size = point.split(":")[-1].strip()
|
92 |
+
elif "total system cost" in point.lower():
|
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 results in 4 separate lines
|
100 |
+
st.write(f"1. Solar System Size: {solar_system_size}")
|
101 |
+
st.write(f"2. Estimated Cost: {total_system_cost}")
|
102 |
+
st.write(f"3. Monthly Savings: {monthly_savings}")
|
103 |
+
st.write(f"4. Payback Period: {payback_period}")
|
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.")
|
|