import pandas as pd import streamlit as st import plotly.graph_objects as go # Sample AQI data (replace with your actual data source) data = { 'Timestamp': pd.to_datetime(['2024-07-26 10:00:00', '2024-07-26 11:00:00', '2024-07-26 12:00:00', '2024-07-26 13:00:00', '2024-07-26 14:00:00']), 'AQI': [80, 120, 150, 90, 60], 'PM2.5': [30, 50, 65, 35, 20], 'O3': [40, 60, 80, 50, 30], 'CO': [5, 8, 10, 6, 3], 'SO2': [10, 15, 20, 12, 8], 'NO2': [15, 25, 30, 20, 12] } df = pd.DataFrame(data) # AQI Categories and Health Recommendations aqi_categories = { (0, 50): {'label': 'Good', 'color': 'green', 'recommendations': { 'heart_patients': 'Enjoy your normal activities.', 'old_age': 'Enjoy your normal activities.', 'mid_age': 'Enjoy your normal activities.', 'young_age': 'Enjoy your normal activities.', 'general': 'Air quality is satisfactory.' }}, (51, 100): {'label': 'Moderate', 'color': 'yellow', 'recommendations': { 'heart_patients': 'Consider limiting prolonged or heavy exertion.', 'old_age': 'Consider limiting prolonged or heavy exertion.', 'mid_age': 'Generally acceptable for most.', 'young_age': 'Generally acceptable for most.', 'general': 'Air quality is acceptable; however, unusually sensitive people should consider limiting their outdoor exertion.' }}, (101, 150): {'label': 'Unhealthy for Sensitive Groups', 'color': 'orange', 'recommendations': { 'heart_patients': 'Avoid prolonged or heavy exertion. Consult your doctor if you experience symptoms.', 'old_age': 'Avoid prolonged or heavy exertion. Consult your doctor if you experience symptoms.', 'mid_age': 'Limit prolonged or heavy exertion.', 'young_age': 'Limit prolonged or heavy exertion.', 'general': 'Members of sensitive groups may experience health effects. The general public is not likely to be affected.' }}, (151, 200): {'label': 'Unhealthy', 'color': 'red', 'recommendations': { 'heart_patients': 'Avoid all outdoor exertion. Stay indoors as much as possible. Consult your doctor if you experience symptoms.', 'old_age': 'Avoid all outdoor exertion. Stay indoors as much as possible. Consult your doctor if you experience symptoms.', 'mid_age': 'Avoid all outdoor exertion. Stay indoors as much as possible.', 'young_age': 'Avoid all outdoor exertion. Stay indoors as much as possible.', 'general': 'Everyone may begin to experience health effects; members of sensitive groups may experience more serious health effects.' }}, (201, 300): {'label': 'Very Unhealthy', 'color': 'purple', 'recommendations': { 'heart_patients': 'Remain indoors. Avoid all exertion. Consult your doctor immediately if you experience symptoms.', 'old_age': 'Remain indoors. Avoid all exertion. Consult your doctor immediately if you experience symptoms.', 'mid_age': 'Remain indoors. Avoid all exertion.', 'young_age': 'Remain indoors. Avoid all exertion.', 'general': 'Health alert: everyone may experience more serious health effects.' }}, (301, 500): {'label': 'Hazardous', 'color': 'maroon', 'recommendations': { 'heart_patients': 'Seek immediate medical attention.', 'old_age': 'Seek immediate medical attention.', 'mid_age': 'Seek immediate medical attention.', 'young_age': 'Seek immediate medical attention.', 'general': 'Health emergency: a health alert indicates that everyone may experience more serious health effects.' }} } # Streamlit app st.title('Air Quality Dashboard') # Current AQI and Category current_aqi = df['AQI'].iloc[-1] current_category = None for aqi_range, category_data in aqi_categories.items(): if aqi_range[0] <= current_aqi <= aqi_range[1]: current_category = category_data break # Display AQI with color st.markdown( f"