Spaces:
Runtime error
Runtime error
Commit
·
1c7505d
1
Parent(s):
28a3150
Delete app.py
Browse files
app.py
DELETED
@@ -1,47 +0,0 @@
|
|
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=2)
|
15 |
-
model_dir = model.download()
|
16 |
-
model = joblib.load(model_dir + "/titanic_model.pkl")
|
17 |
-
|
18 |
-
|
19 |
-
def titanic(pclass, sex, age_bin, fare_bin):
|
20 |
-
input_list = []
|
21 |
-
input_list.append(pclass)
|
22 |
-
input_list.append(sex)
|
23 |
-
input_list.append(age_bin)
|
24 |
-
input_list.append(fare_bin)
|
25 |
-
# 'res' is a list of predictions returned as the label.
|
26 |
-
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
27 |
-
res_0 = str(res[0])
|
28 |
-
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
29 |
-
# the first element.
|
30 |
-
prediction_url = "https://raw.githubusercontent.com/torileatherman/serverless_ml_titanic/main/src/assets/"+res_0+".png"
|
31 |
-
img = Image.open(requests.get(prediction_url, stream=True).raw)
|
32 |
-
return img
|
33 |
-
|
34 |
-
demo = gr.Interface(
|
35 |
-
fn=titanic,
|
36 |
-
title="Titanic Survival Predictive Analytics",
|
37 |
-
description="Experiment with class, sex, age, and fare type to predict if the passenger survived",
|
38 |
-
allow_flagging="never",
|
39 |
-
inputs=[
|
40 |
-
gr.inputs.Number(default=1, label="Class (1 is highest, 3 is lowest"),
|
41 |
-
gr.inputs.Number(default=1, label="Gender (0 is male, 1 is female)"),
|
42 |
-
gr.inputs.Number(default=20, label="Age (years)"),
|
43 |
-
gr.inputs.Number(default=1, label="Fare Type (1 is lowest, 4 is highest)"),
|
44 |
-
],
|
45 |
-
outputs=gr.Image(type="pil"))
|
46 |
-
|
47 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|