Engineer786 commited on
Commit
1826faa
·
verified ·
1 Parent(s): 4915bbd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import tariff_scraper
4
+
5
+ # UI Components
6
+ def main():
7
+ st.sidebar.title("Electricity Tariff App")
8
+ st.sidebar.header("Navigation")
9
+
10
+ # Button to Fetch Tariff Data
11
+ if st.sidebar.button("Fetch Tariff Data"):
12
+ url = "https://iesco.com.pk/index.php/customer-services/tariff-guide"
13
+ try:
14
+ tariff_data = tariff_scraper.fetch_tariff_data(url)
15
+ tariff_scraper.save_tariff_data(tariff_data, "tariff_data.xlsx")
16
+ st.success("Tariff data fetched and saved successfully!")
17
+ except Exception as e:
18
+ st.error(f"Error: {e}")
19
+
20
+ # Dropdown for Load Type
21
+ tariff_data_file = "tariff_data.xlsx"
22
+ if st.sidebar.button("Load Tariff Data"):
23
+ try:
24
+ tariffs = pd.ExcelFile(tariff_data_file)
25
+ sections = tariffs.sheet_names
26
+ selected_section = st.sidebar.selectbox("Select Tariff Section", sections)
27
+
28
+ df = tariffs.parse(selected_section)
29
+ st.write(f"### {selected_section}")
30
+ st.dataframe(df)
31
+ except Exception as e:
32
+ st.error(f"Error: {e}")
33
+
34
+ st.header("Electricity Bill Calculator")
35
+ appliances = []
36
+
37
+ # Appliance Input Section
38
+ col1, col2, col3 = st.columns(3)
39
+ with col1:
40
+ appliance_name = st.text_input("Appliance Name")
41
+ with col2:
42
+ appliance_count = st.number_input("Number of Appliances", min_value=1, step=1)
43
+ with col3:
44
+ usage_hours = st.number_input("Usage Hours per Day", min_value=0.0, step=0.5)
45
+
46
+ if st.button("Add Appliance"):
47
+ appliances.append((appliance_name, appliance_count, usage_hours))
48
+ st.write(f"Added {appliance_name}: {appliance_count} appliances used {usage_hours} hours/day.")
49
+
50
+ # Calculate Bill
51
+ if st.button("Calculate Bill"):
52
+ if not appliances:
53
+ st.error("Please add appliances before calculating.")
54
+ else:
55
+ total_units = sum(appliance_count * usage_hours * 30 for _, appliance_count, usage_hours in appliances)
56
+ st.write(f"Total Units Consumed: {total_units} kWh")
57
+
58
+ if __name__ == "__main__":
59
+ main()