Engineer786 commited on
Commit
683d25b
·
verified ·
1 Parent(s): 473a876

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -52
app.py CHANGED
@@ -1,53 +1,24 @@
1
- import os
2
- import requests
3
  import streamlit as st
4
- import pandas as pd
5
- from scraper import scrape_tariffs
6
- from sentence_transformers import SentenceTransformer
7
-
8
- # Replace the model loading approach with hf_hub_download to avoid cached_download error
9
- def download_model():
10
- model_repo_id = "sentence-transformers/all-MiniLM-L6-v2"
11
-
12
- # Initialize Streamlit components
13
- st.title("Electricity Bill Estimator")
14
- st.sidebar.header("User Input")
15
-
16
- tariff_urls = {
17
- "IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide",
18
- "FESCO": "https://fesco.com.pk/tariff",
19
- "HESCO": "http://www.hesco.gov.pk/htmls/tariffs.htm",
20
- "KE": "https://www.ke.com.pk/customer-services/tariff-structure/",
21
- "LESCO": "https://www.lesco.gov.pk/ElectricityTariffs",
22
- "PESCO": "https://pesconlinebill.pk/pesco-tariff/",
23
- "QESCO": "http://qesco.com.pk/Tariffs.aspx",
24
- "TESCO": "https://tesco.gov.pk/index.php/electricity-traiff"
25
- }
26
-
27
- def show_tariff_input():
28
- # Display tariff rates selection
29
- tariff_data = pd.read_csv("data/tariffs.csv")
30
- tariff_types = tariff_data["category"].unique()
31
- tariff_choice = st.selectbox("Select your tariff category:", tariff_types)
32
- st.write(f"Selected Tariff: {tariff_choice}")
33
-
34
- def scrape_data():
35
- # Scraping tariff data using provided URLs
36
- scrape_tariffs(list(tariff_urls.values()))
37
-
38
- # Streamlit actions
39
- if st.sidebar.button("Scrape Data"):
40
- scrape_data()
41
-
42
- if st.sidebar.button("Download Model"):
43
- download_model()
44
-
45
- # User inputs for appliance and usage time (replace placeholders as needed)
46
- appliance_load = st.number_input("Enter appliance load in watts", min_value=10, max_value=5000, value=1000)
47
- usage_time = st.number_input("Enter usage time (in hours)", min_value=1, max_value=24, value=5)
48
-
49
- # Placeholder for electricity bill calculation and output display
50
- if appliance_load and usage_time:
51
- bill_amount = appliance_load * usage_time * 0.25 # Add your own calculation based on tariffs
52
- st.write(f"Your electricity bill: {bill_amount} PKR")
53
-
 
 
 
1
  import streamlit as st
2
+ from tariff_scraper import TARIFF_URLS, scrape_tariff_data
3
+
4
+ def main():
5
+ st.title("PESCO Tariff Rates Viewer")
6
+ st.write("This app fetches and displays the latest PESCO tariff rates.")
7
+
8
+ # Display the fetch button
9
+ if st.button("Fetch PESCO Tariff Rates"):
10
+ url = TARIFF_URLS["PESCO"]
11
+ st.write(f"Fetching data from {url}...")
12
+
13
+ with st.spinner("Scraping data..."):
14
+ data = scrape_tariff_data(url)
15
+ if data and isinstance(data, list) and len(data) > 0:
16
+ st.success("Data fetched successfully!")
17
+ st.write("### Tariff Rates:")
18
+ for row in data:
19
+ st.write(row)
20
+ else:
21
+ st.error("Failed to fetch tariff data or no data found.")
22
+
23
+ if __name__ == "__main__":
24
+ main()