Spaces:
Runtime error
Runtime error
File size: 2,348 Bytes
a1d4102 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import gradio as gr
import hopsworks
import joblib
import pandas as pd
features = ['fixed_acidity',
'volatile_acidity',
'citric_acid',
'residual_sugar',
'chlorides',
'free_sulfur_dioxide',
'total_sulfur_dioxide',
'density',
'pH',
'sulphates',
'alcohol',
'is_white']
labels = ["Low", "Medium", "High"]
project = hopsworks.login()
fs = project.get_feature_store()
mr = project.get_model_registry()
model = mr.get_model("wine_model", version=1)
model_dir = model.download()
model = joblib.load(model_dir + "/wine_model.pkl")
print("Model downloaded")
def wine(fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
total_sulfur_dioxide, density, pH, sulphates, alcohol, white) -> str:
print("Calling function")
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
total_sulfur_dioxide, density, pH, sulphates, alcohol, white]], columns=features)
print("Predicting")
print(df)
# 'res' is a list of predictions returned as the label.
res = model.predict(df)
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
# the first element.
# print("Res: {0}").format(res)
print(res)
return f"{labels[res[0]]} quality"
demo = gr.Interface(
fn=wine,
title="Wine Quality Predictive Analytics",
description="Experiment with wine characteristics to get the wine quality (low, medium, high)",
allow_flagging="never",
inputs=[
gr.components.Number(label='fixed acidity'),
gr.components.Number(label='volatile acidity'),
gr.components.Number(label='citric acid'),
gr.components.Number(label='residual sugar'),
gr.components.Number(label='chlorides'),
gr.components.Number(label='free sulfur dioxide'),
gr.components.Number(label='total sulfur dioxide'),
gr.components.Number(label='density'),
gr.components.Number(label='pH'),
gr.components.Number(label='sulphates'),
gr.components.Number(label='alcohol'),
gr.components.Checkbox(label='is white'),
],
outputs=gr.Text())
demo.launch(debug=True) |