Create app.py
Browse files
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 titanic(Pclass, Sex, Age, SibSp, Parch, Embarked):
|
20 |
+
input_list = []
|
21 |
+
|
22 |
+
input_list.append(Pclass)
|
23 |
+
input_list.append(Sex)
|
24 |
+
input_list.append(Age)
|
25 |
+
input_list.append(SibSp)
|
26 |
+
input_list.append(Parch)
|
27 |
+
input_list.append(Embarked)
|
28 |
+
# 'res' is a list of predictions returned as the label.
|
29 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
30 |
+
if res[0]==0:
|
31 |
+
link ="https://github.com/JeetNimbhorkar/TitanicLab1/raw/d9482baa7cbe47d0a8d5dcbe93e1ce7c0b2538a2/didnotsurvive.png"
|
32 |
+
else:
|
33 |
+
link = "https://github.com/JeetNimbhorkar/TitanicLab1/raw/d9482baa7cbe47d0a8d5dcbe93e1ce7c0b2538a2/survived.png"
|
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 |
+
#flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + pred + ".png"
|
37 |
+
titanic_url=link
|
38 |
+
img = Image.open(requests.get(titanic_url, stream=True).raw)
|
39 |
+
return img
|
40 |
+
|
41 |
+
demo = gr.Interface(
|
42 |
+
fn=titanic,
|
43 |
+
title="Titanic survival Predictive Analytics",
|
44 |
+
description="Enter passanger details to predict survival in Titanic",
|
45 |
+
allow_flagging="never",
|
46 |
+
inputs=[
|
47 |
+
gr.inputs.Number(default=1.0, label="Pclass (Enter 1,2 or 3)"),
|
48 |
+
gr.inputs.Number(default=1.0, label="Sex (0 for Male, 1 for Female)"),
|
49 |
+
gr.inputs.Number(default=1.0, label="Age"),
|
50 |
+
gr.inputs.Number(default=1.0, label="SibSp (Enter 0,1,2,3,4,5 or 8)"),
|
51 |
+
gr.inputs.Number(default=1.0, label="Parch (Enter 0,1,2,3,4,5 or 6)"),
|
52 |
+
gr.inputs.Number(default=1.0, label="Embarked (Enter 0 for C, 1 for Q and 2 for S)")
|
53 |
+
],
|
54 |
+
outputs=gr.Image(type="pil"))
|
55 |
+
|
56 |
+
demo.launch()
|
57 |
+
|