File size: 3,275 Bytes
cb7becb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d62cd3
 
 
 
 
cb7becb
 
 
 
 
 
 
 
e27cec7
 
 
 
cb7becb
 
 
 
 
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
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")

# "Pclass", "Sex", "Age", "Parch"
def titanic(pclass, sex, age, parch):
    input_list = []
    input_list.append(pclass)
    input_list.append(sex)
    input_list.append(age)
    input_list.append(parch)
    # '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.
    if res[0] == 0:
        titanic_url = "https://lh3.googleusercontent.com/drive-viewer/AFDK6gNF4xxysDnR9rP3VtnQ0gqQABJaF9MHN6fx9ndnGEp3HwuAH8X4Qh-ewYGg-DbgtNM0q3mKfBKVNK2wyvZdPkGvnKpE=w1920-h487"
    elif res[0] == 1:
        titanic_url = "https://lh3.googleusercontent.com/fife/AAbDypAIrE-Me7Sqj3LvMGiOSqrypr9JZfdlWp46clUTEYaZC6zzZeF0iT2zi49Hrj8B0-I4DNb7ce1bqCAFDbNMhQnPNhtjXmrgfV-aFuGpUc6otrmuBT8mM6xpeyW5ljhTcLKTg2YUaY6E2d_XCj8WHY3BTXJvbU55KyOplRicpcLpElmXW2s4RW9op-3waE4p6uY0fIRphNMfxjCZDpCzlmni-zq3RsT3YL8CZaV_03CfW84ntB4nirFedH6zfuWhgreTdKmw6lqoHWm9QgRji33fJJ4bG9APfQCB2anF9z7GJJ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ah7WCs6IsMRQ-_7lWOt9dCNntEdcm2hc9jRrrBxgMSB-6IJ5c90MXjj-yiYisGH3K6keppoR9iaddtKWkyo3d0VEobsTPRUyMdQ=w1920-h892"
    img = Image.open(requests.get(titanic_url, stream=True).raw)            
    return img
        
demo = gr.Interface(
    fn=titanic,
    title="Titanic Passenger Survival Predictive Analytics",
    description="Experiment to predict passenger survival on the Titanic.",
    allow_flagging="never",
    inputs=[
        gr.inputs.Number(default=1.0, label="Pclass (1st class -> 3 class)"),
        gr.inputs.Number(default=1.0, label="Sex (0 = Female, 1 = Male)"),
        gr.inputs.Number(default=1.0, label="Age (0 -> 100 years)"),
        gr.inputs.Number(default=1.0, label="Parch (0 -> 2 parents/children on board)"),
        ],
    outputs=gr.Image(type="pil"))

demo.launch()