Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,8 @@ import requests
|
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
from scraper import scrape_tariffs
|
| 6 |
-
from transformers import AutoTokenizer, AutoModel
|
| 7 |
-
import torch
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
|
| 11 |
-
model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
|
| 12 |
-
|
| 13 |
-
# Streamlit App: Electricity Bill Estimator
|
| 14 |
st.title("π Electricity Bill & Carbon Footprint Estimator")
|
| 15 |
st.sidebar.header("βοΈ User Input")
|
| 16 |
|
|
@@ -59,6 +53,18 @@ def calculate_carbon_footprint(monthly_energy_kwh):
|
|
| 59 |
if st.sidebar.button("Scrape Tariff Data"):
|
| 60 |
scrape_data()
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# Sidebar: User Inputs for Appliances
|
| 63 |
st.sidebar.subheader("π Add Appliances")
|
| 64 |
selected_appliance = st.sidebar.selectbox("Select an appliance:", list(appliances.keys()))
|
|
@@ -95,13 +101,13 @@ if st.session_state["appliance_list"]:
|
|
| 95 |
)
|
| 96 |
|
| 97 |
# Electricity Bill and Carbon Footprint Calculation
|
| 98 |
-
if st.session_state["appliance_list"]:
|
| 99 |
total_daily_energy_kwh = sum(
|
| 100 |
(appliance["power"] * appliance["quantity"] * appliance["hours"]) / 1000
|
| 101 |
for appliance in st.session_state["appliance_list"]
|
| 102 |
)
|
| 103 |
monthly_energy_kwh = total_daily_energy_kwh * 30 # Assume 30 days in a month
|
| 104 |
-
bill_amount = monthly_energy_kwh *
|
| 105 |
carbon_footprint = calculate_carbon_footprint(monthly_energy_kwh)
|
| 106 |
|
| 107 |
st.subheader("π΅ Electricity Bill & π Carbon Footprint")
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
from scraper import scrape_tariffs
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Streamlit App: Electricity Bill & Carbon Footprint Estimator
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
st.title("π Electricity Bill & Carbon Footprint Estimator")
|
| 9 |
st.sidebar.header("βοΈ User Input")
|
| 10 |
|
|
|
|
| 53 |
if st.sidebar.button("Scrape Tariff Data"):
|
| 54 |
scrape_data()
|
| 55 |
|
| 56 |
+
# Sidebar: Tariff Selection
|
| 57 |
+
st.sidebar.subheader("π‘ Select Tariff")
|
| 58 |
+
try:
|
| 59 |
+
tariff_data = pd.read_csv("data/tariffs.csv")
|
| 60 |
+
tariff_types = tariff_data["category"].unique()
|
| 61 |
+
selected_tariff = st.sidebar.selectbox("Select your tariff category:", tariff_types)
|
| 62 |
+
rate_per_kwh = tariff_data[tariff_data["category"] == selected_tariff]["rate"].iloc[0]
|
| 63 |
+
st.sidebar.write(f"Rate per kWh: **{rate_per_kwh} PKR**")
|
| 64 |
+
except FileNotFoundError:
|
| 65 |
+
st.sidebar.error("β οΈ Tariff data not found. Please scrape the data first.")
|
| 66 |
+
rate_per_kwh = 0
|
| 67 |
+
|
| 68 |
# Sidebar: User Inputs for Appliances
|
| 69 |
st.sidebar.subheader("π Add Appliances")
|
| 70 |
selected_appliance = st.sidebar.selectbox("Select an appliance:", list(appliances.keys()))
|
|
|
|
| 101 |
)
|
| 102 |
|
| 103 |
# Electricity Bill and Carbon Footprint Calculation
|
| 104 |
+
if st.session_state["appliance_list"] and rate_per_kwh > 0:
|
| 105 |
total_daily_energy_kwh = sum(
|
| 106 |
(appliance["power"] * appliance["quantity"] * appliance["hours"]) / 1000
|
| 107 |
for appliance in st.session_state["appliance_list"]
|
| 108 |
)
|
| 109 |
monthly_energy_kwh = total_daily_energy_kwh * 30 # Assume 30 days in a month
|
| 110 |
+
bill_amount = monthly_energy_kwh * rate_per_kwh # Dynamic tariff rate
|
| 111 |
carbon_footprint = calculate_carbon_footprint(monthly_energy_kwh)
|
| 112 |
|
| 113 |
st.subheader("π΅ Electricity Bill & π Carbon Footprint")
|