Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,93 +1,53 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
-
from tariff_scraper import fetch_tariff_data
|
| 4 |
import pandas as pd
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
-
"
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"
|
| 24 |
-
"
|
| 25 |
-
"Water Pump": 1000,
|
| 26 |
-
"Geyser (Electric)": 3000
|
| 27 |
}
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"""Calculate total units consumed in kWh."""
|
| 36 |
-
total_energy_wh = 0
|
| 37 |
-
for data in st.session_state.appliance_data:
|
| 38 |
-
total_energy_wh += data["quantity"] * data["load"] * data["usage_hours"]
|
| 39 |
-
return total_energy_wh / 1000 # Convert watt-hours to kilowatt-hours
|
| 40 |
|
| 41 |
-
def
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
response = client.chat.completions.create(
|
| 45 |
-
messages=[
|
| 46 |
-
{
|
| 47 |
-
"role": "user",
|
| 48 |
-
"content": f"Provide tariff rate for {units} units consumed in PKR."
|
| 49 |
-
}
|
| 50 |
-
],
|
| 51 |
-
model="llama3-8b-8192",
|
| 52 |
-
)
|
| 53 |
-
return float(response.choices[0].message.content.strip())
|
| 54 |
-
except Exception as e:
|
| 55 |
-
st.error(f"Error fetching tariff from Groq: {e}")
|
| 56 |
-
return None
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
appliance = st.sidebar.selectbox("Select Appliance", options=list(APPLIANCE_OPTIONS.keys()))
|
| 63 |
-
default_load = APPLIANCE_OPTIONS[appliance]
|
| 64 |
-
quantity = st.sidebar.number_input("Number of Appliances", min_value=1, value=1)
|
| 65 |
-
load = st.sidebar.number_input("Load (Watts per Appliance)", min_value=1, value=default_load)
|
| 66 |
-
usage_hours = st.sidebar.number_input("Usage Time (Hours per Day)", min_value=0.0, value=6.0)
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
"load": load,
|
| 72 |
-
"quantity": quantity,
|
| 73 |
-
"usage_hours": usage_hours
|
| 74 |
-
})
|
| 75 |
-
st.sidebar.success(f"Added {quantity} {appliance}(s) to the list!")
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
st.write(f"{idx}. {data['appliance']} - {data['quantity']} units, {data['load']}W each, {data['usage_hours']} hours/day")
|
| 82 |
-
else:
|
| 83 |
-
st.write("No appliances added.")
|
| 84 |
|
| 85 |
-
# Calculate Monthly Units and Electricity Bill
|
| 86 |
-
if st.button("Calculate Monthly Bill"):
|
| 87 |
-
total_units_kwh = calculate_total_units() * 30 # Assuming 30 days in a month
|
| 88 |
-
st.write(f"**Total Units Consumed (kWh): {total_units_kwh:.2f}**")
|
| 89 |
-
tariff_rate = fetch_tariff_from_groq(total_units_kwh)
|
| 90 |
-
if tariff_rate:
|
| 91 |
-
monthly_bill = total_units_kwh * tariff_rate
|
| 92 |
-
st.subheader("Electricity Bill")
|
| 93 |
-
st.write(f"**Total Monthly Bill: PKR {monthly_bill:.2f}**")
|
|
|
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|