AQI_SXR / app.py
adil9858's picture
Update app.py
ab6367f verified
raw
history blame
2.58 kB
import streamlit as st
import requests
from bs4 import BeautifulSoup
import datetime
import pytz
# Set the timezone to Indian Standard Time (IST)
indian_timezone = pytz.timezone('Asia/Kolkata')
# Custom CSS for styling
custom_css = """
<style>
body {
color: orange;
background-color: black;
}
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)
# Prescribed limits for AQI and PM2.5
PRESCRIBED_LIMITS = {
'AQI': {
'good': (0, 50),
'moderate': (51, 100),
'unhealthy_sensitive': (101, 150),
'unhealthy': (151, 200),
'very_unhealthy': (201, 300),
'hazardous': (301, 500)
},
'PM2.5': {
'good': (0, 12.0),
'moderate': (12.1, 35.4),
'unhealthy_sensitive': (35.5, 55.5),
'unhealthy': (55.6, 150.4),
'very_unhealthy': (150.5, 250.4),
'hazardous': (250.5, float('inf'))
}
}
# Color codes for different AQI and PM2.5 levels
COLOR_CODES = {
'good': 'green',
'moderate': 'yellow',
'unhealthy_sensitive': 'orange',
'unhealthy': 'red',
'very_unhealthy': 'purple',
'hazardous': 'maroon'
}
def check_safety_level(value, parameter):
for level, limits in PRESCRIBED_LIMITS[parameter].items():
if limits[0] <= value <= limits[1]:
return level
return None
def main():
# Logo
logo = 'LOGO.png'
st.image(logo, width=200)
st.title('Real Time SXR AQI Dashboard')
st.subheader('Real-time Air Quality Monitoring')
aqi, aqi_level, pm25, pm10 = get_aqi_data()
# Display AQI with safety level
st.markdown('### Current Data:')
st.write(f"- **AQI:** {aqi} ({aqi_level})")
aqi_safety = check_safety_level(aqi, 'AQI')
if aqi_safety:
st.write(f"Safety Level: {aqi_safety}")
color_code = COLOR_CODES[aqi_safety]
st.markdown(f'<p style="color:{color_code};">The AQI level is {aqi_safety}.</p>', unsafe_allow_html=True)
# Display PM2.5 with safety level
st.write(f"- **PM2.5:** {pm25} µg/m³")
pm25_safety = check_safety_level(pm25, 'PM2.5')
if pm25_safety:
st.write(f"Safety Level: {pm25_safety}")
color_code = COLOR_CODES[pm25_safety]
st.markdown(f'<p style="color:{color_code};">The PM2.5 level is {pm25_safety}.</p>', unsafe_allow_html=True)
# Display PM10 with safety level
st.write(f"- **PM10:** {pm10} µg/m³")
# Developer section
st.markdown('### Developer:')
st.text('Adil Aziz')
st.text('Data Scientist')
st.text('adilaziz2013@gmail.com')
if __name__ == '__main__':
main()