Spaces:
Runtime error
Runtime error
Commit ·
b8c2ceb
1
Parent(s): a3b8500
Upload 2 files
Browse files- app.py +111 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import hopsworks
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Connect to Hopsworks
|
| 6 |
+
project = hopsworks.login()
|
| 7 |
+
fs = project.get_feature_store()
|
| 8 |
+
dataset_api = project.get_dataset_api()
|
| 9 |
+
|
| 10 |
+
# List of features:
|
| 11 |
+
feat = ['temperature_2m', 'apparent_temperature', 'rain', 'snowfall', 'surface_pressure', 'cloud_cover',
|
| 12 |
+
'wind_speed_10m', 'wind_direction_10m']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def refresh_images():
|
| 16 |
+
"""Function to download the latest images from the hopsworks database."""
|
| 17 |
+
# Download all the images
|
| 18 |
+
for feature in feat:
|
| 19 |
+
dataset_api.download('Resources/predictions' +'/pred_' + feature + '.png', overwrite=True)
|
| 20 |
+
dataset_api.download('Resources/predictions' + '/prev_' + feature + '.png', overwrite=True)
|
| 21 |
+
|
| 22 |
+
images = []
|
| 23 |
+
|
| 24 |
+
for feature in feat:
|
| 25 |
+
images.append(Image.open('pred_' + feature + '.png'))
|
| 26 |
+
images.append(Image.open('prev_' + feature + '.png'))
|
| 27 |
+
|
| 28 |
+
return images
|
| 29 |
+
|
| 30 |
+
css = """
|
| 31 |
+
h1 {
|
| 32 |
+
text-align: center;
|
| 33 |
+
display:block;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
p {
|
| 37 |
+
text-align: center;
|
| 38 |
+
display:block;
|
| 39 |
+
}
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
with gr.Blocks(css=css) as demo:
|
| 43 |
+
gr.Markdown('<h1>Weather prediction service </h1>'
|
| 44 |
+
'<p>These graphs shows the latest weather predictions of our model. This includes various features '
|
| 45 |
+
'such as temperature, pressure, rain and so on. These predictions are based on the latest data '
|
| 46 |
+
'from our dataset, which is updated every day with two day old data. The predictions are based '
|
| 47 |
+
'on the weather data from stockholm specifically and the model predictions are unfortunately already '
|
| 48 |
+
'outdated by the time they are made, due to the delay in data updates of our database. </p>'
|
| 49 |
+
'<p>Press the update button to get the latest prediction and the performance of our last predictions '
|
| 50 |
+
'using our model. The performance degrade severely after one day and as such this interval'
|
| 51 |
+
'is kept for predictions. </p>')
|
| 52 |
+
|
| 53 |
+
# Create a refresh button to download the newest data
|
| 54 |
+
with gr.Row():
|
| 55 |
+
gr.Column()
|
| 56 |
+
with gr.Column():
|
| 57 |
+
ref_btn = gr.Button('Refresh')
|
| 58 |
+
gr.Column()
|
| 59 |
+
|
| 60 |
+
# Create a tab for the newest predictions (in our case 2 days old...) and for old prediction and the performance
|
| 61 |
+
with gr.Tabs():
|
| 62 |
+
with gr.TabItem('Latest weather prediction'):
|
| 63 |
+
# Create rows with two figures each
|
| 64 |
+
with gr.Row():
|
| 65 |
+
with gr.Column():
|
| 66 |
+
temp = gr.Image(label='Temperature (°C)', show_download_button=True, interactive=False)
|
| 67 |
+
with gr.Column():
|
| 68 |
+
app_temp = gr.Image(label='Apparent temperature (°C)', show_download_button=True, interactive=False)
|
| 69 |
+
with gr.Row():
|
| 70 |
+
with gr.Column():
|
| 71 |
+
rain = gr.Image(label='Rain (mm)', show_download_button=True, interactive=False)
|
| 72 |
+
with gr.Column():
|
| 73 |
+
snow = gr.Image(label='snowfall (cm)', show_download_button=True, interactive=False)
|
| 74 |
+
with gr.Row():
|
| 75 |
+
with gr.Column():
|
| 76 |
+
press = gr.Image(label='Surface pressure (hPa)', show_download_button=True, interactive=False)
|
| 77 |
+
with gr.Column():
|
| 78 |
+
cloud = gr.Image(label='cloud_cover (%)', show_download_button=True, interactive=False)
|
| 79 |
+
with gr.Row():
|
| 80 |
+
with gr.Column():
|
| 81 |
+
speed = gr.Image(label='Wind speed (km/h)', show_download_button=True, interactive=False)
|
| 82 |
+
with gr.Column():
|
| 83 |
+
direction = gr.Image(label='Wind direction (°)', show_download_button=True, interactive=False)
|
| 84 |
+
|
| 85 |
+
with gr.TabItem('Previous prediction performance'):
|
| 86 |
+
with gr.Row():
|
| 87 |
+
with gr.Column():
|
| 88 |
+
ptemp = gr.Image(label=r'Temperature (°C)', show_download_button=True, interactive=False)
|
| 89 |
+
with gr.Column():
|
| 90 |
+
papp_temp = gr.Image(label='Apparent temperature (°C)', show_download_button=True, interactive=False)
|
| 91 |
+
with gr.Row():
|
| 92 |
+
with gr.Column():
|
| 93 |
+
prain = gr.Image(label='Rain (mm)', show_download_button=True, interactive=False)
|
| 94 |
+
with gr.Column():
|
| 95 |
+
psnow = gr.Image(label='snowfall (cm)', show_download_button=True, interactive=False)
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Column():
|
| 98 |
+
ppress = gr.Image(label='Surface pressure (hPa)', show_download_button=True, interactive=False)
|
| 99 |
+
with gr.Column():
|
| 100 |
+
pcloud = gr.Image(label='cloud_cover (%)', show_download_button=True, interactive=False)
|
| 101 |
+
with gr.Row():
|
| 102 |
+
with gr.Column():
|
| 103 |
+
pspeed = gr.Image(label='Wind speed (km/h)', show_download_button=True, interactive=False)
|
| 104 |
+
with gr.Column():
|
| 105 |
+
pdirection = gr.Image(label='Wind direction (°)', show_download_button=True, interactive=False)
|
| 106 |
+
|
| 107 |
+
# On button click update all images:
|
| 108 |
+
ref_btn.click(refresh_images, inputs=None, outputs=[temp, ptemp, app_temp, papp_temp, rain, prain, snow, psnow,
|
| 109 |
+
press, ppress, cloud, pcloud, speed, pspeed, direction, pdirection])
|
| 110 |
+
|
| 111 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
hopsworks
|