TLeonidas commited on
Commit
2ac8bf6
·
verified ·
1 Parent(s): 3ee9ded

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
6
  # Load the trained model
7
  model = joblib.load('hackathonrf.joblib')
8
 
9
- # Define AQI category labels
10
  aqi_labels = {
11
  0: 'good',
12
  1: 'moderate',
@@ -28,16 +28,17 @@ def get_aqi(latitude, longitude):
28
  url = f"http://api.openweathermap.org/data/2.5/air_pollution?lat={latitude}&lon={longitude}&appid={api_key}"
29
  response = requests.get(url)
30
  data = response.json()
 
31
  aqi_value = data['list'][0]['main']['aqi']
32
- return aqi_value
33
 
34
  # Function to make prediction
35
  def predict_air_quality(location):
36
  latitude, longitude = get_coordinates(location)
37
- aqi_value = get_aqi(latitude, longitude)
38
  prediction = model.predict([[aqi_value, aqi_value, aqi_value, aqi_value]])
39
  label_string = aqi_labels[prediction[0]]
40
- return f"{location} air quality is currently '{label_string}'"
41
 
42
  # Create Gradio interface
43
  iface = gr.Interface(fn=predict_air_quality,
 
6
  # Load the trained model
7
  model = joblib.load('hackathonrf.joblib')
8
 
9
+ # Define AQI labels
10
  aqi_labels = {
11
  0: 'good',
12
  1: 'moderate',
 
28
  url = f"http://api.openweathermap.org/data/2.5/air_pollution?lat={latitude}&lon={longitude}&appid={api_key}"
29
  response = requests.get(url)
30
  data = response.json()
31
+ pm25_aqi_level = data['list'][0]['components']['pm2_5']
32
  aqi_value = data['list'][0]['main']['aqi']
33
+ return pm25_aqi_level, aqi_value
34
 
35
  # Function to make prediction
36
  def predict_air_quality(location):
37
  latitude, longitude = get_coordinates(location)
38
+ pm25_aqi_level, aqi_value = get_aqi(latitude, longitude)
39
  prediction = model.predict([[aqi_value, aqi_value, aqi_value, aqi_value]])
40
  label_string = aqi_labels[prediction[0]]
41
+ return f"{location} air quality is currently {label_string}, with AQI {pm25_aqi_level}"
42
 
43
  # Create Gradio interface
44
  iface = gr.Interface(fn=predict_air_quality,