WCarlW commited on
Commit
af19cfe
1 Parent(s): 5a6d0b2
Files changed (3) hide show
  1. README.md +5 -5
  2. app.py +47 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Titanic
3
- emoji: 💩
4
- colorFrom: red
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.11.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
1
  ---
2
+ title: Iris
3
+ emoji: 🐢
4
+ colorFrom: purple
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 3.5
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.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
+
13
+ mr = project.get_model_registry()
14
+ model = mr.get_model("titanic", version=4)
15
+ model_dir = model.download()
16
+ model = joblib.load(model_dir + "/titanic_model.pkl")
17
+
18
+
19
+ def titanic(Pclass, Sex, Age, SibSp):
20
+ input_list = []
21
+ input_list.append(Pclass)
22
+ input_list.append(Sex)
23
+ input_list.append(Age)
24
+ input_list.append(SibSp)
25
+ # 'res' is a list of predictions returned as the label.
26
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
27
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
28
+ # the first element.
29
+ flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
30
+ img = Image.open(requests.get(flower_url, stream=True).raw)
31
+ return img
32
+
33
+ demo = gr.Interface(
34
+ fn=titanic,
35
+ title="Titanic Predictive Analytics",
36
+ description="Experiment with Passenger class/Sex/Age/SibSp to predict if the person is survived or not.",
37
+ allow_flagging="never",
38
+ inputs=[
39
+ gr.inputs.Number(default=1.0, label="Pclass (Flight class 1/2/3)"),
40
+ gr.inputs.Number(default=1.0, label="Sex (male=1/female=2)"),
41
+ gr.inputs.Number(default=1.0, label="Age (in years)"),
42
+ gr.inputs.Number(default=1.0, label="SibSp (number of siblings)"),
43
+ ],
44
+ outputs=gr.Image(type="pil"))
45
+
46
+ demo.launch()
47
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn