File size: 1,058 Bytes
6524a04
706626a
 
c095840
706626a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
!pip install joblib
import requests
import gradio as gr
import joblib as joblib

# Load the trained model
model = joblib.load('hackathonrf.joblib')

# Function to get AQI value from OpenWeatherMap API
def get_aqi(latitude, longitude, api_key):
    url = f"http://api.openweathermap.org/data/2.5/air_pollution?lat={latitude}&lon={longitude}&appid={api_key}"
    response = requests.get(url)
    data = response.json()
    aqi_value = data['list'][0]['main']['aqi']
    return aqi_value

# Function to make prediction
def predict_air_quality(latitude, longitude, api_key):
    aqi_value = get_aqi(latitude, longitude, api_key)
    prediction = model.predict([[aqi_value, aqi_value, aqi_value, aqi_value]])
    return prediction[0]

# Create Gradio interface
iface = gr.Interface(fn=predict_air_quality, 
                      inputs=["text", "text", "text"], 
                      outputs="text", 
                      title="Air Quality Prediction",
                      description="Enter latitude, longitude, and OpenWeatherMap API key:")
iface.launch()