Spaces:
Runtime error
Runtime error
GianlucaRub
commited on
Commit
·
d3e086c
1
Parent(s):
2bd8fa4
added app.py
Browse files- app.py +57 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
import hopsworks
|
| 7 |
+
import joblib
|
| 8 |
+
|
| 9 |
+
project = hopsworks.login()
|
| 10 |
+
fs = project.get_feature_store()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
mr = project.get_model_registry()
|
| 14 |
+
model = mr.get_model("titanic_modal", version=1)
|
| 15 |
+
model_dir = model.download()
|
| 16 |
+
model = joblib.load(model_dir + "/titanic_model.pkl")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def passenger(Pclass, Age, SibSp, Parch, Fare, Sex_female, Sex_male, Embarked_C, Embarked_Q, Embarked_S):
|
| 20 |
+
input_list = []
|
| 21 |
+
input_list.append(Pclass)
|
| 22 |
+
input_list.append(Age)
|
| 23 |
+
input_list.append(SibSp)
|
| 24 |
+
input_list.append(Parch)
|
| 25 |
+
input_list.append(Fare)
|
| 26 |
+
input_list.append(Sex_female)
|
| 27 |
+
input_list.append(Sex_male)
|
| 28 |
+
input_list.append(Embarked_C)
|
| 29 |
+
input_list.append(Embarked_Q)
|
| 30 |
+
input_list.append(Embarked_S)
|
| 31 |
+
|
| 32 |
+
# 'res' is a list of predictions returned as the label.
|
| 33 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
| 34 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
| 35 |
+
# the first element.
|
| 36 |
+
passenger_url = "https://raw.githubusercontent.com/GianlucaRub/Scalable-Machine-Learning-and-Deep-Learning/main/lab1/assets/" + res[0] + ".png"
|
| 37 |
+
img = Image.open(requests.get(passenger_url, stream=True).raw)
|
| 38 |
+
return img
|
| 39 |
+
|
| 40 |
+
demo = gr.Interface(
|
| 41 |
+
fn=passenger,
|
| 42 |
+
title="Titanic Predictive Analytics",
|
| 43 |
+
description="Insert passenger class, age, number of sibilings/spouse on board of the Titanic, number of parents/children on board of the Titanic, fare, sex, port of embarkation and see if he/she survived ",
|
| 44 |
+
allow_flagging="never",
|
| 45 |
+
inputs=[
|
| 46 |
+
gr.inputs.Radio(choices=["First Class", "Second Class", "Third Class", label="Passenger Class"),
|
| 47 |
+
gr.inputs.Number(default=20, label="Age"),
|
| 48 |
+
gr.inputs.Number(default=1.0, label="Number of sibilings/spouse on board of the Titanic"),
|
| 49 |
+
gr.inputs.Number(default=1.0, label="Number of parents/children on board of the Titanic"),
|
| 50 |
+
gr.inputs.Number(defalut=10.0, label="Fare"),
|
| 51 |
+
gr.inputs.Radio(choices=["Male","Female"], label = "Sex"),
|
| 52 |
+
gr.inputs.Radio(choices=["Cherbourg","Queenstown","Southampton"], label = "Port of embarkation")
|
| 53 |
+
],
|
| 54 |
+
outputs=gr.Image(type="pil"))
|
| 55 |
+
|
| 56 |
+
demo.launch()
|
| 57 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
hopsworks
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn
|