|
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 = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTexIY-41JII4bGQ_088QA1uqWRAgzbasyvVA&usqp=CAU" |
|
rose_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSGoi8okN1Fw6tYE7k-0H-wnMabl1e3NBNPpQ&usqp=CAU" |
|
|
|
|
|
|
|
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 res |
|
|
|
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.Number()) |
|
|
|
demo.launch() |