Spaces:
Runtime error
Runtime error
Commit
·
423b3f5
1
Parent(s):
3915236
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
import hopsworks
|
5 |
+
import joblib
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
hopsworks_iris_api_key = bP6PFOAzbXllM89C.l9gzwKTyxct786c3V1gwIQEvbQfZnSELxp7UM4RdBhw0eTaqkdl1Ld2a4A32UmR9
|
9 |
+
project = hopsworks.login(api_key_value = hopsworks_iris_api_key)
|
10 |
+
fs = project.get_feature_store()
|
11 |
+
|
12 |
+
# Get the model from the registry on Hopsworks and load it
|
13 |
+
mr = project.get_model_registry()
|
14 |
+
model = mr.get_model("iris_model", version=1)
|
15 |
+
model_dir = model.download()
|
16 |
+
model = joblib.load(model_dir + "/iris_model.pkl")
|
17 |
+
print("Model downloaded")
|
18 |
+
|
19 |
+
def iris(sepal_length, sepal_width, petal_length, petal_width):
|
20 |
+
print("Calling function")
|
21 |
+
#df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
|
22 |
+
df = pd.DataFrame([[sepal_length,sepal_width,petal_length,petal_width]],
|
23 |
+
columns=['sepal_length','sepal_width','petal_length','petal_width'])
|
24 |
+
print("Predicting")
|
25 |
+
print(df)
|
26 |
+
|
27 |
+
# 'res' is a list of predictions returned as the label.
|
28 |
+
res = model.predict(df)
|
29 |
+
|
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 |
+
#print("Res: {0}").format(res)
|
33 |
+
print(res[0])
|
34 |
+
flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
|
35 |
+
img = Image.open(requests.get(flower_url, stream=True).raw)
|
36 |
+
print(img)
|
37 |
+
return img
|
38 |
+
|
39 |
+
demo = gr.Interface(
|
40 |
+
fn=iris,
|
41 |
+
title="Iris Flower Predictive Analytics",
|
42 |
+
description="Experiment with sepal/petal lengths/widths to predict which flower it is.",
|
43 |
+
allow_flagging="never",
|
44 |
+
inputs=[
|
45 |
+
gr.Number(label="sepal length (cm)", default='2'),
|
46 |
+
gr.Number(label="sepal width (cm)"),
|
47 |
+
gr.Number(label="petal length (cm)"),
|
48 |
+
gr.Number(label="petal width (cm)"),
|
49 |
+
],
|
50 |
+
outputs=gr.Image(type="pil"))
|
51 |
+
|
52 |
+
demo.launch(debug=True)
|