Upload 2 files
Browse files
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
1 |
---
|
2 |
+
title: Iris
|
3 |
+
emoji: 🐨
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.9.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(api_key_value="CDqcnm3gyfxjyCO8.TZwOClLOwCqDp33vX0P5Q2nsvNNyEhfBMArwNoPjnb9tUSSKq6I8X35HQ5D2tlJ7")
|
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, sibs, par_ch, fare):
|
20 |
+
input_list = []
|
21 |
+
input_list.append(pclass)
|
22 |
+
input_list.append(sex)
|
23 |
+
input_list.append(age)
|
24 |
+
input_list.append(sibs)
|
25 |
+
input_list.append(par_ch)
|
26 |
+
input_list.append(fare)
|
27 |
+
input_list.append(np.random.choice([0,1], 9))
|
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 |
+
man_url = "https://raw.githubusercontent.com/Tilosmsh/IL2223_lab1/main/images/" + ("survived.jpg" if res[0] else "dead.jpg")
|
33 |
+
img = Image.open(requests.get(man_url, stream=True).raw)
|
34 |
+
return img
|
35 |
+
|
36 |
+
demo = gr.Interface(
|
37 |
+
fn=titanic,
|
38 |
+
title="Titanic Predictive Analytics",
|
39 |
+
description="Experiment with passenger class, sex, age, number of siblings, number of parents & children and fare, to predict whether the passenger survived.",
|
40 |
+
allow_flagging="never",
|
41 |
+
inputs=[
|
42 |
+
gr.inputs.Number(default=1, label="Passenger Class (0, 1 or 2)"),
|
43 |
+
gr.inputs.Number(default=1, label="Sex (0 or 1)"),
|
44 |
+
gr.inputs.Number(default=30.0, label="Age (0 to 80)"),
|
45 |
+
gr.inputs.Number(default=1, label="Number of Siblings (0 to 8)"),
|
46 |
+
gr.inputs.Number(default=1, label="Number of Parents and children (0 to 6)"),
|
47 |
+
gr.inputs.Number(default=35.0, label="Fare (0 to 513)"),
|
48 |
+
],
|
49 |
+
outputs=gr.Image(type="pil"))
|
50 |
+
|
51 |
+
demo.launch()
|
52 |
+
|