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