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. flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png" 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