Update app.py
Browse files
app.py
CHANGED
|
@@ -3,99 +3,127 @@ import pandas as pd
|
|
| 3 |
import plotly.express as px
|
| 4 |
import pydeck as pdk
|
| 5 |
|
| 6 |
-
# Set page
|
| 7 |
-
st.set_page_config(page_title="Air Quality Dashboard", layout="wide")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
st.markdown("""
|
| 11 |
<style>
|
| 12 |
-
.
|
|
|
|
| 13 |
padding: 20px;
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
margin: 10px;
|
| 18 |
}
|
| 19 |
-
.header
|
| 20 |
-
font-size:
|
| 21 |
font-weight: bold;
|
| 22 |
-
color: #
|
| 23 |
text-align: center;
|
|
|
|
| 24 |
margin-bottom: 20px;
|
| 25 |
}
|
| 26 |
-
.
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
-
.
|
| 31 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
font-weight: bold;
|
| 33 |
}
|
| 34 |
</style>
|
| 35 |
""", unsafe_allow_html=True)
|
| 36 |
|
| 37 |
-
# Sidebar for
|
| 38 |
st.sidebar.header("Air Quality Monitoring")
|
| 39 |
station_list = ["Louisville", "Lexington", "Richmond", "Elizabethtown"]
|
| 40 |
selected_station = st.sidebar.selectbox("Select AQI Station", station_list)
|
| 41 |
|
| 42 |
-
# Mock data
|
| 43 |
aqi_data = {
|
| 44 |
"Louisville": {"AQI": 50, "Pollutant": "Carbon Monoxide", "CO_ppb": 572.21},
|
| 45 |
-
"Lexington": {"AQI":
|
| 46 |
-
"Richmond": {"AQI":
|
| 47 |
-
"Elizabethtown": {"AQI": 85, "Pollutant": "Sulfur Dioxide", "SO2_ppb":
|
| 48 |
}
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
st.markdown("<div class='header
|
| 52 |
|
| 53 |
-
#
|
| 54 |
station_data = aqi_data[selected_station]
|
| 55 |
-
col1, col2 = st.columns(2)
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
with col1:
|
| 58 |
-
st.markdown("<div class='
|
| 59 |
st.metric(label="Air Quality Index (AQI)", value=station_data["AQI"])
|
| 60 |
st.write(f"**Top Pollutant:** {station_data['Pollutant']}")
|
| 61 |
st.write(f"**Concentration:** {station_data.get('CO_ppb', station_data.get('PM25_ug/m3', 'N/A'))} ppb/µg/m³")
|
| 62 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 63 |
|
|
|
|
| 64 |
with col2:
|
| 65 |
-
st.markdown("<div class='
|
|
|
|
|
|
|
|
|
|
| 66 |
if station_data["AQI"] <= 50:
|
| 67 |
-
|
| 68 |
elif station_data["AQI"] <= 100:
|
| 69 |
-
|
| 70 |
elif station_data["AQI"] <= 150:
|
| 71 |
-
|
| 72 |
else:
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
st.subheader("AQI
|
| 78 |
trend_data = pd.DataFrame({
|
| 79 |
"Date": ["2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04"],
|
| 80 |
-
"AQI": [station_data["AQI"] -
|
| 81 |
})
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 86 |
|
| 87 |
-
#
|
| 88 |
-
st.subheader("
|
| 89 |
map_data = pd.DataFrame(
|
| 90 |
[
|
| 91 |
{"lat": 38.2527, "lon": -85.7585, "AQI": 50}, # Louisville
|
| 92 |
-
{"lat": 38.0406, "lon": -84.5037, "AQI":
|
| 93 |
-
{"lat": 37.7479, "lon": -84.2947, "AQI":
|
| 94 |
-
{"lat": 37.6939, "lon": -85.8591, "AQI": 85},
|
| 95 |
]
|
| 96 |
)
|
| 97 |
|
| 98 |
-
# Render map with
|
| 99 |
aqi_map = pdk.Deck(
|
| 100 |
map_style="mapbox://styles/mapbox/light-v9",
|
| 101 |
initial_view_state=pdk.ViewState(
|
|
@@ -110,7 +138,7 @@ aqi_map = pdk.Deck(
|
|
| 110 |
data=map_data,
|
| 111 |
get_position="[lon, lat]",
|
| 112 |
get_radius=5000,
|
| 113 |
-
get_fill_color="[255-AQI,
|
| 114 |
pickable=True,
|
| 115 |
)
|
| 116 |
],
|
|
@@ -118,6 +146,6 @@ aqi_map = pdk.Deck(
|
|
| 118 |
|
| 119 |
st.pydeck_chart(aqi_map)
|
| 120 |
|
| 121 |
-
# Footer
|
| 122 |
st.write("---")
|
| 123 |
st.write("Learn more about air quality and its impact [here](https://www.epa.gov/air-quality-index).")
|
|
|
|
| 3 |
import plotly.express as px
|
| 4 |
import pydeck as pdk
|
| 5 |
|
| 6 |
+
# Set page layout and title
|
| 7 |
+
st.set_page_config(page_title="AI-Powered Air Quality Dashboard", layout="wide")
|
| 8 |
|
| 9 |
+
# CSS for custom styling
|
| 10 |
st.markdown("""
|
| 11 |
<style>
|
| 12 |
+
.card {
|
| 13 |
+
background-color: #ffffff;
|
| 14 |
padding: 20px;
|
| 15 |
+
border-radius: 15px;
|
| 16 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
| 17 |
+
margin-bottom: 20px;
|
|
|
|
| 18 |
}
|
| 19 |
+
.header {
|
| 20 |
+
font-size: 26px;
|
| 21 |
font-weight: bold;
|
| 22 |
+
color: #333333;
|
| 23 |
text-align: center;
|
| 24 |
+
margin-top: 10px;
|
| 25 |
margin-bottom: 20px;
|
| 26 |
}
|
| 27 |
+
.subheader {
|
| 28 |
+
font-size: 20px;
|
| 29 |
+
color: #555555;
|
| 30 |
+
font-weight: 600;
|
| 31 |
+
margin-top: 10px;
|
| 32 |
+
margin-bottom: 15px;
|
| 33 |
}
|
| 34 |
+
.recommendation {
|
| 35 |
+
background-color: #f0f9ff;
|
| 36 |
+
padding: 15px;
|
| 37 |
+
border-radius: 10px;
|
| 38 |
+
border-left: 5px solid #007bff;
|
| 39 |
+
color: #007bff;
|
| 40 |
font-weight: bold;
|
| 41 |
}
|
| 42 |
</style>
|
| 43 |
""", unsafe_allow_html=True)
|
| 44 |
|
| 45 |
+
# Sidebar for user interaction
|
| 46 |
st.sidebar.header("Air Quality Monitoring")
|
| 47 |
station_list = ["Louisville", "Lexington", "Richmond", "Elizabethtown"]
|
| 48 |
selected_station = st.sidebar.selectbox("Select AQI Station", station_list)
|
| 49 |
|
| 50 |
+
# Mock air quality data (can be replaced with real data)
|
| 51 |
aqi_data = {
|
| 52 |
"Louisville": {"AQI": 50, "Pollutant": "Carbon Monoxide", "CO_ppb": 572.21},
|
| 53 |
+
"Lexington": {"AQI": 150, "Pollutant": "Ozone", "O3_ppb": 70.00},
|
| 54 |
+
"Richmond": {"AQI": 400, "Pollutant": "PM2.5", "PM25_ug/m3": 180.00},
|
| 55 |
+
"Elizabethtown": {"AQI": 85, "Pollutant": "Sulfur Dioxide", "SO2_ppb": 15.00},
|
| 56 |
}
|
| 57 |
|
| 58 |
+
# Header
|
| 59 |
+
st.markdown("<div class='header'>AI-Powered Air Quality Dashboard</div>", unsafe_allow_html=True)
|
| 60 |
|
| 61 |
+
# Get selected station's data
|
| 62 |
station_data = aqi_data[selected_station]
|
|
|
|
| 63 |
|
| 64 |
+
# --- Cards Section ---
|
| 65 |
+
col1, col2, col3 = st.columns(3)
|
| 66 |
+
|
| 67 |
+
# Card 1: AQI Summary
|
| 68 |
with col1:
|
| 69 |
+
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 70 |
st.metric(label="Air Quality Index (AQI)", value=station_data["AQI"])
|
| 71 |
st.write(f"**Top Pollutant:** {station_data['Pollutant']}")
|
| 72 |
st.write(f"**Concentration:** {station_data.get('CO_ppb', station_data.get('PM25_ug/m3', 'N/A'))} ppb/µg/m³")
|
| 73 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 74 |
|
| 75 |
+
# Card 2: AI Recommendation
|
| 76 |
with col2:
|
| 77 |
+
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 78 |
+
st.write("<div class='subheader'>AI Recommendation</div>", unsafe_allow_html=True)
|
| 79 |
+
|
| 80 |
+
# Generate recommendation based on AQI severity
|
| 81 |
if station_data["AQI"] <= 50:
|
| 82 |
+
recommendation = "The air quality is good. It's a great day to enjoy outdoor activities."
|
| 83 |
elif station_data["AQI"] <= 100:
|
| 84 |
+
recommendation = "The air quality is moderate. Sensitive groups may need to limit prolonged outdoor activities."
|
| 85 |
elif station_data["AQI"] <= 150:
|
| 86 |
+
recommendation = "Unhealthy for sensitive groups. Reduce outdoor exertion if you have heart or lung conditions."
|
| 87 |
else:
|
| 88 |
+
recommendation = "The air is hazardous. It's strongly recommended to stay indoors and use air purifiers."
|
| 89 |
+
|
| 90 |
+
st.markdown(f"<div class='recommendation'>{recommendation}</div>", unsafe_allow_html=True)
|
| 91 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 92 |
+
|
| 93 |
+
# Card 3: Health Impact Insights
|
| 94 |
+
with col3:
|
| 95 |
+
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 96 |
+
st.write("<div class='subheader'>Health Impact</div>", unsafe_allow_html=True)
|
| 97 |
+
st.write("""
|
| 98 |
+
- **General Population:** No immediate danger at low AQI levels.
|
| 99 |
+
- **Sensitive Groups:** Individuals with heart or lung conditions may experience symptoms at higher AQI.
|
| 100 |
+
""")
|
| 101 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 102 |
|
| 103 |
+
# --- Trends Visualization ---
|
| 104 |
+
st.subheader("AQI Trends Over Time")
|
| 105 |
trend_data = pd.DataFrame({
|
| 106 |
"Date": ["2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04"],
|
| 107 |
+
"AQI": [station_data["AQI"] - 20, station_data["AQI"], station_data["AQI"] + 30, station_data["AQI"] - 10]
|
| 108 |
})
|
| 109 |
|
| 110 |
+
trend_chart = px.line(trend_data, x="Date", y="AQI", title=f"AQI Trend for {selected_station}")
|
| 111 |
+
trend_chart.update_traces(line=dict(color="#007bff"))
|
| 112 |
+
trend_chart.update_layout(plot_bgcolor="rgba(0,0,0,0)", paper_bgcolor="rgba(0,0,0,0)")
|
| 113 |
+
st.plotly_chart(trend_chart, use_container_width=True)
|
| 114 |
|
| 115 |
+
# --- Map Section ---
|
| 116 |
+
st.subheader("Air Quality Stations Map")
|
| 117 |
map_data = pd.DataFrame(
|
| 118 |
[
|
| 119 |
{"lat": 38.2527, "lon": -85.7585, "AQI": 50}, # Louisville
|
| 120 |
+
{"lat": 38.0406, "lon": -84.5037, "AQI": 150}, # Lexington
|
| 121 |
+
{"lat": 37.7479, "lon": -84.2947, "AQI": 400}, # Richmond
|
| 122 |
+
{"lat": 37.6939, "lon": -85.8591, "AQI": 85}, # Elizabethtown
|
| 123 |
]
|
| 124 |
)
|
| 125 |
|
| 126 |
+
# Render the map with AQI points
|
| 127 |
aqi_map = pdk.Deck(
|
| 128 |
map_style="mapbox://styles/mapbox/light-v9",
|
| 129 |
initial_view_state=pdk.ViewState(
|
|
|
|
| 138 |
data=map_data,
|
| 139 |
get_position="[lon, lat]",
|
| 140 |
get_radius=5000,
|
| 141 |
+
get_fill_color="[255-AQI, 100, AQI/2, 150]",
|
| 142 |
pickable=True,
|
| 143 |
)
|
| 144 |
],
|
|
|
|
| 146 |
|
| 147 |
st.pydeck_chart(aqi_map)
|
| 148 |
|
| 149 |
+
# --- Footer ---
|
| 150 |
st.write("---")
|
| 151 |
st.write("Learn more about air quality and its impact [here](https://www.epa.gov/air-quality-index).")
|