File size: 2,068 Bytes
b22e39b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
688873e
b22e39b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
688873e
 
 
b22e39b
688873e
 
 
b22e39b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import gradio as gr
import numpy as np
from PIL import Image
import requests

import hopsworks
import joblib

project = hopsworks.login()
fs = project.get_feature_store()


mr = project.get_model_registry()
model = mr.get_model("titanic_modal", version=1)
model_dir = model.download()
model = joblib.load(model_dir + "/titanic_model.pkl")


def titanic(Sex, Age, Pclass, Fare, Parch, SibSp, Embarked):
    input_list = []
    input_list.append(Sex)
    input_list.append(Age)
    input_list.append(Pclass + 1.0)
    input_list.append(Fare)
    input_list.append(Parch)
    input_list.append(SibSp)
    input_list.append(Embarked)
    # 'res' is a list of predictions returned as the label.
    res = model.predict(np.asarray(input_list).reshape(1, -1))
    # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want 
    # the first element.
    pic_url = "https://raw.githubusercontent.com/backgroundhumeur/id2223_labs/main/src/titanic/assets/titanic_" + res[0] + ".jpg"
    img = Image.open(requests.get(pic_url, stream=True).raw)
    return img

demo = gr.Interface(
    fn=titanic,
    title="Titanic Passenger Survival Predictive Analytics",
    description="Experiment with different characteristics of a passenger to predict whether he would have survived if he were aboard the titanic.",
    allow_flagging="never",
    inputs=[
        gr.inputs.Dropdown(choices=["male","female"],type='index', default="male", label="Sex"),
        gr.inputs.Slider(minimum=1.0,maximum=100.0,default=28.0,step=1.0, label="Age"),
        gr.inputs.Dropdown(choices=["First", "Second","Third"],type='index', default="first", label="Ticket class"),
        gr.inputs.Number(default=14.4542, label="Fare ($)"),
        gr.inputs.Number(default=0.0, label="Number of parents/children aboard"),
        gr.inputs.Number(default=0.0, label="Number of siblings/spouses aboard"),
        gr.inputs.Dropdown(choices=["S","C", "Q"],type='index', default="C", label="Port of Embarkation")
        ],
    outputs=gr.Image(type="pil"))

demo.launch()