File size: 2,192 Bytes
20e321f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14158d2
7d718dc
1879a44
7d718dc
1879a44
20e321f
 
 
 
 
 
 
 
 
 
 
 
 
6960e95
20e321f
 
 
 
262ffc8
6be5cc8
20e321f
 
 
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
54
55
56
57
58
59
60
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_Code,Pclass,Embarked_Code,Title_Code,FamilySize,AgeBin_Code,FareBin_Code):
    input_list = []
    input_list.append(Sex_Code)
    input_list.append(Pclass)
    input_list.append(Embarked_Code)
    input_list.append(Title_Code)
    input_list.append(FamilySize)
    input_list.append(AgeBin_Code)
    input_list.append(FareBin_Code)
    # '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]==1):
        flower_url = "https://images.pexels.com/photos/8384595/pexels-photo-8384595.jpeg?auto=compress&cs=tinysrgb&w=600"
    elif(res[0]==0):
        flower_url = "https://images.pexels.com/photos/1121906/pexels-photo-1121906.jpeg?auto=compress&cs=tinysrgb&w=600"
    img = Image.open(requests.get(flower_url, stream=True).raw)            
    return img
        
demo = gr.Interface(
    fn=titanic,
    title="Titanic Survivor Predictive Analytics",
    description="Experiment with input parameters to predict survival",
    allow_flagging="never",
    inputs=[
        #0= female 1=male
        gr.Radio(["Female", "Male"], label="Gender", type="index"),
        gr.Radio([1, 2, 3], label="Ticket class", type = "value"),
        gr.Radio([1, 2, 3], label="Embarked from", type="index"),
        gr.Radio(["Master", "miscellaneous", "Miss", "Mr", "Mrs" ], label="Title", type="index"),
        gr.Radio([1,2,3,4,5,6,7,8,11], label="Family size", type="value"),
        gr.Radio(["age<=16", "16<age<=32", "32<age<=48", "48<age<=64", "64<age<=80"], label="Age", type="index"),
        gr.Radio(["Low", "Medium", "High", "Very high"], label="Fare", type="index"),
        ],
    outputs=gr.Image(type="pil")
   )

demo.launch()