Spaces:
Runtime error
Runtime error
Commit
·
13ca372
1
Parent(s):
a74dd7b
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(project="zeihers_mart")
|
| 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(alcohol, volatile_acidity, total_sulfur_dioxide, chlorides, density):
|
| 19 |
+
print("Calling function")
|
| 20 |
+
# df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
|
| 21 |
+
df = pd.DataFrame([[alcohol, volatile_acidity, total_sulfur_dioxide, chlorides, density]],
|
| 22 |
+
columns=["alcohol", "volatile acidity", "total sulfur dioxide", "chlorides", "density"])
|
| 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 |
+
return res[0]
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=wine,
|
| 35 |
+
title="Wine Predictive Analytics",
|
| 36 |
+
description="Experiment with inputs to predict wine quality.",
|
| 37 |
+
allow_flagging="never",
|
| 38 |
+
inputs=[
|
| 39 |
+
gr.inputs.Number(default=0, label="alcohol"),
|
| 40 |
+
gr.inputs.Number(default=0, label="volatile acidity"),
|
| 41 |
+
gr.inputs.Number(default=0, label="total sulfur dioxide"),
|
| 42 |
+
gr.inputs.Number(default=0, label="chlorides"),
|
| 43 |
+
gr.inputs.Number(defualt=0, label = "density"),
|
| 44 |
+
],
|
| 45 |
+
outputs=gr.Number(label="Prediction"))
|
| 46 |
+
|
| 47 |
+
demo.launch(debug=True)
|
| 48 |
+
|