Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +76 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import hopsworks
|
7 |
+
import joblib
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
+
# Connect to Hopsworks
|
11 |
+
project = hopsworks.login(project="finetune")
|
12 |
+
fs = project.get_feature_store()
|
13 |
+
dataset_api = project.get_dataset_api()
|
14 |
+
|
15 |
+
def show_reloaded_images():
|
16 |
+
'''
|
17 |
+
Show new images.
|
18 |
+
'''
|
19 |
+
# download emoticons
|
20 |
+
for day in range(1,7):
|
21 |
+
img = f'Resources/img_prediction/{day}.png'
|
22 |
+
dataset_api.download(img, overwrite=True)
|
23 |
+
# download snow prediction forecast
|
24 |
+
dataset_api.download("Resources/img_prediction/plot.png", overwrite=True)
|
25 |
+
# optput images
|
26 |
+
plot_pred = Image.open("plot.png")
|
27 |
+
img1 = Image.open("1.png")
|
28 |
+
img2 = Image.open("2.png")
|
29 |
+
img3 = Image.open("3.png")
|
30 |
+
img4 = Image.open("4.png")
|
31 |
+
img5 = Image.open("5.png")
|
32 |
+
img6 = Image.open("6.png")
|
33 |
+
output = [plot_pred, img1, img2, img3, img4, img5, img6]
|
34 |
+
|
35 |
+
return output
|
36 |
+
|
37 |
+
def show_history():
|
38 |
+
'''
|
39 |
+
Get history of predictions.
|
40 |
+
'''
|
41 |
+
dataset_api.download("Resources/img_prediction/plot_history.png", overwrite=True)
|
42 |
+
plot_hist = Image.open("plot_history.png")
|
43 |
+
|
44 |
+
return plot_hist
|
45 |
+
|
46 |
+
with gr.Blocks() as demo:
|
47 |
+
with gr.Tabs():
|
48 |
+
with gr.TabItem("Snow prediction"):
|
49 |
+
with gr.Row():
|
50 |
+
btn = gr.Button("New prediction").style(full_width=True)
|
51 |
+
with gr.Row():
|
52 |
+
plot_pred = gr.Image(label="Predicted snow height").style(height=500) # plotted graph
|
53 |
+
with gr.Row():
|
54 |
+
#input_img1 = gr.Image("1.png", elem_id="Day 1")
|
55 |
+
img1 = gr.Image()
|
56 |
+
img2 = gr.Image()
|
57 |
+
img3 = gr.Image()
|
58 |
+
img4 = gr.Image()
|
59 |
+
img5 = gr.Image()
|
60 |
+
img6 = gr.Image()
|
61 |
+
|
62 |
+
with gr.TabItem("Accuracy of past 10 days"):
|
63 |
+
with gr.Row():
|
64 |
+
btn2 = gr.Button("Get history").style(full_width=True)
|
65 |
+
with gr.Row():
|
66 |
+
pred_hist = gr.Image(label="Past 10 days of predictions").style(height=500)
|
67 |
+
|
68 |
+
btn.click(show_reloaded_images,
|
69 |
+
inputs=None,
|
70 |
+
outputs=[plot_pred, img1, img2, img3, img4, img5, img6])
|
71 |
+
|
72 |
+
btn2.click(show_history,
|
73 |
+
inputs=None,
|
74 |
+
outputs=pred_hist)
|
75 |
+
|
76 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
hopsworks
|
2 |
+
joblib
|
3 |
+
scikit-learn
|