File size: 6,160 Bytes
b8c2ceb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ffa503
 
 
 
b8c2ceb
 
 
 
 
 
8ffa503
 
b8c2ceb
8ffa503
 
b8c2ceb
 
8ffa503
b8c2ceb
8ffa503
 
b8c2ceb
 
8ffa503
 
b8c2ceb
8ffa503
 
b8c2ceb
 
8ffa503
 
b8c2ceb
8ffa503
 
b8c2ceb
 
 
 
8ffa503
 
b8c2ceb
8ffa503
 
b8c2ceb
 
8ffa503
b8c2ceb
8ffa503
 
b8c2ceb
 
8ffa503
 
b8c2ceb
8ffa503
 
b8c2ceb
 
8ffa503
 
b8c2ceb
8ffa503
 
b8c2ceb
 
 
 
 
8ffa503
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import gradio as gr
import hopsworks
from PIL import Image

# Connect to Hopsworks
project = hopsworks.login()
fs = project.get_feature_store()
dataset_api = project.get_dataset_api()

# List of features:
feat = ['temperature_2m', 'apparent_temperature', 'rain', 'snowfall', 'surface_pressure', 'cloud_cover',
        'wind_speed_10m', 'wind_direction_10m']


def refresh_images():
    """Function to download the latest images from the hopsworks database."""
    # Download all the images
    for feature in feat:
        dataset_api.download('Resources/predictions' +'/pred_' + feature + '.png', overwrite=True)
        dataset_api.download('Resources/predictions' + '/prev_' + feature + '.png', overwrite=True)

    images = []

    for feature in feat:
        images.append(Image.open('pred_' + feature + '.png'))
        images.append(Image.open('prev_' + feature + '.png'))

    return images

css = """
h1 {
    text-align: center;
    display:block;
}

p {
    text-align: center;
    display:block;
}
"""

with gr.Blocks(css=css) as demo:
    gr.Markdown('<h1>Weather prediction service </h1>'
                '<p>These graphs shows the latest weather predictions of our model. This includes various features '
                'such as temperature, pressure, rain and so on. These predictions are based on the latest data '
                'from our dataset, which is updated every day with two day old data. The predictions are based '
                'on the weather data from stockholm specifically and the model predictions are unfortunately already '
                'outdated by the time they are made, due to the delay in data updates of our database. </p>'
                '<p>Press the update button to get the latest prediction and the performance of our last predictions '
                'using our model. The performance degrade severely after one day and as such this interval'
                'is kept for predictions. </p>')

    # Create a refresh button to download the newest data
    with gr.Row():
        gr.Column()
        with gr.Column():
            ref_btn = gr.Button('Refresh')
        gr.Column()
        
    # Load the initial images
    images = refresh_images()
    
    # Create a tab for the newest predictions (in our case 2 days old...) and for old prediction and the performance
    with gr.Tabs():
        with gr.TabItem('Latest weather prediction'):
        # Create rows with two figures each
            with gr.Row():
                with gr.Column():
                    temp = gr.Image(value=images[0], label='Temperature (°C)', show_download_button=True,
                                    interactive=False)
                with gr.Column():
                    app_temp = gr.Image(value=images[2], label='Apparent temperature (°C)', show_download_button=True,
                                        interactive=False)
            with gr.Row():
                with gr.Column():
                    rain = gr.Image(value=images[4], label='Rain (mm)', show_download_button=True, interactive=False)
                with gr.Column():
                    snow = gr.Image(value=images[6], label='snowfall (cm)', show_download_button=True,
                                    interactive=False)
            with gr.Row():
                with gr.Column():
                    press = gr.Image(value=images[8], label='Surface pressure (hPa)', show_download_button=True,
                                     interactive=False)
                with gr.Column():
                    cloud = gr.Image(value=images[10], label='cloud_cover (%)', show_download_button=True,
                                     interactive=False)
            with gr.Row():
                with gr.Column():
                    speed = gr.Image(value=images[12], label='Wind speed (km/h)', show_download_button=True,
                                     interactive=False)
                with gr.Column():
                    direction = gr.Image(value=images[14], label='Wind direction (°)', show_download_button=True,
                                         interactive=False)

        with gr.TabItem('Previous prediction performance'):
            with gr.Row():
                with gr.Column():
                    ptemp = gr.Image(value=images[1], label=r'Temperature (°C)', show_download_button=True,
                                     interactive=False)
                with gr.Column():
                    papp_temp = gr.Image(value=images[3], label='Apparent temperature (°C)', show_download_button=True,
                                         interactive=False)
            with gr.Row():
                with gr.Column():
                    prain = gr.Image(value=images[5], label='Rain (mm)', show_download_button=True, interactive=False)
                with gr.Column():
                    psnow = gr.Image(value=images[7], label='snowfall (cm)', show_download_button=True,
                                     interactive=False)
            with gr.Row():
                with gr.Column():
                    ppress = gr.Image(value=images[9], label='Surface pressure (hPa)', show_download_button=True,
                                      interactive=False)
                with gr.Column():
                    pcloud = gr.Image(value=images[11], label='cloud_cover (%)', show_download_button=True,
                                      interactive=False)
            with gr.Row():
                with gr.Column():
                    pspeed = gr.Image(value=images[13], label='Wind speed (km/h)', show_download_button=True,
                                      interactive=False)
                with gr.Column():
                    pdirection = gr.Image(value=images[15], label='Wind direction (°)', show_download_button=True,
                                          interactive=False)

    # On button click update all images:
    ref_btn.click(refresh_images, inputs=None, outputs=[temp, ptemp, app_temp, papp_temp, rain, prain, snow, psnow,
                                                        press, ppress, cloud, pcloud, speed, pspeed, direction, pdirection])

demo.launch()