eengel7 commited on
Commit
a92ab5c
1 Parent(s): 33eebef

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +47 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Titanic
3
- emoji: 📚
4
- colorFrom: indigo
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.10.1
8
  app_file: app.py
 
1
  ---
2
  title: Titanic
3
+ emoji: 🚢
4
+ colorFrom: green
5
+ colorTo: red
6
  sdk: gradio
7
  sdk_version: 3.10.1
8
  app_file: app.py
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_modal", version=2)
15
+ model_dir = model.download()
16
+ model = joblib.load(model_dir + "/titanic_model.pkl")
17
+
18
+
19
+ def titanic(pclass, sex, age_bin, fare_bin):
20
+ input_list = []
21
+ input_list.append(pclass)
22
+ input_list.append(sex)
23
+ input_list.append(age_bin)
24
+ input_list.append(fare_bin)
25
+ # 'res' is a list of predictions returned as the label.
26
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
27
+ res_0 = str(res[0])
28
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
29
+ # the first element.
30
+ prediction_url = "https://raw.githubusercontent.com/torileatherman/serverless_ml_titanic/main/src/assets/"+res_0+".png"
31
+ img = Image.open(requests.get(prediction_url, stream=True).raw)
32
+ return img
33
+
34
+ demo = gr.Interface(
35
+ fn=titanic,
36
+ title="Titanic Survival Predictive Analytics",
37
+ description="Experiment with class, sex, age, and fare type to predict if the passenger survived",
38
+ allow_flagging="never",
39
+ inputs=[
40
+ gr.inputs.Number(default=1, label="Class (1 is highest, 3 is lowest"),
41
+ gr.inputs.Number(default=1, label="Gender (0 is male, 1 is female)"),
42
+ gr.inputs.Number(default=20, label="Age (years)"),
43
+ gr.inputs.Number(default=1, label="Fare Type (1 is lowest, 4 is highest)"),
44
+ ],
45
+ outputs=gr.Image(type="pil"))
46
+
47
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn