Engineer786 commited on
Commit
a44b04f
Β·
verified Β·
1 Parent(s): 517d947

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -36
app.py CHANGED
@@ -11,7 +11,7 @@ tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v
11
  model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
12
 
13
  # Streamlit App: Electricity Bill Estimator
14
- st.title("πŸ”Œ Electricity Bill Estimator")
15
  st.sidebar.header("βš™οΈ User Input")
16
 
17
  # Tariff URLs for scraping
@@ -26,17 +26,19 @@ tariff_urls = {
26
  "TESCO": "https://tesco.gov.pk/index.php/electricity-traiff",
27
  }
28
 
29
- def show_tariff_input():
30
- """
31
- Displays a dropdown menu for tariff categories loaded from a CSV file.
32
- """
33
- try:
34
- tariff_data = pd.read_csv("data/tariffs.csv")
35
- tariff_types = tariff_data["category"].unique()
36
- tariff_choice = st.selectbox("Select your tariff category:", tariff_types)
37
- st.write(f"βœ… Selected Tariff: **{tariff_choice}**")
38
- except FileNotFoundError:
39
- st.error("⚠️ Tariff data not found. Please ensure 'data/tariffs.csv' exists.")
 
 
40
 
41
  def scrape_data():
42
  """
@@ -57,36 +59,53 @@ def calculate_carbon_footprint(monthly_energy_kwh):
57
  if st.sidebar.button("Scrape Tariff Data"):
58
  scrape_data()
59
 
60
- # User Inputs for Electricity Usage
61
- st.subheader("πŸ’‘ Electricity Usage Input")
62
- appliance_load = st.number_input(
63
- "Enter appliance load in watts:",
64
- min_value=10, max_value=5000, value=1000
 
65
  )
66
- usage_time = st.number_input(
67
- "Enter daily usage time (in hours):",
68
- min_value=1, max_value=24, value=5
69
  )
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  # Electricity Bill and Carbon Footprint Calculation
72
- if appliance_load and usage_time:
73
- daily_energy_kwh = (appliance_load * usage_time) / 1000 # Convert to kWh
74
- monthly_energy_kwh = daily_energy_kwh * 30 # Assume 30 days in a month
 
 
 
75
  bill_amount = monthly_energy_kwh * 0.25 # Simplified bill calculation
76
  carbon_footprint = calculate_carbon_footprint(monthly_energy_kwh)
77
 
 
78
  st.write(f"πŸ’΅ **Estimated Electricity Bill**: **{bill_amount:.2f} PKR**")
79
  st.write(f"🌍 **Estimated Carbon Footprint**: **{carbon_footprint:.2f} kg CO2 per month**")
80
-
81
- # Query processing logic remains in the backend, if needed
82
- def process_query(query):
83
- """
84
- Generates embeddings for the given query using the transformer model.
85
- """
86
- inputs = tokenizer(query, return_tensors="pt", padding=True, truncation=True)
87
- with torch.no_grad():
88
- outputs = model(**inputs)
89
- embeddings = outputs.last_hidden_state.mean(dim=1).squeeze().numpy()
90
- return embeddings
91
-
92
- # Note: No user-facing query box displayed on the front-end
 
11
  model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
12
 
13
  # Streamlit App: Electricity Bill Estimator
14
+ st.title("πŸ”Œ Electricity Bill & Carbon Footprint Estimator")
15
  st.sidebar.header("βš™οΈ User Input")
16
 
17
  # Tariff URLs for scraping
 
26
  "TESCO": "https://tesco.gov.pk/index.php/electricity-traiff",
27
  }
28
 
29
+ # Predefined appliances and their power in watts
30
+ appliances = {
31
+ "LED Bulb (10W)": 10,
32
+ "Ceiling Fan (75W)": 75,
33
+ "Refrigerator (150W)": 150,
34
+ "Air Conditioner (1.5 Ton, 1500W)": 1500,
35
+ "Washing Machine (500W)": 500,
36
+ "Television (100W)": 100,
37
+ "Laptop (65W)": 65,
38
+ "Iron (1000W)": 1000,
39
+ "Microwave Oven (1200W)": 1200,
40
+ "Water Heater (2000W)": 2000,
41
+ }
42
 
43
  def scrape_data():
44
  """
 
59
  if st.sidebar.button("Scrape Tariff Data"):
60
  scrape_data()
61
 
62
+ # Sidebar: User Inputs for Appliances
63
+ st.sidebar.subheader("🏠 Add Appliances")
64
+ selected_appliance = st.sidebar.selectbox("Select an appliance:", list(appliances.keys()))
65
+ appliance_power = appliances[selected_appliance]
66
+ appliance_quantity = st.sidebar.number_input(
67
+ "Enter quantity:", min_value=1, max_value=10, value=1
68
  )
69
+ usage_hours = st.sidebar.number_input(
70
+ "Enter usage hours per day:", min_value=1, max_value=24, value=5
 
71
  )
72
 
73
+ # Add appliance details to the main list
74
+ if "appliance_list" not in st.session_state:
75
+ st.session_state["appliance_list"] = []
76
+
77
+ if st.sidebar.button("Add Appliance"):
78
+ st.session_state["appliance_list"].append(
79
+ {
80
+ "appliance": selected_appliance,
81
+ "power": appliance_power,
82
+ "quantity": appliance_quantity,
83
+ "hours": usage_hours,
84
+ }
85
+ )
86
+
87
+ # Display the list of added appliances
88
+ st.subheader("πŸ“‹ Added Appliances")
89
+ if st.session_state["appliance_list"]:
90
+ for idx, appliance in enumerate(st.session_state["appliance_list"], start=1):
91
+ st.write(
92
+ f"{idx}. **{appliance['appliance']}** - "
93
+ f"{appliance['power']}W, {appliance['quantity']} unit(s), "
94
+ f"{appliance['hours']} hours/day"
95
+ )
96
+
97
  # Electricity Bill and Carbon Footprint Calculation
98
+ if st.session_state["appliance_list"]:
99
+ total_daily_energy_kwh = sum(
100
+ (appliance["power"] * appliance["quantity"] * appliance["hours"]) / 1000
101
+ for appliance in st.session_state["appliance_list"]
102
+ )
103
+ monthly_energy_kwh = total_daily_energy_kwh * 30 # Assume 30 days in a month
104
  bill_amount = monthly_energy_kwh * 0.25 # Simplified bill calculation
105
  carbon_footprint = calculate_carbon_footprint(monthly_energy_kwh)
106
 
107
+ st.subheader("πŸ’΅ Electricity Bill & 🌍 Carbon Footprint")
108
  st.write(f"πŸ’΅ **Estimated Electricity Bill**: **{bill_amount:.2f} PKR**")
109
  st.write(f"🌍 **Estimated Carbon Footprint**: **{carbon_footprint:.2f} kg CO2 per month**")
110
+ else:
111
+ st.info("ℹ️ Add appliances to calculate the electricity bill and carbon footprint.")