Spaces:
Sleeping
Sleeping
| # streamlit_app.py | |
| import streamlit as st | |
| import scraper | |
| # URLs for different companies | |
| tariff_urls = { | |
| "IESCO": "https://iesco.com.pk/index.php/customer-services/tariff-guide", | |
| # Add other companies as needed | |
| } | |
| def main(): | |
| st.title("PowerCalc: AI-Driven Bill & Carbon Footprint Tracker") | |
| # User input | |
| company = st.selectbox("Select your electricity company", list(tariff_urls.keys())) | |
| appliance_name = st.text_input("Appliance Name") | |
| load = st.number_input("Load of Appliance (kW)", min_value=0.0) | |
| daily_usage = st.number_input("Daily Usage Time (hours)", min_value=0.0) | |
| if st.button("Calculate"): | |
| # Fetch the tariff data for the selected company | |
| url = tariff_urls.get(company) | |
| tariff_data = scraper.fetch_tariff_data(url) | |
| if tariff_data: | |
| # Calculate monthly bill and carbon footprint | |
| monthly_bill = calculate_monthly_bill(tariff_data, load, daily_usage) | |
| carbon_footprint = calculate_carbon_footprint(load, daily_usage) | |
| st.write(f"Monthly Bill for {appliance_name}: Rs. {monthly_bill}") | |
| st.write(f"Carbon Footprint: {carbon_footprint} kg CO2") | |
| else: | |
| st.error("Error fetching tariff data. Please try again.") | |
| def calculate_monthly_bill(tariff_data, load, daily_usage): | |
| daily_consumption = load * daily_usage # kWh per day | |
| monthly_consumption = daily_consumption * 30 # kWh per month | |
| total_bill = 0 | |
| for slab in tariff_data: | |
| if monthly_consumption > slab['lower_limit']: | |
| consumption_in_slab = min(monthly_consumption, slab['upper_limit']) - slab['lower_limit'] | |
| total_bill += consumption_in_slab * slab['rate'] | |
| return round(total_bill, 2) | |
| def calculate_carbon_footprint(load, daily_usage): | |
| daily_consumption = load * daily_usage # kWh per day | |
| monthly_consumption = daily_consumption * 30 # kWh per month | |
| emissions_factor = 0.92 # kg CO2 per kWh | |
| carbon_footprint = monthly_consumption * emissions_factor | |
| return round(carbon_footprint, 2) | |
| if __name__ == "__main__": | |
| main() | |