|
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") |
|
leo_url = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAQDw8PEA4NDw0PDw0PDQ8NDw8NDQ0NFREWFhURFRUYHSggGBolGxUVITEhJSkrLi4uFx8zOD8tNygtLisBCgoKDg0OFxAQFy0dHR8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tOC4tLS0tLSstLS0tKy0rLSstLS0rLSstNy0tK//AABEIAMgA/AMBIgACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAAAwQBAgUGB//EAC4QAAICAQIFBAICAQUBAAAAAAABAgMRBCESMUFTkgUUUWEicRORgQYyUnLRFf/EABkBAQADAQEAAAAAAAAAAAAAAAABAwQCBf/EACIRAQEAAwACAgIDAQAAAAAAAAABAgMREiEEMSIyE0FRQv/aAAwDAQACEQMRAD8A+J+6s7lnnIe6s7lnnIhBIm91Z3LPOQ91Z3LPOREBwS+6s7lnnIz7mzuWeciAySJvc2dyzzkY91Z3LPOREYIE/ubO5Z5yMe6s7lnnIhBAm91Z3LPOQ91Z3LPORCAJvdWdyzzkPdWdyzzkQgnom91Z3LPOX/pn3Vncs85EAIE/ubO5Z5yMe6s7lnnIiAEvurO5Z5yHubO5Z5yIgBL7mzuWech7mzuWeciIAS+5s7lnnIe5s7lnnIiAEvurO5Z5yHurO5Z5yIgBL7qzuWech7qzuWeciIwBN7qzuWech7qzuWeciIICX3Vncs85D3Vncs85EZqAAAAAE9AADoAAgAAAAAGRg2hHcuxo2O8cOuMs5ioYMFyNO+CLUU8LwRcbCZyoQ0ZS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/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) |
|
|
|
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() |