RizwanSajad commited on
Commit
3d2d973
·
verified ·
1 Parent(s): 1d41a33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -82,25 +82,28 @@ if st.session_state.appliance_data:
82
  else:
83
  st.write("No appliances added yet.")
84
 
85
- # Calculate Bill Button
86
- if st.button("Calculate Total Bill"):
87
- # Calculate total energy in kWh (1 Wh = 1/1000 kWh)
88
  total_energy_kwh = total_energy_wh / 1000 # Convert energy to kWh
89
 
 
 
 
90
  # Get the rate from tariff data or use a default rate if not found
91
  rate_per_unit = tariff_data.get("rate_per_unit", 25) # Default rate of 25 PKR/kWh
92
 
93
- # Correct Bill Calculation: Total Energy in kWh * Rate per kWh (Rate in PKR)
94
- bill = total_energy_kwh * rate_per_unit
95
 
96
  # Query AI Model (optional, if needed for insights)
97
- query = f"Calculate the electricity bill for appliances with a total energy consumption of {total_energy_kwh:.2f} kWh per day."
98
  response = client.chat.completions.create(
99
  messages=[{"role": "user", "content": query}],
100
  model="llama3-8b-8192",
101
  )
102
 
103
  # Display Results
104
- st.write(f"**Total Electricity Bill: PKR {bill:.2f}**")
105
  st.write("**AI Model Insight:**")
106
  st.write(response.choices[0].message.content)
 
82
  else:
83
  st.write("No appliances added yet.")
84
 
85
+ # Calculate Monthly Bill Button
86
+ if st.button("Calculate Monthly Bill"):
87
+ # Convert total energy consumption from watt-hours (Wh) to kilowatt-hours (kWh)
88
  total_energy_kwh = total_energy_wh / 1000 # Convert energy to kWh
89
 
90
+ # Calculate total monthly energy consumption by multiplying by 30
91
+ monthly_energy_kwh = total_energy_kwh * 30
92
+
93
  # Get the rate from tariff data or use a default rate if not found
94
  rate_per_unit = tariff_data.get("rate_per_unit", 25) # Default rate of 25 PKR/kWh
95
 
96
+ # Correct Monthly Bill Calculation: Total Monthly Energy in kWh * Rate per kWh (Rate in PKR)
97
+ monthly_bill = monthly_energy_kwh * rate_per_unit
98
 
99
  # Query AI Model (optional, if needed for insights)
100
+ query = f"Calculate the monthly electricity bill for appliances with a total energy consumption of {monthly_energy_kwh:.2f} kWh per month."
101
  response = client.chat.completions.create(
102
  messages=[{"role": "user", "content": query}],
103
  model="llama3-8b-8192",
104
  )
105
 
106
  # Display Results
107
+ st.write(f"**Total Monthly Electricity Bill: PKR {monthly_bill:.2f}**")
108
  st.write("**AI Model Insight:**")
109
  st.write(response.choices[0].message.content)