Spaces:
Runtime error
Runtime error
Commit ·
8f33436
1
Parent(s): f8fc315
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import hopsworks
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import keras
|
| 5 |
+
|
| 6 |
+
project = hopsworks.login()
|
| 7 |
+
fs = project.get_feature_store()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
mr = project.get_model_registry()
|
| 11 |
+
model = mr.get_model("wine_model", version=1)
|
| 12 |
+
model_dir = model.download()
|
| 13 |
+
model = keras.models.load_model(model_dir + '/wine_model.keras')
|
| 14 |
+
print("Model downloaded")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def wine(type, alcohol, density, sugar, vol_acid, chlorides, total_sulfur):
|
| 18 |
+
print("Calling function")
|
| 19 |
+
type = 0 if type == 'White' else 1
|
| 20 |
+
|
| 21 |
+
# df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
|
| 22 |
+
df = pd.DataFrame([[type, vol_acid, sugar, chlorides, total_sulfur, density, alcohol]],
|
| 23 |
+
columns=['type', 'volatile acidity', 'sugar', 'chlorides', 'total sulfur dioxide', '´density', 'alcohol'])
|
| 24 |
+
print("Predicting")
|
| 25 |
+
# 'res' is a list of predictions returned as the label.
|
| 26 |
+
wine_prediction = model.predict(df)
|
| 27 |
+
wine_prediction = {'High Quality': float(wine_prediction[0][2]),
|
| 28 |
+
'Good Quality': float(wine_prediction[0][1]),
|
| 29 |
+
'Low Quality': float(wine_prediction[0][0])}
|
| 30 |
+
return wine_prediction
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(
|
| 34 |
+
fn=wine,
|
| 35 |
+
title="Wine Quality Analytics",
|
| 36 |
+
description="Experiment with wine contents to predict what quality of wine it is.",
|
| 37 |
+
allow_flagging="never",
|
| 38 |
+
inputs=[
|
| 39 |
+
gr.Radio(["White", "Red"], value='White', label="What kind of wine is it?"),
|
| 40 |
+
gr.Number(value=9.6, label="Alcohol content (%), normal range 8-15 %"),
|
| 41 |
+
gr.Number(value=0.9935, label="Density (kg/dm^3), normal range 0.99-0.101 kg/dm^3"),
|
| 42 |
+
gr.Number(value=1.1, label="Residual sugar content (g/L), normal range 0.6-66 g/L"),
|
| 43 |
+
gr.Number(value=0.26, label="Volatile acid content (g/L), normal range 0.1 - 1.6 g/L"),
|
| 44 |
+
gr.Number(value=0.04, label="Chloride content (g/L), normal range 0.01-0.6 g/L"),
|
| 45 |
+
gr.Number(value=147, label="Total sulfur dioxide content (ppm), normal range 6-450 ppm"),
|
| 46 |
+
],
|
| 47 |
+
outputs=gr.Label(num_top_classes=3))
|
| 48 |
+
|
| 49 |
+
demo.launch(debug=True)
|
| 50 |
+
|