Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,68 +1,10 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
from tariff_scraper import scrape_tariff_data
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
with st.spinner("Fetching tariff rates..."):
|
| 13 |
-
data = scrape_tariff_data(url)
|
| 14 |
-
if isinstance(data, dict): # Check if data is a valid dictionary
|
| 15 |
-
st.session_state["tariff_rates"] = data
|
| 16 |
-
st.sidebar.success("Tariff rates fetched successfully!")
|
| 17 |
-
st.write("### Tariff Rates")
|
| 18 |
-
for category, rate in data.items():
|
| 19 |
-
st.write(f"{category}: {rate} PKR/unit")
|
| 20 |
-
else:
|
| 21 |
-
st.sidebar.error(data)
|
| 22 |
-
|
| 23 |
-
# Use fetched tariff rates
|
| 24 |
-
tariff_categories = st.session_state.get("tariff_rates", {})
|
| 25 |
-
if tariff_categories:
|
| 26 |
-
load_type = st.sidebar.selectbox("Select Load Type", options=tariff_categories.keys())
|
| 27 |
-
tariff_rate = tariff_categories.get(load_type, 0.0)
|
| 28 |
-
else:
|
| 29 |
-
st.sidebar.warning("Using default rate. Fetch tariff rates to use live data.")
|
| 30 |
-
load_type = "Default"
|
| 31 |
-
tariff_rate = st.sidebar.number_input("Default Tariff Rate (PKR/unit)", min_value=0.0, value=20.0)
|
| 32 |
-
|
| 33 |
-
# Electricity bill calculation
|
| 34 |
-
st.sidebar.subheader("Appliance Usage")
|
| 35 |
-
appliances = {
|
| 36 |
-
"Fan": 75, "Air Conditioner (1 Ton)": 1500, "Refrigerator": 150,
|
| 37 |
-
"LED Bulb (20W)": 20, "Iron": 1000, "Microwave Oven": 1200
|
| 38 |
-
}
|
| 39 |
-
appliance = st.sidebar.selectbox("Select Appliance", options=appliances.keys())
|
| 40 |
-
quantity = st.sidebar.number_input("Quantity", min_value=1, value=1)
|
| 41 |
-
usage_hours = st.sidebar.number_input("Usage Hours/Day", min_value=1.0, value=6.0)
|
| 42 |
-
|
| 43 |
-
if st.sidebar.button("Add Appliance"):
|
| 44 |
-
st.session_state.setdefault("appliances", []).append({
|
| 45 |
-
"appliance": appliance,
|
| 46 |
-
"load": appliances[appliance],
|
| 47 |
-
"quantity": quantity,
|
| 48 |
-
"usage_hours": usage_hours
|
| 49 |
-
})
|
| 50 |
-
st.sidebar.success(f"{quantity} x {appliance} added.")
|
| 51 |
-
|
| 52 |
-
# Display appliances and calculate bill
|
| 53 |
-
st.write("### Selected Appliances")
|
| 54 |
-
if "appliances" in st.session_state:
|
| 55 |
-
for app in st.session_state["appliances"]:
|
| 56 |
-
st.write(f"{app['quantity']} x {app['appliance']} ({app['usage_hours']} hours/day)")
|
| 57 |
-
|
| 58 |
-
if st.button("Calculate Bill"):
|
| 59 |
-
total_units = sum(
|
| 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 for {load_type}: PKR {bill:.2f}")
|
| 64 |
-
else:
|
| 65 |
-
st.write("No appliances added yet.")
|
| 66 |
-
|
| 67 |
-
if __name__ == "__main__":
|
| 68 |
-
main()
|
|
|
|
|
|
|
| 1 |
from tariff_scraper import scrape_tariff_data
|
| 2 |
|
| 3 |
+
url = "https://iesco.com.pk/index.php/customer-services/tariff-guide"
|
| 4 |
+
data = scrape_tariff_data(url)
|
| 5 |
+
if isinstance(data, list):
|
| 6 |
+
print("Scraped Data:")
|
| 7 |
+
for row in data[:10]: # Print the first 10 rows
|
| 8 |
+
print(row)
|
| 9 |
+
else:
|
| 10 |
+
print(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|