Spaces:
Runtime error
Runtime error
Commit
·
d99941f
1
Parent(s):
f293983
Upload 3 files
Browse files- README.md +1 -1
- app.py +59 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 😻
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.14.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("wine_model", version=1)
|
| 14 |
+
model_dir = model.download()
|
| 15 |
+
model = joblib.load(model_dir + "/wine_model.pkl")
|
| 16 |
+
print("Model downloaded")
|
| 17 |
+
|
| 18 |
+
def wine(fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
|
| 19 |
+
total_sulfur_dioxide, density, ph, sulphates, alcohol):
|
| 20 |
+
print("Calling function")
|
| 21 |
+
# df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
|
| 22 |
+
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
|
| 23 |
+
total_sulfur_dioxide, density, ph, sulphates, alcohol]],
|
| 24 |
+
columns=['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar', 'chlorides', 'free_sulfur_dioxide',
|
| 25 |
+
'total_sulfur_dioxide', 'density', 'ph', 'sulphates', 'alcohol'])
|
| 26 |
+
print("Predicting")
|
| 27 |
+
print(df)
|
| 28 |
+
# 'res' is a list of predictions returned as the label.
|
| 29 |
+
res = model.predict(df)
|
| 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)
|
| 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 |
+
# return img
|
| 37 |
+
|
| 38 |
+
demo = gr.Interface(
|
| 39 |
+
fn=wine,
|
| 40 |
+
title="Wine Predictive Analytics",
|
| 41 |
+
description="Experiment with various wine components to predict its quality.",
|
| 42 |
+
allow_flagging="never",
|
| 43 |
+
inputs=[
|
| 44 |
+
gr.inputs.Number(default=0.0, label="fixed acidity"),
|
| 45 |
+
gr.inputs.Number(default=0.0, label="volatile acidity"),
|
| 46 |
+
gr.inputs.Number(default=0.0, label="citric acid"),
|
| 47 |
+
gr.inputs.Number(default=0.0, label="residual sugar"),
|
| 48 |
+
gr.inputs.Number(default=0.0, label="chlorides"),
|
| 49 |
+
gr.inputs.Number(default=0.0, label="free sulfur dioxide"),
|
| 50 |
+
gr.inputs.Number(default=0.0, label="total sulfur dioxide"),
|
| 51 |
+
gr.inputs.Number(default=0.0, label="density"),
|
| 52 |
+
gr.inputs.Number(default=0.0, label="pH"),
|
| 53 |
+
gr.inputs.Number(default=0.0, label="sulphates"),
|
| 54 |
+
gr.inputs.Number(default=0.0, label="alcohol")
|
| 55 |
+
],
|
| 56 |
+
outputs=gr.Image(type="pil"))
|
| 57 |
+
|
| 58 |
+
demo.launch(debug=True)
|
| 59 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
hopsworks
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn==1.1.1
|