Spaces:
Runtime error
Runtime error
Campfireman
commited on
Commit
•
d8d35e1
1
Parent(s):
12c92ab
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
mr = project.get_model_registry()
|
13 |
+
model = mr.get_model("titanic_modal_more_specs_grad_boosted", version=1)
|
14 |
+
model_dir = model.download()
|
15 |
+
model = joblib.load(model_dir + "/titanic_model.pkl")
|
16 |
+
|
17 |
+
|
18 |
+
def titanic(pclass,sex,age,sibsp,parch,embarked,fare_per_customer,embarked_remapped,cabin_remapped):
|
19 |
+
input_list = []
|
20 |
+
input_list.append(pclass)
|
21 |
+
input_list.append(sex)
|
22 |
+
input_list.append(age)
|
23 |
+
input_list.append(sibsp)
|
24 |
+
input_list.append(parch)
|
25 |
+
input_list.append(embarked)
|
26 |
+
input_list.append(fare_per_customer)
|
27 |
+
input_list.append(embarked_remapped)
|
28 |
+
input_list.append(cabin_remapped)
|
29 |
+
# 'res' is a list of predictions returned as the label.
|
30 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
31 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
32 |
+
# the first element.
|
33 |
+
|
34 |
+
demo = gr.Interface(
|
35 |
+
fn=titanic,
|
36 |
+
title="Titanic Predictive Analytics",
|
37 |
+
description="Predict survivals.",
|
38 |
+
allow_flagging="never",
|
39 |
+
inputs=[
|
40 |
+
gr.inputs.Number(default=1.0, label="pclass"),
|
41 |
+
gr.inputs.Number(default=1.0, label="gender(male=0, female=1)"),
|
42 |
+
gr.inputs.Number(default=1.0, label="age"),
|
43 |
+
gr.inputs.Number(default=1.0, label="sibsp"),
|
44 |
+
gr.inputs.Number(default=1.0, label="parch"),
|
45 |
+
gr.inputs.Number(default=1.0, label="embarked(C=1,S=2,Q=3)"),
|
46 |
+
gr.inputs.Number(default=1.0, label="fare_per_customer"),
|
47 |
+
gr.inputs.Number(default=1.0, label="cabin_remapped(if the passanger has one cabin =1, else =0)"),
|
48 |
+
|
49 |
+
],
|
50 |
+
outputs=gr.Image(type="pil"))
|
51 |
+
|
52 |
+
demo.launch()
|