explorall commited on
Commit
0bd33c6
·
1 Parent(s): 2eabc5b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import hopsworks
4
+
5
+ project = hopsworks.login(project="ID2223_L2")
6
+ fs = project.get_feature_store()
7
+
8
+ predictions_fg = fs.get_feature_group(name="weather_predictions", version=1)
9
+ query = predictions_fg.select_all()
10
+ predictions_df = query.read(read_options={"use_hive": True})
11
+
12
+ predictions_df = predictions_df.sort_values(by=["timestamp_local"])
13
+
14
+ dataset_api = project.get_dataset_api()
15
+
16
+ dataset_api.download("Resources/weather/last_prediction.txt")
17
+ dataset_api.download("Resources/weather/prediction_graph.png")
18
+
19
+ def latest_prediction(path):
20
+ f = open(path,"r")
21
+ date = f.readline()
22
+ temp = f.readline()
23
+ f.close()
24
+
25
+ return "Prediction at time : "+date+"\n\nPredicted temperature:"+temp
26
+
27
+ with gr.Blocks() as demo:
28
+ with gr.Row():
29
+ with gr.Column():
30
+ gr.Label("Latest Predicted Forecast")
31
+ gr.Markdown(latest_prediction("last_prediction.txt"))
32
+ with gr.Column():
33
+ gr.Label("Graph of Recent Predictions")
34
+ input_img = gr.Image("prediction_graph.png", elem_id="temperature-graph")
35
+ with gr.Row():
36
+ with gr.Column():
37
+ gr.Label("Recent Prediction History")
38
+ gr.DataFrame(predictions_df.tail(4))
39
+
40
+ demo.launch()