Update app.py
Browse files4 unmodified lines567891035 unmodified lines46474849505152535455565758596021 unmodified lines8283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241254 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 linesestimated_data = response.text.strip().split("\n")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 graphsystem_size_kw = Nonemonthly_savings_rs = Nonefor 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 availableif 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)else:st.error("Sorry, the location entered does not match any available data.")else:4 unmodified lines56789101135 unmodified lines47484950515253545556575821 unmodified lines80818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211224 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 linesestimated_data = response.text.strip().split("\n")system_size_kw = Nonemonthly_savings_rs = Nonetotal_system_cost = Nonefor 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])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 availableif 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