Spaces:
Runtime error
Runtime error
Commit
·
10d096e
1
Parent(s):
e1e150a
Upload 4 files
Browse files- .hw_api_key +1 -0
- README.md +4 -4
- app.py +44 -4
- requirements.txt +4 -0
.hw_api_key
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gJHnXNU7BFSJKue3.9GJb8V4qJRXE7Vn25uM6mDb39eOZIstYWJZ8XbgU7Fo6rlCZlzE3JNkcwDAYaAUJ
|
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
title: Iris
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
|
|
|
| 1 |
---
|
| 2 |
title: Iris
|
| 3 |
+
emoji: 🐢
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.5
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
app.py
CHANGED
|
@@ -1,7 +1,47 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
-
iface.launch()
|
|
|
|
| 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("iris_modal", version=1)
|
| 15 |
+
model_dir = model.download()
|
| 16 |
+
model = joblib.load(model_dir + "/iris_model.pkl")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def iris(sepal_length, sepal_width, petal_length, petal_width):
|
| 20 |
+
input_list = []
|
| 21 |
+
input_list.append(sepal_length)
|
| 22 |
+
input_list.append(sepal_width)
|
| 23 |
+
input_list.append(petal_length)
|
| 24 |
+
input_list.append(petal_width)
|
| 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 |
+
flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
|
| 30 |
+
img = Image.open(requests.get(flower_url, stream=True).raw)
|
| 31 |
+
return img
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=iris,
|
| 35 |
+
title="Iris Flower Predictive Analytics",
|
| 36 |
+
description="Experiment with sepal/petal lengths/widths to predict which flower it is.",
|
| 37 |
+
allow_flagging="never",
|
| 38 |
+
inputs=[
|
| 39 |
+
gr.inputs.Number(default=1.0, label="sepal length (cm)"),
|
| 40 |
+
gr.inputs.Number(default=1.0, label="sepal width (cm)"),
|
| 41 |
+
gr.inputs.Number(default=1.0, label="petal length (cm)"),
|
| 42 |
+
gr.inputs.Number(default=1.0, label="petal width (cm)"),
|
| 43 |
+
],
|
| 44 |
+
outputs=gr.Image(type="pil"))
|
| 45 |
+
|
| 46 |
+
demo.launch()
|
| 47 |
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
hopsworks
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn
|
| 4 |
+
gradio
|