#imports 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 passenger(pclass, sex, age, embarked): input_list = [] input_list.append(int(pclass+1)) input_list.append(int(sex)) input_list.append(int(age)) input_list.append(int(embarked)) # '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. titanic_url = "https://raw.githubusercontent.com/AbyelT/ID2223-Scalable-ML-and-DL/main/Lab1/Titanic/assets/" + str(res[0]) + ".png" img = Image.open(requests.get(titanic_url, stream=True).raw) return img demo = gr.Interface( fn=passenger, title="Titanic Survival Predictive Analytics", #description="Experiment with sepal/petal lengths/widths to predict which flower it is.", allow_flagging="never", inputs=[ gr.inputs.Dropdown(choices=["Class 1","Class 2","Class 3"], type="index", label="Pclass"), gr.inputs.Dropdown(choices=["Male", "Female"], type="index", label="Sex"), gr.inputs.Dropdown(choices=["0","1", "2", "3", "4","5"], type="index", label="Age"), gr.inputs.Dropdown(choices=["S", "C", "Q"], type="index", label="Embarked"), ], outputs=gr.Image(type="pil")) demo.launch()