titanic / app.py
Nathanotal's picture
update inputs
3b27c45
raw
history blame
1.45 kB
import gradio as gr
import numpy as np
from PIL import Image
import requests
import pandas as pd
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")
df = pd
features = pd.read_csv(
"https://raw.githubusercontent.com/Nathanotal/remoteFiles/main/titanicCleaned.csv")
features = features.drop(columns=["survived"])
featureLabels = features.columns
def titanic(input_list):
# '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.
# Todo: survivor, "https://fakeface.rest/face/json?maximum_age=50&gender=female&minimum_age=49"
survivor_url = 'https://picsum.photos/200/300'
img = Image.open(requests.get(survivor_url, stream=True).raw)
return img
inputs = []
for feature in featureLabels:
inputs.append(gr.inputs.Number(default=1.0, label=feature))
demo = gr.Interface(
fn=titanic,
title="Titanic Survivor Predictive Analytics",
description="Experiment with person features to predict which survivor it is.",
allow_flagging="never",
inputs=inputs,
outputs=gr.Image(type="pil"))
demo.launch()