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