Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,25 +3,27 @@ from tariff_scraper import scrape_tariff_data
|
|
| 3 |
|
| 4 |
def main():
|
| 5 |
st.title("Electricity Bill Calculator with Tariff Scraper")
|
| 6 |
-
st.sidebar.subheader("Tariff Data Scraper")
|
| 7 |
-
|
| 8 |
-
# Tariff Scraper Section
|
| 9 |
-
st.sidebar.write("Enter the URL of the electricity tariff page:")
|
| 10 |
-
url = st.sidebar.text_input("Tariff URL", "https://iesco.com.pk/index.php/customer-services/tariff-guide")
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Electricity Bill Calculator Section
|
| 27 |
st.write("## Electricity Bill Calculator")
|
|
@@ -31,7 +33,7 @@ def main():
|
|
| 31 |
"Fan": 75, "Air Conditioner (1 Ton)": 1500, "Refrigerator": 150,
|
| 32 |
"LED Bulb (20W)": 20, "Iron": 1000, "Microwave Oven": 1200
|
| 33 |
}
|
| 34 |
-
|
| 35 |
appliance = st.sidebar.selectbox("Select Appliance", options=list(appliances.keys()))
|
| 36 |
quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
|
| 37 |
usage_hours = st.sidebar.number_input("Usage Hours/Day", min_value=1.0, value=6.0)
|
|
@@ -60,7 +62,7 @@ def main():
|
|
| 60 |
app["quantity"] * app["load"] * app["usage_hours"] / 1000 for app in st.session_state["appliances"]
|
| 61 |
)
|
| 62 |
bill = total_units * 30 * tariff_rate
|
| 63 |
-
st.success(f"Estimated Monthly Bill: PKR {bill:.2f}")
|
| 64 |
else:
|
| 65 |
st.warning("No appliances added for calculation.")
|
| 66 |
|
|
|
|
| 3 |
|
| 4 |
def main():
|
| 5 |
st.title("Electricity Bill Calculator with Tariff Scraper")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Default URL for scraping tariff rates
|
| 8 |
+
url = "https://iesco.com.pk/index.php/customer-services/tariff-guide"
|
| 9 |
+
|
| 10 |
+
# Scrape tariff rates
|
| 11 |
+
tariff_rate = 0.0
|
| 12 |
+
with st.spinner("Fetching tariff rates..."):
|
| 13 |
+
data = scrape_tariff_data(url)
|
| 14 |
+
if isinstance(data, list) and data:
|
| 15 |
+
# Extract tariff rate from the scraped data
|
| 16 |
+
# Assuming tariff rate is mentioned as a numeric value in PKR/unit
|
| 17 |
+
for row in data:
|
| 18 |
+
if "PKR" in row: # Replace with specific logic matching the structure of the scraped data
|
| 19 |
+
try:
|
| 20 |
+
tariff_rate = float(row.split()[1]) # Adjust this parsing logic based on your data
|
| 21 |
+
break
|
| 22 |
+
except (ValueError, IndexError):
|
| 23 |
+
continue
|
| 24 |
+
if tariff_rate == 0.0:
|
| 25 |
+
st.warning("Could not fetch tariff rates. Using default rate of PKR 20.0/unit.")
|
| 26 |
+
tariff_rate = 20.0 # Default rate
|
| 27 |
|
| 28 |
# Electricity Bill Calculator Section
|
| 29 |
st.write("## Electricity Bill Calculator")
|
|
|
|
| 33 |
"Fan": 75, "Air Conditioner (1 Ton)": 1500, "Refrigerator": 150,
|
| 34 |
"LED Bulb (20W)": 20, "Iron": 1000, "Microwave Oven": 1200
|
| 35 |
}
|
| 36 |
+
|
| 37 |
appliance = st.sidebar.selectbox("Select Appliance", options=list(appliances.keys()))
|
| 38 |
quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
|
| 39 |
usage_hours = st.sidebar.number_input("Usage Hours/Day", min_value=1.0, value=6.0)
|
|
|
|
| 62 |
app["quantity"] * app["load"] * app["usage_hours"] / 1000 for app in st.session_state["appliances"]
|
| 63 |
)
|
| 64 |
bill = total_units * 30 * tariff_rate
|
| 65 |
+
st.success(f"Estimated Monthly Bill: PKR {bill:.2f} (Tariff Rate: PKR {tariff_rate:.2f}/unit)")
|
| 66 |
else:
|
| 67 |
st.warning("No appliances added for calculation.")
|
| 68 |
|