3v324v23 commited on
Commit
8f7fb5e
1 Parent(s): 8e9f8af

Add application file

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import requests
5
+
6
+ import hopsworks
7
+ import joblib
8
+
9
+ project = hopsworks.login()
10
+ fs = project.get_feature_store()
11
+
12
+ mr = project.get_model_registry()
13
+ model = mr.get_model("iris_modal", version=1)
14
+ model_dir = model.download()
15
+ model = joblib.load(model_dir + "/iris_model.pkl")
16
+
17
+
18
+ def iris(sepal_length, sepal_width, petal_length, petal_width):
19
+ input_list = []
20
+ input_list.append(sepal_length)
21
+ input_list.append(sepal_width)
22
+ input_list.append(petal_length)
23
+ input_list.append(petal_width)
24
+ # 'res' is a list of predictions returned as the label.
25
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
26
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
27
+ # the first element.
28
+ flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + \
29
+ res[0] + ".png"
30
+ img = Image.open(requests.get(flower_url, stream=True).raw)
31
+ return img
32
+
33
+
34
+ demo = gr.Interface(
35
+ fn=iris,
36
+ title="Iris Flower Predictive Analytics",
37
+ description="Experiment with sepal/petal lengths/widths to predict which flower it is.",
38
+ allow_flagging="never",
39
+ inputs=[
40
+ gr.inputs.Number(default=1.0, label="sepal length (cm)"),
41
+ gr.inputs.Number(default=1.0, label="sepal width (cm)"),
42
+ gr.inputs.Number(default=1.0, label="petal length (cm)"),
43
+ gr.inputs.Number(default=1.0, label="petal width (cm)"),
44
+ ],
45
+ outputs=gr.Image(type="pil"))
46
+
47
+ demo.launch()