Manbearpig01 commited on
Commit
9303e53
1 Parent(s): 8bba14b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +86 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ import gradio as gr
8
+ import numpy as np
9
+ from PIL import Image
10
+ import requests
11
+
12
+ import hopsworks
13
+ import joblib
14
+
15
+ project = hopsworks.login()
16
+ fs = project.get_feature_store()
17
+
18
+
19
+ mr = project.get_model_registry()
20
+ model = mr.get_model("tita_modal", version=1)
21
+ model_dir = model.download()
22
+ model = joblib.load(model_dir + "/tita_model.pkl")
23
+
24
+
25
+ def tita(passengerid, age, sibsp, parch, fare, cabin_no, cabin_yes, embarked_c, embarked_q, embarked_s, sex_female, sex_male, pclass_1, pclass_2, pclass_3):
26
+ input_list = []
27
+ input_list.append(passengerid)
28
+ input_list.append(age)
29
+ input_list.append(sibsp)
30
+ input_list.append(parch)
31
+ input_list.append(fare)
32
+ input_list.append(cabin_no)
33
+ input_list.append(cabin_yes)
34
+ input_list.append(embarked_c)
35
+ input_list.append(embarked_q)
36
+ input_list.append(embarked_s)
37
+ input_list.append(sex_female)
38
+ input_list.append(sex_male)
39
+ input_list.append(pclass_1)
40
+ input_list.append(pclass_2)
41
+ input_list.append(pclass_3)
42
+ # 'res' is a list of predictions returned as the label.
43
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
44
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
45
+ # the first element.
46
+ if (res[0] == 1):
47
+ life = "alive"
48
+ else:
49
+ life = "dead"
50
+ flower_url = "https://raw.githubusercontent.com/Man-bearpig/ID2223/main/" + life + ".png"
51
+ img = Image.open(requests.get(flower_url, stream=True).raw)
52
+ return img
53
+
54
+ demo = gr.Interface(
55
+ fn=tita,
56
+ title="titanic",
57
+ description="Experiment with sepal/petal lengths/widths to predict which flower it is.",
58
+ allow_flagging="never",
59
+ inputs=[
60
+ gr.inputs.Number(default=1.0, label="passengerid"),
61
+ gr.inputs.Number(default=1.0, label="age"),
62
+ gr.inputs.Number(default=1.0, label="sibsp"),
63
+ gr.inputs.Number(default=1.0, label="parch"),
64
+ gr.inputs.Number(default=1.0, label="fare"),
65
+ gr.inputs.Number(default=1.0, label="cabin_no"),
66
+ gr.inputs.Number(default=1.0, label="cabin_yes"),
67
+ gr.inputs.Number(default=1.0, label="embarked_c"),
68
+ gr.inputs.Number(default=1.0, label="embarked_q"),
69
+ gr.inputs.Number(default=1.0, label="embarked_s"),
70
+ gr.inputs.Number(default=1.0, label="sex_female"),
71
+ gr.inputs.Number(default=1.0, label="sex_male"),
72
+ gr.inputs.Number(default=1.0, label="pclass_1"),
73
+ gr.inputs.Number(default=1.0, label="pclass_2"),
74
+ gr.inputs.Number(default=1.0, label="pclass_3"),
75
+
76
+ ],
77
+ outputs=gr.Image(type="pil"))
78
+
79
+ demo.launch()
80
+
81
+
82
+ # In[ ]:
83
+
84
+
85
+
86
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn