File size: 2,407 Bytes
211d13c
3fa0367
 
211d13c
3fa0367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211d13c
 
3fa0367
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
import gradio as gr
from PIL import Image
import hopsworks

# IDE Help
from hopsworks.core.dataset_api import DatasetApi

# Images
hopsworks_images_location = "Resources/images"
hopsworks_images = {
    "latest_bridge":
        {
            "name": "latest_bridge/latest_bridge.png",
            "local_path": ""
        },
    "actual_bridge":
        {
            "name": "latest_bridge/actual_bridge.png",
            "local_path": ""
        },
    "df_recent":
        {
            "name": "latest_bridge/df_recent.png",
            "local_path": ""
        }
}

print("Logging in to Hopsworks...")
project = hopsworks.login()

print("Getting feature store...")
fs = project.get_feature_store()

print("Get database handler from Hopsworks...")
dataset_api: DatasetApi = project.get_dataset_api()

for image in hopsworks_images:
    print(f"Downloading {hopsworks_images[image]['name']} from Hopsworks...")
    hopsworks_images[image]['local_path'] = \
        dataset_api.download(f"{hopsworks_images_location}/{hopsworks_images[image]['name']}", overwrite=True)
    print(f"Saved in: {hopsworks_images[image]['local_path']}")

print("Configuring gradio...")
with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            label1 = gr.Label("Last Predicted Bridge Status")
            image1 = gr.Image(hopsworks_images['latest_bridge']['local_path'],
                              elem_id="predicted-bridge-img", type="pil")
        with gr.Column():
            label2 = gr.Label("Last Actual Bridge Status")
            image2 = gr.Image(hopsworks_images['actual_bridge']['local_path'],
                              elem_id="actual-bridge-img", type="pil")
    with gr.Row():
        with gr.Column():
            label3 = gr.Label("Recent Bridge Status Prediction History")
            image3 = gr.Image(hopsworks_images['df_recent']['local_path'],
                              elem_id="recent-bridge-predictions", type="pil")
        with gr.Column(scale=2):
            image_credits = gr.Label(
                "Image Credits: Open bridge image from "
                "[Wikimedia Commons](https://commons.wikimedia.org/wiki/File:M%C3%A4larbron_juni_2017f.jpg), "
                "Closed bridge image from "
                "[Wikimedia Commons](https://commons.wikimedia.org/wiki/File:M%C3%A4larbron_juni_2017e.jpg)")

print("Launching gradio...")
demo.launch(debug=True)