File size: 1,338 Bytes
34c1b45
 
2bba396
34c1b45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
from PIL import Image
import hsfs
import hopsworks
import datetime 

project = hopsworks.login()
fs = project.get_feature_store()
air_fg = fs.get_or_create_feature_group(name="air_quality_predictions",
                                            version=2,
                                            primary_key=["date"],
                                            description="Air quality predictions"
                                            )

air_fg = air_fg.show(20).sort_values('date', ignore_index=True)
prediction = air_fg.iloc[-1]['pred_aqi']
date = air_fg.iloc[-1]['date']
date_str = datetime.date.fromtimestamp(date//1000).strftime("%Y-%m-%d")


with gr.Blocks() as demo:
    
    if prediction == 0 or prediction <= 50 :
        img_string =  "aqi_green.png"
    elif prediction > 50 or prediction <= 100:
        img_string= "aqi_yellow.png"
    elif prediction > 100 or prediction <= 150:
        img_string= "aqi_red.png"
    elif prediction > 150 or prediction <= 200:
        img_string= "aqi_purple.png"
    else:
        img_string= "aqi_black.png"    
        
    with gr.Row():
      with gr.Column():
          gr.Label(f"Predicted AQI for {date_str} in Madrid is {prediction}") 
          input_img = gr.Image("images/" + img_string, elem_id="predicted-img")            

demo.launch()