wine / app.py
pierrelf's picture
Refactor wine function to accept input in a
46dcc1c
raw
history blame
1.8 kB
import gradio as gr
import hopsworks
import joblib
import pandas as pd
project = hopsworks.login()
fs = project.get_feature_store()
mr = project.get_model_registry()
model = mr.get_model("wine_model")
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, total_sulfur_dioxide, ph, sulphates, alcohol, type):
if type == "red":
type = 0
else:
type = 1
print("Calling function")
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, total_sulfur_dioxide, ph, sulphates, alcohol, type]], columns=['fixed acidity', 'volatile acidity', 'citric acid', 'residual sugar', 'chlorides', 'total sulfur dioxide', 'ph', 'sulphates', 'alcohol', 'type'])
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)
return res[0]
iface = gr.Interface(
fn=wine,
title="Wine Quality Prediction",
description="Predict the quality of a wine based on its features.",
allow_flagging="never",
inputs=[
gr.Number(label="fixed_acidity"),
gr.Number(label="volatile_acidity"),
gr.Number(label="citric_acid"),
gr.Number(label="residual_sugar"),
gr.Number(label="chlorides"),
gr.Number(label="total_sulfur_dioxide"),
gr.Number(label="ph"),
gr.Number(label="sulphates"),
gr.Number(label="alcohol"),
gr.Radio(["red", "white"], label="type")
],
outputs=gr.Number(label="quality"))
iface.launch()