titanic / app.py
Valdimarb13's picture
gravestone flip
7d718dc
raw
history blame contribute delete
No virus
2.19 kB
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()