Update app.py
Browse files4 unmodified lines56789101135 unmodified lines47484949505152535455555756575821 unmodified lines8081828384858687888788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012189909192939495969798991001011021031041051061071081091101111121131141151161171181191201211224 unmodified linesfrom dotenv import load_dotenvimport plotly.graph_objects as go
# Load environment variables from .env fileload_dotenv()
35 unmodified linesdef build_prompt(location, roof_size, electricity_bill, ghi, solar_cost_per_kw): prompt = f"""You are a solar project estimator tool. Based on the following details, calculate and return only the values without any extra description:
Location: {location}Roof size: {roof_size} sq metersMonthly electricity bill: ₹{electricity_bill}Average GHI: {ghi} kWh/m²/daySolar system cost per kW: ₹{solar_cost_per_kw}
Respond strictly in this format (do not add anything extra):
Estimated solar system size in kW: <value>Estimated daily solar output in kWh: <value>Total system cost in ₹: <value>21 unmodified lines estimated_data = response.text.strip().split("\n") system_size_kw = None monthly_savings_rs = None total_system_cost = None for point in estimated_data: if ":" in point: key, value = point.split(":", 1) st.write(f"**{key.strip()}**: {value.strip()}") # Variables to store extracted values for graph system_size_kw = None monthly_savings_rs = None
for point in estimated_data: if ":" in point: try: key, value = point.split(":", 1) key = key.strip() value = value.strip()
st.write(f"**{key}**: {value}")
if "Estimated solar system size" in key: system_size_kw = float(value.split()[0]) if "Monthly savings" in key: monthly_savings_rs = float(value.split()[0]) except ValueError: st.warning("There was an issue processing the response.")
# Show Graph if available if system_size_kw is not None and monthly_savings_rs is not None: st.subheader("📊 Visual Summary") fig = go.Figure(data=[ go.Bar(name='Estimate', x=['Solar System Size (kW)', 'Monthly Savings (₹)'], y=[system_size_kw, monthly_savings_rs], marker_color=['#636EFA', '#00CC96']) ]) fig.update_layout(title="Solar Project Estimates", yaxis_title="Values", xaxis_title="Parameters") st.plotly_chart(fig) try: key, value = point.split(":", 1) key = key.strip() value = value.strip() st.write(f"**{key}**: {value}")
if "Estimated solar system size" in key: system_size_kw = float(value.split()[0]) if "Monthly savings" in key: monthly_savings_rs = float(value.split()[0]) if "Total system cost" in key: total_system_cost = float(value.split()[0])
except ValueError: st.warning("There was an issue processing the response.")
# Show Graph if values are available if total_system_cost is not None and monthly_savings_rs is not None: st.subheader("📊 Visual Summary") fig = go.Figure(data=[ go.Bar( x=["Total System Cost (₹)", "Monthly Savings (₹)"], y=[total_system_cost, monthly_savings_rs], marker_color=['#636EFA', '#00CC96'] ) ]) fig.update_layout(title="Solar Project Financial Estimates", yaxis_title="Amount (₹)", xaxis_title="Parameters") st.plotly_chart(fig, use_container_width=True, key="solar_graph")
else: st.error("Sorry, the location entered does not match any available data.")else:app.py+35-38