Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from tariff_scraper import fetch_tariff_data, save_tariff_data
|
|
|
|
| 4 |
|
| 5 |
# Predefined appliance list with typical loads in watts
|
| 6 |
APPLIANCE_OPTIONS = {
|
|
@@ -59,10 +60,15 @@ if st.sidebar.button("Fetch Tariff"):
|
|
| 59 |
if load_type in tariff_data:
|
| 60 |
df = tariff_data[load_type]
|
| 61 |
if "Variable Rs/kWh" in df.columns:
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
else:
|
| 65 |
-
st.sidebar.error(f"Variable Rs/kWh not found in {load_type}.")
|
| 66 |
else:
|
| 67 |
st.sidebar.warning(f"No data available for {load_type}.")
|
| 68 |
except Exception as e:
|
|
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from tariff_scraper import fetch_tariff_data, save_tariff_data
|
| 4 |
+
import pandas as pd
|
| 5 |
|
| 6 |
# Predefined appliance list with typical loads in watts
|
| 7 |
APPLIANCE_OPTIONS = {
|
|
|
|
| 60 |
if load_type in tariff_data:
|
| 61 |
df = tariff_data[load_type]
|
| 62 |
if "Variable Rs/kWh" in df.columns:
|
| 63 |
+
# Filter numeric values only
|
| 64 |
+
df_numeric = df[pd.to_numeric(df["Variable Rs/kWh"], errors="coerce").notnull()]
|
| 65 |
+
if not df_numeric.empty:
|
| 66 |
+
st.session_state.tariff_rate = float(df_numeric["Variable Rs/kWh"].iloc[0])
|
| 67 |
+
st.sidebar.success(f"Tariff fetched for {load_type}: {st.session_state.tariff_rate} PKR/unit")
|
| 68 |
+
else:
|
| 69 |
+
st.sidebar.warning(f"No numeric tariff rates found for {load_type}.")
|
| 70 |
else:
|
| 71 |
+
st.sidebar.error(f"Variable Rs/kWh column not found in {load_type}.")
|
| 72 |
else:
|
| 73 |
st.sidebar.warning(f"No data available for {load_type}.")
|
| 74 |
except Exception as e:
|