adil9858 commited on
Commit
f6d2c53
1 Parent(s): a82fe78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -33
app.py CHANGED
@@ -18,6 +18,37 @@ body {
18
  """
19
  st.markdown(custom_css, unsafe_allow_html=True)
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def get_aqi_data():
22
  url = 'https://www.aqi.in/dashboard/india/jammu-and-kashmir/srinagar'
23
  r = requests.get(url)
@@ -28,25 +59,20 @@ def get_aqi_data():
28
  # Extract AQI value
29
  aqi_start = line.find("AQI) is") + len("AQI) is")
30
  aqi_end = line.find(" level")
31
- aqi = line[aqi_start:aqi_end].strip().split()[0]
32
  level = line[aqi_start:aqi_end].strip().split()[1]
33
 
34
  # Extract PM2.5 value
35
  pm25_start = line.find("PM2.5 (") + len("PM2.5 (")
36
  pm25_end = line.find(" µg/m³)", pm25_start)
37
- pm25 = line[pm25_start:pm25_end].strip()
38
 
39
  # Extract PM10 value
40
  pm10_start = line.find("PM10 (") + len("PM10 (")
41
  pm10_end = line.find(" µg/m³)", pm10_start)
42
- pm10 = line[pm10_start:pm10_end].strip()
43
-
44
- # Extract temperature value
45
- temp_start = line.find("temperature (") + len("temperature (")
46
- temp_end = line.find("˚C)", temp_start)
47
- temp = line[temp_start:temp_end].strip()
48
 
49
- return aqi, level, temp, pm25, pm10
50
 
51
  def main():
52
  # Logo
@@ -56,30 +82,38 @@ def main():
56
  st.title('Real Time SXR AQI Dashboard')
57
  st.subheader('Real-time Air Quality Monitoring')
58
 
59
- aqi, level, temp, pm25, pm10 = get_aqi_data()
60
-
61
- # Set up columns for horizontal layout
62
- col1, col2 = st.columns([2, 1])
63
-
64
- # Current Data section
65
- with col1:
66
- st.markdown('### Current Data:')
67
- st.write(f"- **AQI:** {aqi} ({level})")
68
- st.write(f"- **PM2.5:** {pm25} µg/m³")
69
- st.write(f"- **PM10:** {pm10} µg/m³")
70
- st.write(f"- **Temperature:** {temp}˚C")
71
-
72
- # Display Data in Buttons section
73
- with col2:
74
- st.markdown('### Real Time Data :')
75
- if st.button('Show AQI'):
76
- st.write(f"**AQI:** {aqi} ({level})")
77
- if st.button('Show PM2.5'):
78
- st.write(f"**PM2.5:** {pm25} µg/m³")
79
- if st.button('Show PM10'):
80
- st.write(f"**PM10:** {pm10} µg/m³")
81
- if st.button('Show Temperature'):
82
- st.write(f"**Temperature:** {temp}˚C")
 
 
 
 
 
 
 
 
83
 
84
  # Developer section
85
  st.markdown('### Developer:')
 
18
  """
19
  st.markdown(custom_css, unsafe_allow_html=True)
20
 
21
+ # Prescribed limits for AQI, PM2.5, and PM10
22
+ PRESCRIBED_LIMITS = {
23
+ 'AQI': {
24
+ 'good': (0, 50),
25
+ 'moderate': (51, 100),
26
+ 'poor': (101, 200),
27
+ 'very_poor': (201, 300),
28
+ 'severe': (301, 500)
29
+ },
30
+ 'PM2.5': {
31
+ 'safe': (0, 30),
32
+ 'moderate': (31, 60),
33
+ 'poor': (61, 90),
34
+ 'very_poor': (91, 120),
35
+ 'severe': (121, 250)
36
+ },
37
+ 'PM10': {
38
+ 'safe': (0, 50),
39
+ 'moderate': (51, 100),
40
+ 'poor': (101, 250),
41
+ 'very_poor': (251, 350),
42
+ 'severe': (351, 430)
43
+ }
44
+ }
45
+
46
+ def check_safety_level(value, parameter):
47
+ for level, limits in PRESCRIBED_LIMITS[parameter].items():
48
+ if limits[0] <= value <= limits[1]:
49
+ return level
50
+ return None
51
+
52
  def get_aqi_data():
53
  url = 'https://www.aqi.in/dashboard/india/jammu-and-kashmir/srinagar'
54
  r = requests.get(url)
 
59
  # Extract AQI value
60
  aqi_start = line.find("AQI) is") + len("AQI) is")
61
  aqi_end = line.find(" level")
62
+ aqi = int(line[aqi_start:aqi_end].strip().split()[0])
63
  level = line[aqi_start:aqi_end].strip().split()[1]
64
 
65
  # Extract PM2.5 value
66
  pm25_start = line.find("PM2.5 (") + len("PM2.5 (")
67
  pm25_end = line.find(" µg/m³)", pm25_start)
68
+ pm25 = int(line[pm25_start:pm25_end].strip())
69
 
70
  # Extract PM10 value
71
  pm10_start = line.find("PM10 (") + len("PM10 (")
72
  pm10_end = line.find(" µg/m³)", pm10_start)
73
+ pm10 = int(line[pm10_start:pm10_end].strip())
 
 
 
 
 
74
 
75
+ return aqi, level, pm25, pm10
76
 
77
  def main():
78
  # Logo
 
82
  st.title('Real Time SXR AQI Dashboard')
83
  st.subheader('Real-time Air Quality Monitoring')
84
 
85
+ aqi, aqi_level, pm25, pm10 = get_aqi_data()
86
+
87
+ # Display AQI with safety level
88
+ st.markdown('### Current Data:')
89
+ st.write(f"- **AQI:** {aqi} ({aqi_level})")
90
+ aqi_safety = check_safety_level(aqi, 'AQI')
91
+ if aqi_safety:
92
+ st.write(f"Safety Level: {aqi_safety}")
93
+ if aqi_safety == 'good':
94
+ st.markdown('<p style="color:green;">The AQI level is safe.</p>', unsafe_allow_html=True)
95
+ else:
96
+ st.markdown('<p style="color:red;">The AQI level is unsafe.</p>', unsafe_allow_html=True)
97
+
98
+ # Display PM2.5 with safety level
99
+ st.write(f"- **PM2.5:** {pm25} µg/m³")
100
+ pm25_safety = check_safety_level(pm25, 'PM2.5')
101
+ if pm25_safety:
102
+ st.write(f"Safety Level: {pm25_safety}")
103
+ if pm25_safety == 'safe':
104
+ st.markdown('<p style="color:green;">The PM2.5 level is safe.</p>', unsafe_allow_html=True)
105
+ else:
106
+ st.markdown('<p style="color:red;">The PM2.5 level is unsafe.</p>', unsafe_allow_html=True)
107
+
108
+ # Display PM10 with safety level
109
+ st.write(f"- **PM10:** {pm10} µg/m³")
110
+ pm10_safety = check_safety_level(pm10, 'PM10')
111
+ if pm10_safety:
112
+ st.write(f"Safety Level: {pm10_safety}")
113
+ if pm10_safety == 'safe':
114
+ st.markdown('<p style="color:green;">The PM10 level is safe.</p>', unsafe_allow_html=True)
115
+ else:
116
+ st.markdown('<p style="color:red;">The PM10 level is unsafe.</p>', unsafe_allow_html=True)
117
 
118
  # Developer section
119
  st.markdown('### Developer:')