bridge / app.py
martenb's picture
Updated app at ons 10 jan 2024 08:56:10 CET
3fa0367
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)