| import gradio as gr |
| import numpy as np |
| from PIL import Image |
| import requests |
| from feature_engineering import feat_eng |
| import hopsworks |
| import joblib |
| import pandas as pd |
|
|
| project = hopsworks.login() |
| fs = project.get_feature_store() |
| sharebool = True |
|
|
| mr = project.get_model_registry() |
| model = mr.get_model("titanic_modal_simple_classifier", version=1) |
| model_dir = model.download() |
| model = joblib.load(model_dir + "/titanic_model.pkl") |
| print(model_dir) |
| |
| |
| leo_url = "./imgs/leo.gif" |
| rose_url = "./imgs/rose.webp" |
| |
| |
| |
| |
|
|
| def titanic(pclass, name, sex, age, sibsp, parch, ticket, fare, cabin, embarked): |
| df_pre = pd.DataFrame({"PassengerId":[-1], "Pclass": [pclass], "Name": [name], "Sex": [sex], "Age": [age], "SibSp": [sibsp], "Parch": [parch], "Ticket": [ticket], "Fare": [fare], "Cabin": [cabin], "Embarked": [embarked]}) |
| |
| |
|
|
| df_post = feat_eng(df_pre) |
| print(df_post) |
| |
| |
| |
| |
| res = model.predict(df_post)[0] |
| |
| |
| |
| img = Image.open(leo_url) if res == 0 else Image.open(rose_url) |
| return img |
| |
| demo = gr.Interface( |
| fn=titanic, |
| title="Titanic Survival Predictive Analytics", |
| description="Experiment with Titanic Passenger data to predict survival", |
| allow_flagging="never", |
| inputs=[ |
| gr.inputs.Number(default=1.0, label="pclass, [1,2,3]"), |
| gr.inputs.Textbox(default="Mr. Anton", label="name"), |
| gr.inputs.Textbox(default="male", label="sex, male or female"), |
| gr.inputs.Number(default=25, label="age"), |
| gr.inputs.Number(default=2, label="sibsb"), |
| gr.inputs.Number(default=2, label="parch"), |
| gr.inputs.Textbox(default="blabla", label="Ticket"), |
| gr.inputs.Number(default=200, label="Fare"), |
| gr.inputs.Textbox(default="A123", label="Cabin"), |
| gr.inputs.Textbox(default="S", label="Embarked: [S, C, Q]") |
| ], |
| |
| outputs=gr.Image(type="pil")) |
|
|
| demo.launch() |