Spaces:
Runtime error
Runtime error
Valdimarb13
commited on
Commit
•
20e321f
1
Parent(s):
dc7380e
initial commit
Browse files- app.py +54 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 titanic(Sex_Code,Pclass,Embarked_Code,Title_Code,FamilySize,AgeBin_Code,FareBin_Code):
|
20 |
+
input_list = []
|
21 |
+
input_list.append(Sex_Code)
|
22 |
+
input_list.append(Pclass)
|
23 |
+
input_list.append(Embarked_Code)
|
24 |
+
input_list.append(Title_Code)
|
25 |
+
input_list.append(FamilySize)
|
26 |
+
input_list.append(AgeBin_Code)
|
27 |
+
input_list.append(FareBin_Code)
|
28 |
+
# 'res' is a list of predictions returned as the label.
|
29 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
30 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
31 |
+
# the first element.
|
32 |
+
flower_url = "https://images.pexels.com/photos/8384595/pexels-photo-8384595.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
|
33 |
+
img = Image.open(requests.get(flower_url, stream=True).raw)
|
34 |
+
return img
|
35 |
+
|
36 |
+
demo = gr.Interface(
|
37 |
+
fn=titanic,
|
38 |
+
title="Titanic Survivor Predictive Analytics",
|
39 |
+
description="Experiment with input parameters to predict survival",
|
40 |
+
allow_flagging="never",
|
41 |
+
inputs=[
|
42 |
+
#0= female 1=male
|
43 |
+
gr.Radio(["Female", "Male"], label="Gender", type="index"),
|
44 |
+
gr.Radio([1, 2, 3], label="Ticket class", type = "value"),
|
45 |
+
gr.Radio([1, 2, 3], label="Embarked from", type="index"),
|
46 |
+
gr.Radio(["Master", "Miscellenaous", "Miss", "Mr", "Mrs" ], label="Title"),
|
47 |
+
gr.Radio([1,2,3,4,5,6,7,8,11], label="Family size", type="value"),
|
48 |
+
gr.Radio(["age<=16", "16<age<=32", "32<age<=48", "48<age<=64", "64<age<=80"], label="Age", type="index"),
|
49 |
+
gr.Radio(["Low", "Medium", "High", "Very high"], label="Fare", type="index"),
|
50 |
+
],
|
51 |
+
outputs=gr.Image(type="pil"))
|
52 |
+
|
53 |
+
demo.launch()
|
54 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
hopsworks
|
2 |
+
joblib
|
3 |
+
scikit-learn
|