File size: 5,546 Bytes
a601cd3 e8c8ffd a601cd3 e8c8ffd a601cd3 95724f7 a601cd3 e8c8ffd a601cd3 e8c8ffd 1543b55 4bf0388 bde0954 a601cd3 e8c8ffd 9b2f05a e8c8ffd b22e202 22f203b 9163b5a a601cd3 e8c8ffd a601cd3 e8c8ffd 4bf0388 a601cd3 e8c8ffd a601cd3 e8c8ffd c22ad31 e8c8ffd c22ad31 a601cd3 4bf0388 a601cd3 84897f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
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 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAREA8QDxAQEA8PDw0PDw8NDQ8PDw0PFREWFhURExUYHSggGBolGxUVITEhJSkrLi4uFx8zODM4NygtOisBCgoKDg0OGhAQFy0fHR0tKy0rLSstLS0tLS0tLS0tLS0tLS0tKystLS0tLS0tLSstLTctLS0tLTctKy0rKysrK//AABEIAJQBVQMBIgACEQEDEQH/xAAbAAEAAwEBAQEAAAAAAAAAAAAAAQMEAgUGB//EAC8QAQABAwMDAgUDBAMAAAAAAAABAgMRBCExEkFRBWEicYGRoTJSsRMUQvAVYvH/xAAYAQEAAwEAAAAAAAAAAAAAAAAAAQIDBP/EACERAQEAAgICAgMBAAAAAAAAAAABAhEDIRIxMkETQlEE/9oADAMBAAIRAxEAPwD8PwYSJEYMJARgwlKUbc4MOg0bc4MOg0bc4MOg0bc4MOg0bc4T0pE6NucHSkyjoRgwJ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YcvH9x0cXJ9VhAc7cAQAAAAACQAAAAAAbfTbcTMzPbhA04vkpyfGvV0dMTEz3dXIB1uP7LTZRACuTi7LwfU7k9eM7YjbsCnJ8W3B8m30u7OMKvU6t5+gI/VM+bJY5X3eAVnpe+1dE7OqgSIV0gipX2N+WXVc47Arn6Tj7KOIW0AmIyaKFtqqcg1jGtmXUAspU9JhIIczDJqKI3hAX0me3iVIBwX271+jtRVXTTPEzEThVdpxVVHiZj7SkT9H24AVAAH/2Q=="
rose_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSGoi8okN1Fw6tYE7k-0H-wnMabl1e3NBNPpQ&usqp=CAU"
# leo_url = "https://media.tenor.com/FghTtX3ZgbAAAAAC/drowning-leo.gif"
# rose_url = "https://media4.giphy.com/media/6A5zBPtbknIGY/giphy.gif?cid=ecf05e477syp5zeoheii45de76uicvgu0nuegojslz3zgodt&rid=giphy.gif&ct=g"
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]})
namechanges = {("sex", "Sex"), ("age", "Age"), ("sibsp", "SibSp"), ("parch", "Parch"), ("embarked", "Embarked"), ("title", "Title")}
df_post = feat_eng(df_pre)
print(df_post)
# for tuple in namechanges:
# df_post[tuple[0]] = df_post[tuple[1]]
# print(df_post)
# 'res' is a list of predictions returned as the label.
res = model.predict(df_post)[0]
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
# the first element.
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() |