CoderHassan commited on
Commit
3a27cbb
·
verified ·
1 Parent(s): d6b4c7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -31,7 +31,7 @@ if "appliance_data" not in st.session_state:
31
  client = Groq(api_key="EnergyGuru_PowerCalc")
32
 
33
  # App Configuration
34
- st.title("EnergyGuru_PowerCalc: AI DRIVEN AL DRIVEN BILL & CARBON FOOTPRINT TRACKER")
35
  st.sidebar.header("Add Appliances")
36
  st.sidebar.write("Select appliances, quantity, and usage details to calculate electricity consumption.")
37
 
@@ -82,21 +82,27 @@ if st.session_state.appliance_data:
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
- # total monthly energy in kwh = no. of units
93
- monthly_energy_kwh = total_no_of_units
94
 
95
  # Get the rate from tariff data or use a default rate if not found
96
  rate_per_unit = tariff_data.get("rate_per_unit", 25) # Default rate of 25 PKR/kWh
97
 
98
- # Correct Monthly Bill Calculation: Total Monthly Energy in kWh * Rate per kWh (Rate in PKR)
99
- monthly_bill = total_no_of_units * rate_per_unit
 
 
 
100
 
101
  # Query AI Model (optional, if needed for insights)
102
  query = f"Calculate the monthly electricity bill for appliances with a total energy consumption of {monthly_energy_kwh:.2f} kWh per month."
@@ -107,5 +113,6 @@ if st.button("Calculate Monthly Bill"):
107
 
108
  # Display Results
109
  st.write(f"**Total Monthly Electricity Bill: PKR {monthly_bill:.2f}**")
 
110
  st.write("**AI Model Insight:**")
111
  st.write(response.choices[0].message.content)
 
31
  client = Groq(api_key="EnergyGuru_PowerCalc")
32
 
33
  # App Configuration
34
+ st.title("EnergyGuru_PowerCalc: AI DRIVEN BILL & CARBON FOOTPRINT TRACKER")
35
  st.sidebar.header("Add Appliances")
36
  st.sidebar.write("Select appliances, quantity, and usage details to calculate electricity consumption.")
37
 
 
82
  else:
83
  st.write("No appliances added yet.")
84
 
85
+ # Function to calculate carbon footprint (in kg CO2)
86
+ def calculate_carbon_footprint(monthly_energy_kwh):
87
+ carbon_emission_factor = 0.75 # kg CO2 per kWh, adjust based on actual data
88
+ return monthly_energy_kwh * carbon_emission_factor
89
+
90
  # Calculate Monthly Bill Button
91
  if st.button("Calculate Monthly Bill"):
92
  # Convert total energy consumption from watt-hours (Wh) to kilowatt-hours (kWh)
93
  total_energy_kwh = total_energy_wh / 1000 # Convert energy to kWh
94
 
95
+ # Calculate total monthly energy consumption by multiplying by 30 (days)
96
+ monthly_energy_kwh = total_energy_kwh * 30 # Total energy consumption in a month
 
 
97
 
98
  # Get the rate from tariff data or use a default rate if not found
99
  rate_per_unit = tariff_data.get("rate_per_unit", 25) # Default rate of 25 PKR/kWh
100
 
101
+ # Calculate Monthly Bill
102
+ monthly_bill = monthly_energy_kwh * rate_per_unit
103
+
104
+ # Calculate the carbon footprint based on monthly energy consumption
105
+ carbon_footprint = calculate_carbon_footprint(monthly_energy_kwh)
106
 
107
  # Query AI Model (optional, if needed for insights)
108
  query = f"Calculate the monthly electricity bill for appliances with a total energy consumption of {monthly_energy_kwh:.2f} kWh per month."
 
113
 
114
  # Display Results
115
  st.write(f"**Total Monthly Electricity Bill: PKR {monthly_bill:.2f}**")
116
+ st.write(f"**Total Carbon Footprint: {carbon_footprint:.2f} kg CO2**")
117
  st.write("**AI Model Insight:**")
118
  st.write(response.choices[0].message.content)