|
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", version=1) |
|
model_dir = model.download() |
|
model = joblib.load(model_dir + "/wine_model.pkl") |
|
print("Model downloaded") |
|
|
|
def wine(alcohol, chlorides, citric_acid, fixed_acidity, ph, residual_sugar, sulphates, total_sulfur_dioxide, type, volatile_acidity): |
|
print("Calling function") |
|
df = pd.DataFrame([[alcohol, chlorides, citric_acid, fixed_acidity, ph, residual_sugar, sulphates, total_sulfur_dioxide, type, volatile_acidity]], |
|
columns=['alcohol', 'chlorides', 'citric_acid', 'fixed_acidity', 'ph', 'residual_sugar', 'sulphates', 'total_sulfur_dioxide', 'type', 'volatile_acidity']) |
|
print("Predicting") |
|
print(df) |
|
|
|
res = model.predict(df) |
|
|
|
|
|
|
|
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.inputs.Number(label="alcohol"), |
|
gr.inputs.Number(label="chlorides"), |
|
gr.inputs.Number(label="citric acid"), |
|
gr.inputs.Number(label="fixed acidity"), |
|
gr.inputs.Number(label="ph"), |
|
gr.inputs.Number(label="residual sugar"), |
|
gr.inputs.Number(label="sulphates"), |
|
gr.inputs.Number(label="total sulfur dioxide"), |
|
gr.inputs.Number(label="type"), |
|
gr.inputs.Number(label="volatile acidity"), |
|
], |
|
outputs=gr.Number(type="number")) |
|
|
|
iface.launch() |
|
|