Yasaman commited on
Commit
febc075
·
1 Parent(s): dce3df4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,Fare,Embarked):
20
+ input_list = []
21
+ input_list.append(Pclass)
22
+ input_list.append(Sex)
23
+ input_list.append(Age)
24
+ input_list.append(SibSp)
25
+ input_list.append(Parch)
26
+ input_list.append(Fare)
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
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
31
+ # the first element.
32
+ survival_url = "https://raw.githubusercontent.com/Yasaman97/ID2223-Titanic-Yasaman/main/img/" + str(res[0]) + ".jpg"
33
+ img = Image.open(requests.get(survival_url, stream=True).raw)
34
+ return img
35
+
36
+ demo = gr.Interface(
37
+ fn=titanic,
38
+ title="Titanic Survival Analytics",
39
+ description="Experiment with Passenger class, Sex, Age, SibSp, Parch, Fare, and Embarked to predict Survival.",
40
+ allow_flagging="never",
41
+ inputs=[
42
+ gr.inputs.Number(default=1.0, label="Pclass (int 1-3)"),
43
+ gr.inputs.Number(default=1.0, label="Sex (1: female, 0: male)"),
44
+ gr.inputs.Number(default=1.0, label="Age (float (in the dataset: 1-80))"),
45
+ gr.inputs.Number(default=1.0, label="SibSp (int 0-3)"),
46
+ gr.inputs.Number(default=1.0, label="Parch (int 0-4)"),
47
+ gr.inputs.Number(default=1.0, label="Fare (float (in the dataset: 0-512)"),
48
+ gr.inputs.Number(default=1.0, label="Embarked (int 0-2)"),
49
+ ],
50
+ outputs=gr.Image(type="pil"))
51
+
52
+ demo.launch()
53
+