Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import geopy
|
|
3 |
import joblib
|
4 |
import gradio as gr
|
5 |
|
|
|
6 |
# Load the trained model
|
7 |
model = joblib.load('hackathonrf.joblib')
|
8 |
|
@@ -13,23 +14,21 @@ def get_coordinates(location):
|
|
13 |
return location.latitude, location.longitude
|
14 |
|
15 |
# Function to get AQI value from OpenWeatherMap API
|
16 |
-
def get_aqi(latitude, longitude):
|
17 |
-
url = f"http://api.openweathermap.org/data/2.5/air_pollution/history?lat={latitude}&lon={longitude}&start=1614556800&end=1614643200&appid=78b94879cbb50e02397e93687aa24adc"
|
18 |
-
|
19 |
-
data = response.json()
|
20 |
-
return data['list']
|
21 |
|
22 |
-
# Function to make prediction
|
23 |
-
def predict_air_quality(location):
|
24 |
latitude, longitude = get_coordinates(location)
|
25 |
-
|
26 |
-
prediction = model.predict([[
|
27 |
-
return prediction[0]
|
28 |
|
29 |
# Create Gradio interface
|
30 |
iface = gr.Interface(fn=predict_air_quality,
|
31 |
-
inputs=["text"],
|
32 |
-
outputs=
|
33 |
-
title="Air Quality Prediction
|
34 |
-
description="Enter
|
35 |
-
iface.launch()
|
|
|
3 |
import joblib
|
4 |
import gradio as gr
|
5 |
|
6 |
+
|
7 |
# Load the trained model
|
8 |
model = joblib.load('hackathonrf.joblib')
|
9 |
|
|
|
14 |
return location.latitude, location.longitude
|
15 |
|
16 |
# Function to get AQI value from OpenWeatherMap API
|
17 |
+
def get_aqi(latitude, longitude, api_key):
|
18 |
+
url = f"http://api.openweathermap.org/data/2.5/air_pollution/history?lat={latitude}&lon={longitude}&start=1614556800&end=1614643200&appid=78b94879cbb50e02397e93687aa24adc"
|
19 |
+
return aqi_value
|
|
|
|
|
20 |
|
21 |
+
# Function to make prediction
|
22 |
+
def predict_air_quality(location, api_key):
|
23 |
latitude, longitude = get_coordinates(location)
|
24 |
+
aqi_value = get_aqi(latitude, longitude, api_key)
|
25 |
+
prediction = model.predict([[aqi_value, aqi_value, aqi_value, aqi_value]])
|
26 |
+
return prediction[0]
|
27 |
|
28 |
# Create Gradio interface
|
29 |
iface = gr.Interface(fn=predict_air_quality,
|
30 |
+
inputs=["text", "text"],
|
31 |
+
outputs="text",
|
32 |
+
title="Air Quality Prediction",
|
33 |
+
description="Enter location:")
|
34 |
+
iface.launch()
|