TLeonidas commited on
Commit
706626a
·
verified ·
1 Parent(s): e5635af

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+
4
+ # Load the trained model
5
+ model = joblib.load('hackathonrf.joblib')
6
+
7
+ # Function to get AQI value from OpenWeatherMap API
8
+ def get_aqi(latitude, longitude, api_key):
9
+ url = f"http://api.openweathermap.org/data/2.5/air_pollution?lat={latitude}&lon={longitude}&appid={api_key}"
10
+ response = requests.get(url)
11
+ data = response.json()
12
+ aqi_value = data['list'][0]['main']['aqi']
13
+ return aqi_value
14
+
15
+ # Function to make prediction
16
+ def predict_air_quality(latitude, longitude, api_key):
17
+ aqi_value = get_aqi(latitude, longitude, api_key)
18
+ prediction = model.predict([[aqi_value, aqi_value, aqi_value, aqi_value]])
19
+ return prediction[0]
20
+
21
+ # Create Gradio interface
22
+ iface = gr.Interface(fn=predict_air_quality,
23
+ inputs=["text", "text", "text"],
24
+ outputs="text",
25
+ title="Air Quality Prediction",
26
+ description="Enter latitude, longitude, and OpenWeatherMap API key:")
27
+ iface.launch()