Spaces:
Runtime error
Runtime error
dhruvshettty
commited on
Commit
•
cb7becb
1
Parent(s):
5b3270a
Add gradio for hugging spaces
Browse files- app.py +48 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# "Pclass", "Sex", "Age", "Parch"
|
19 |
+
def titanic(pclass, sex, age, parch):
|
20 |
+
input_list = []
|
21 |
+
input_list.append(pclass)
|
22 |
+
input_list.append(sex)
|
23 |
+
input_list.append(age)
|
24 |
+
input_list.append(parch)
|
25 |
+
# 'res' is a list of predictions returned as the label.
|
26 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
27 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
28 |
+
# the first element.
|
29 |
+
# TODO(Change URL)
|
30 |
+
flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
|
31 |
+
img = Image.open(requests.get(flower_url, stream=True).raw)
|
32 |
+
return img
|
33 |
+
|
34 |
+
demo = gr.Interface(
|
35 |
+
fn=titanic,
|
36 |
+
title="Titanic Passenger Survival Predictive Analytics",
|
37 |
+
description="Experiment to predict passenger survival on the Titanic.",
|
38 |
+
allow_flagging="never",
|
39 |
+
inputs=[
|
40 |
+
gr.inputs.Number(default=1.0, label="Pclass (1 -> 3)"),
|
41 |
+
gr.inputs.Number(default=1.0, label="Sex (0 -> 1)"),
|
42 |
+
gr.inputs.Number(default=1.0, label="Age (0 -> 100)"),
|
43 |
+
gr.inputs.Number(default=1.0, label="Parch (0 -> 2)"),
|
44 |
+
],
|
45 |
+
outputs=gr.Image(type="pil"))
|
46 |
+
|
47 |
+
demo.launch()
|
48 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
hopsworks
|
2 |
+
joblib
|
3 |
+
scikit-learn
|