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=10) model_dir = model.download() model = joblib.load(model_dir + "/titanic_model.pkl") def titanic(age, embarked, fare, parch, pclass, sex, sibsp): input_list = [] input_list.append(age) input_list.append(embarked) input_list.append(fare) input_list.append(parch) input_list.append(pclass) input_list.append(sex) input_list.append(sibsp) # '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) if res == [1]: res = 'survive' else: res = 'die' return res demo = gr.Interface( fn=titanic, title="Titanic Survivor Predictive Analytics", description="Experiment with age/embarked/fare/parch/pclass/sex/sibsp to predict if the passenger survived.", allow_flagging="never", inputs=[ gr.inputs.Number(default=2.0, label="age"), gr.inputs.Number(default=1.0, label="embarked (0 for S, 1 for C, 2 for Q)"), gr.inputs.Number(default=35.0, label="fare"), gr.inputs.Number(default=1.0, label="parch"), gr.inputs.Number(default=1.0, label="pclass"), gr.inputs.Number(default=1.0, label="sex (0 for male, 1 for male)"), gr.inputs.Number(default=1.0, label="sibsp") ], outputs=gr.Textbox()) demo.launch()