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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -56
app.py CHANGED
@@ -18,62 +18,42 @@ body {
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)
55
- soup = BeautifulSoup(r.text, 'html.parser')
56
- meta_tag = soup.find('meta', {'name': 'description'})
57
- line = meta_tag['content']
58
-
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
79
  logo = 'LOGO.png'
@@ -90,30 +70,19 @@ def main():
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:')
 
18
  """
19
  st.markdown(custom_css, unsafe_allow_html=True)
20
 
21
+ # Prescribed limits for AQI and PM2.5
22
  PRESCRIBED_LIMITS = {
23
  'AQI': {
24
  'good': (0, 50),
25
  'moderate': (51, 100),
26
+ 'unhealthy_sensitive': (101, 150),
27
+ 'unhealthy': (151, 200),
28
+ 'very_unhealthy': (201, 300),
29
+ 'hazardous': (301, 500)
30
  },
31
  'PM2.5': {
32
+ 'good': (0, 12.0),
33
+ 'moderate': (12.1, 35.4),
34
+ 'unhealthy_sensitive': (35.5, 55.5),
35
+ 'unhealthy': (55.6, 150.4),
36
+ 'very_unhealthy': (150.5, 250.4),
37
+ 'hazardous': (250.5, float('inf'))
 
 
 
 
 
 
38
  }
39
  }
40
 
41
+ # Color codes for different AQI and PM2.5 levels
42
+ COLOR_CODES = {
43
+ 'good': 'green',
44
+ 'moderate': 'yellow',
45
+ 'unhealthy_sensitive': 'orange',
46
+ 'unhealthy': 'red',
47
+ 'very_unhealthy': 'purple',
48
+ 'hazardous': 'maroon'
49
+ }
50
+
51
  def check_safety_level(value, parameter):
52
  for level, limits in PRESCRIBED_LIMITS[parameter].items():
53
  if limits[0] <= value <= limits[1]:
54
  return level
55
  return None
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  def main():
58
  # Logo
59
  logo = 'LOGO.png'
 
70
  aqi_safety = check_safety_level(aqi, 'AQI')
71
  if aqi_safety:
72
  st.write(f"Safety Level: {aqi_safety}")
73
+ color_code = COLOR_CODES[aqi_safety]
74
+ st.markdown(f'<p style="color:{color_code};">The AQI level is {aqi_safety}.</p>', unsafe_allow_html=True)
 
 
75
 
76
  # Display PM2.5 with safety level
77
  st.write(f"- **PM2.5:** {pm25} µg/m³")
78
  pm25_safety = check_safety_level(pm25, 'PM2.5')
79
  if pm25_safety:
80
  st.write(f"Safety Level: {pm25_safety}")
81
+ color_code = COLOR_CODES[pm25_safety]
82
+ st.markdown(f'<p style="color:{color_code};">The PM2.5 level is {pm25_safety}.</p>', unsafe_allow_html=True)
 
 
83
 
84
  # Display PM10 with safety level
85
  st.write(f"- **PM10:** {pm10} µg/m³")
 
 
 
 
 
 
 
86
 
87
  # Developer section
88
  st.markdown('### Developer:')