Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,24 +13,23 @@ 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?lat={latitude}&lon={longitude}&appid=
|
18 |
response = requests.get(url)
|
19 |
data = response.json()
|
20 |
-
|
21 |
-
return aqi_value
|
22 |
|
23 |
-
# Function to make prediction
|
24 |
-
def predict_air_quality(location
|
25 |
latitude, longitude = get_coordinates(location)
|
26 |
-
|
27 |
-
prediction = model.predict([[
|
28 |
-
return prediction[0]
|
29 |
|
30 |
# Create Gradio interface
|
31 |
iface = gr.Interface(fn=predict_air_quality,
|
32 |
-
inputs=["text"
|
33 |
-
outputs="text",
|
34 |
-
title="Air Quality Prediction",
|
35 |
-
description="Enter
|
36 |
iface.launch()
|
|
|
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" # Hardcoded API key
|
18 |
response = requests.get(url)
|
19 |
data = response.json()
|
20 |
+
return data['list']
|
|
|
21 |
|
22 |
+
# Function to make prediction and fetch historical air pollution data
|
23 |
+
def predict_air_quality(location):
|
24 |
latitude, longitude = get_coordinates(location)
|
25 |
+
historical_data = get_aqi(latitude, longitude)
|
26 |
+
prediction = model.predict([[historical_data[0]['main']['aqi'], historical_data[0]['main']['aqi'], historical_data[0]['main']['aqi'], historical_data[0]['main']['aqi']]])
|
27 |
+
return prediction[0], historical_data
|
28 |
|
29 |
# Create Gradio interface
|
30 |
iface = gr.Interface(fn=predict_air_quality,
|
31 |
+
inputs=["text"],
|
32 |
+
outputs=["text", "text"],
|
33 |
+
title="Air Quality Prediction with Historical Data",
|
34 |
+
description="Enter city name:")
|
35 |
iface.launch()
|