Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import os
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
import plotly.graph_objects as go
|
| 7 |
|
|
|
|
| 8 |
# Load environment variables from .env file
|
| 9 |
load_dotenv()
|
| 10 |
|
|
@@ -46,15 +47,12 @@ with st.form("solar_form"):
|
|
| 46 |
def build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw):
|
| 47 |
prompt = f"""
|
| 48 |
You are a solar project estimator tool. Based on the following details, calculate and return only the values without any extra description:
|
| 49 |
-
|
| 50 |
Location: {location}
|
| 51 |
Roof size: {roof_size} sq meters
|
| 52 |
Monthly electricity bill: ₹{electricity_bill}
|
| 53 |
Average GHI: {ghi} kWh/m²/day
|
| 54 |
Solar system cost per kW: ₹{solar_cost_per_kw}
|
| 55 |
-
|
| 56 |
Respond strictly in this format (do not add anything extra):
|
| 57 |
-
|
| 58 |
Estimated solar system size in kW: <value>
|
| 59 |
Estimated daily solar output in kWh: <value>
|
| 60 |
Total system cost in ₹: <value>
|
|
@@ -82,44 +80,43 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
|
|
| 82 |
|
| 83 |
estimated_data = response.text.strip().split("\n")
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
for point in estimated_data:
|
| 86 |
if ":" in point:
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
except ValueError:
|
| 108 |
-
st.warning("There was an issue processing the response.")
|
| 109 |
-
|
| 110 |
-
# Show Graph if available
|
| 111 |
-
if system_size_kw is not None and monthly_savings_rs is not None:
|
| 112 |
-
st.subheader("📊 Visual Summary")
|
| 113 |
-
|
| 114 |
-
fig = go.Figure(data=[
|
| 115 |
-
go.Bar(name='Estimate',
|
| 116 |
-
x=['Solar System Size (kW)', 'Monthly Savings (₹)'],
|
| 117 |
-
y=[system_size_kw, monthly_savings_rs],
|
| 118 |
-
marker_color=['#636EFA', '#00CC96'])
|
| 119 |
-
])
|
| 120 |
-
fig.update_layout(title="Solar Project Estimates", yaxis_title="Values", xaxis_title="Parameters")
|
| 121 |
-
st.plotly_chart(fig)
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
else:
|
| 124 |
st.error("Sorry, the location entered does not match any available data.")
|
| 125 |
else:
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
import plotly.graph_objects as go
|
| 7 |
|
| 8 |
+
|
| 9 |
# Load environment variables from .env file
|
| 10 |
load_dotenv()
|
| 11 |
|
|
|
|
| 47 |
def build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw):
|
| 48 |
prompt = f"""
|
| 49 |
You are a solar project estimator tool. Based on the following details, calculate and return only the values without any extra description:
|
|
|
|
| 50 |
Location: {location}
|
| 51 |
Roof size: {roof_size} sq meters
|
| 52 |
Monthly electricity bill: ₹{electricity_bill}
|
| 53 |
Average GHI: {ghi} kWh/m²/day
|
| 54 |
Solar system cost per kW: ₹{solar_cost_per_kw}
|
|
|
|
| 55 |
Respond strictly in this format (do not add anything extra):
|
|
|
|
| 56 |
Estimated solar system size in kW: <value>
|
| 57 |
Estimated daily solar output in kWh: <value>
|
| 58 |
Total system cost in ₹: <value>
|
|
|
|
| 80 |
|
| 81 |
estimated_data = response.text.strip().split("\n")
|
| 82 |
|
| 83 |
+
system_size_kw = None
|
| 84 |
+
monthly_savings_rs = None
|
| 85 |
+
total_system_cost = None
|
| 86 |
+
|
| 87 |
for point in estimated_data:
|
| 88 |
if ":" in point:
|
| 89 |
+
try:
|
| 90 |
+
key, value = point.split(":", 1)
|
| 91 |
+
key = key.strip()
|
| 92 |
+
value = value.strip()
|
| 93 |
+
|
| 94 |
+
st.write(f"**{key}**: {value}")
|
| 95 |
+
|
| 96 |
+
if "Estimated solar system size" in key:
|
| 97 |
+
system_size_kw = float(value.split()[0])
|
| 98 |
+
if "Monthly savings" in key:
|
| 99 |
+
monthly_savings_rs = float(value.split()[0])
|
| 100 |
+
if "Total system cost" in key:
|
| 101 |
+
total_system_cost = float(value.split()[0])
|
| 102 |
+
|
| 103 |
+
except ValueError:
|
| 104 |
+
st.warning("There was an issue processing the response.")
|
| 105 |
+
|
| 106 |
+
# Show Graph if values are available
|
| 107 |
+
if total_system_cost is not None and monthly_savings_rs is not None:
|
| 108 |
+
st.subheader("📊 Visual Summary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
fig = go.Figure(data=[
|
| 111 |
+
go.Bar(
|
| 112 |
+
x=["Total System Cost (₹)", "Monthly Savings (₹)"],
|
| 113 |
+
y=[total_system_cost, monthly_savings_rs],
|
| 114 |
+
marker_color=['#636EFA', '#00CC96']
|
| 115 |
+
)
|
| 116 |
+
])
|
| 117 |
+
fig.update_layout(title="Solar Project Financial Estimates", yaxis_title="Amount (₹)", xaxis_title="Parameters")
|
| 118 |
+
st.plotly_chart(fig, use_container_width=True, key="solar_graph")
|
| 119 |
+
|
| 120 |
else:
|
| 121 |
st.error("Sorry, the location entered does not match any available data.")
|
| 122 |
else:
|