Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import streamlit as st
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
-
|
| 5 |
# Sample AQI data (replace with your actual data source)
|
| 6 |
data = {
|
| 7 |
'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']),
|
|
@@ -13,7 +13,7 @@ data = {
|
|
| 13 |
'NO2': [15, 25, 30, 20, 12]
|
| 14 |
}
|
| 15 |
df = pd.DataFrame(data)
|
| 16 |
-
|
| 17 |
# AQI Categories and Health Recommendations
|
| 18 |
aqi_categories = {
|
| 19 |
(0, 50): {'label': 'Good', 'color': 'green', 'recommendations': {
|
|
@@ -59,10 +59,10 @@ aqi_categories = {
|
|
| 59 |
'general': 'Health emergency: a health alert indicates that everyone may experience more serious health effects.'
|
| 60 |
}}
|
| 61 |
}
|
| 62 |
-
|
| 63 |
# Streamlit app
|
| 64 |
st.title('Air Quality Dashboard')
|
| 65 |
-
|
| 66 |
# Current AQI and Category
|
| 67 |
current_aqi = df['AQI'].iloc[-1]
|
| 68 |
current_category = None
|
|
@@ -70,9 +70,13 @@ for aqi_range, category_data in aqi_categories.items():
|
|
| 70 |
if aqi_range[0] <= current_aqi <= aqi_range[1]:
|
| 71 |
current_category = category_data
|
| 72 |
break
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
# Gauge chart for AQI
|
| 77 |
fig_gauge = go.Figure(go.Indicator(
|
| 78 |
mode="gauge+number",
|
|
@@ -90,20 +94,18 @@ fig_gauge = go.Figure(go.Indicator(
|
|
| 90 |
}
|
| 91 |
))
|
| 92 |
st.plotly_chart(fig_gauge)
|
| 93 |
-
|
| 94 |
-
|
| 95 |
# Detailed Pollutant Levels
|
| 96 |
st.subheader('Detailed Pollutant Levels')
|
| 97 |
st.line_chart(df[['PM2.5', 'O3', 'CO', 'SO2', 'NO2']])
|
| 98 |
-
|
| 99 |
# Health Recommendations
|
| 100 |
st.subheader('Health Recommendations')
|
| 101 |
-
|
| 102 |
st.write(f"**General:** {current_category['recommendations']['general']}")
|
| 103 |
st.write(f"**Heart Patients:** {current_category['recommendations']['heart_patients']}")
|
| 104 |
st.write(f"**Old Age:** {current_category['recommendations']['old_age']}")
|
| 105 |
st.write(f"**Mid Age:** {current_category['recommendations']['mid_age']}")
|
| 106 |
st.write(f"**Young Age:** {current_category['recommendations']['young_age']}")
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
# Add more visualizations (e.g., bar charts for pollutant comparison) as needed.
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import streamlit as st
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
+
|
| 5 |
# Sample AQI data (replace with your actual data source)
|
| 6 |
data = {
|
| 7 |
'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']),
|
|
|
|
| 13 |
'NO2': [15, 25, 30, 20, 12]
|
| 14 |
}
|
| 15 |
df = pd.DataFrame(data)
|
| 16 |
+
|
| 17 |
# AQI Categories and Health Recommendations
|
| 18 |
aqi_categories = {
|
| 19 |
(0, 50): {'label': 'Good', 'color': 'green', 'recommendations': {
|
|
|
|
| 59 |
'general': 'Health emergency: a health alert indicates that everyone may experience more serious health effects.'
|
| 60 |
}}
|
| 61 |
}
|
| 62 |
+
|
| 63 |
# Streamlit app
|
| 64 |
st.title('Air Quality Dashboard')
|
| 65 |
+
|
| 66 |
# Current AQI and Category
|
| 67 |
current_aqi = df['AQI'].iloc[-1]
|
| 68 |
current_category = None
|
|
|
|
| 70 |
if aqi_range[0] <= current_aqi <= aqi_range[1]:
|
| 71 |
current_category = category_data
|
| 72 |
break
|
| 73 |
+
|
| 74 |
+
# Display AQI with color
|
| 75 |
+
st.markdown(
|
| 76 |
+
f"<h2 style='color: {current_category['color']}'>Current AQI: {current_aqi} ({current_category['label']})</h2>",
|
| 77 |
+
unsafe_allow_html=True
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
# Gauge chart for AQI
|
| 81 |
fig_gauge = go.Figure(go.Indicator(
|
| 82 |
mode="gauge+number",
|
|
|
|
| 94 |
}
|
| 95 |
))
|
| 96 |
st.plotly_chart(fig_gauge)
|
| 97 |
+
|
|
|
|
| 98 |
# Detailed Pollutant Levels
|
| 99 |
st.subheader('Detailed Pollutant Levels')
|
| 100 |
st.line_chart(df[['PM2.5', 'O3', 'CO', 'SO2', 'NO2']])
|
| 101 |
+
|
| 102 |
# Health Recommendations
|
| 103 |
st.subheader('Health Recommendations')
|
| 104 |
+
|
| 105 |
st.write(f"**General:** {current_category['recommendations']['general']}")
|
| 106 |
st.write(f"**Heart Patients:** {current_category['recommendations']['heart_patients']}")
|
| 107 |
st.write(f"**Old Age:** {current_category['recommendations']['old_age']}")
|
| 108 |
st.write(f"**Mid Age:** {current_category['recommendations']['mid_age']}")
|
| 109 |
st.write(f"**Young Age:** {current_category['recommendations']['young_age']}")
|
| 110 |
+
|
| 111 |
+
# Add more visualizations (e.g., bar charts for pollutant comparison) as needed.
|
|
|