Spaces:
Build error
Build error
| import streamlit as st | |
| import pandas as pd | |
| import tariff_scraper | |
| # UI Components | |
| def main(): | |
| st.sidebar.title("Electricity Tariff App") | |
| st.sidebar.header("Navigation") | |
| # Button to Fetch Tariff Data | |
| if st.sidebar.button("Fetch Tariff Data"): | |
| url = "https://iesco.com.pk/index.php/customer-services/tariff-guide" | |
| try: | |
| tariff_data = tariff_scraper.fetch_tariff_data(url) | |
| tariff_scraper.save_tariff_data(tariff_data, "tariff_data.xlsx") | |
| st.success("Tariff data fetched and saved successfully!") | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| # Dropdown for Load Type | |
| tariff_data_file = "tariff_data.xlsx" | |
| if st.sidebar.button("Load Tariff Data"): | |
| try: | |
| tariffs = pd.ExcelFile(tariff_data_file) | |
| sections = tariffs.sheet_names | |
| selected_section = st.sidebar.selectbox("Select Tariff Section", sections) | |
| df = tariffs.parse(selected_section) | |
| st.write(f"### {selected_section}") | |
| st.dataframe(df) | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| st.header("Electricity Bill Calculator") | |
| appliances = [] | |
| # Appliance Input Section | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| appliance_name = st.text_input("Appliance Name") | |
| with col2: | |
| appliance_count = st.number_input("Number of Appliances", min_value=1, step=1) | |
| with col3: | |
| usage_hours = st.number_input("Usage Hours per Day", min_value=0.0, step=0.5) | |
| if st.button("Add Appliance"): | |
| appliances.append((appliance_name, appliance_count, usage_hours)) | |
| st.write(f"Added {appliance_name}: {appliance_count} appliances used {usage_hours} hours/day.") | |
| # Calculate Bill | |
| if st.button("Calculate Bill"): | |
| if not appliances: | |
| st.error("Please add appliances before calculating.") | |
| else: | |
| total_units = sum(appliance_count * usage_hours * 30 for _, appliance_count, usage_hours in appliances) | |
| st.write(f"Total Units Consumed: {total_units} kWh") | |
| if __name__ == "__main__": | |
| main() | |