Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image | |
import requests | |
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_class_model", version=1) | |
model_dir = model.download() | |
model = joblib.load(model_dir + "/wine_class_model.pkl") | |
print("Model downloaded") | |
def wine_quality_class(fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, density, ph, sulphates, alcohol, wine_type_name): | |
print("Calling function") | |
type_white = 1.0 if wine_type_name == "white" else 0.0 | |
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, density, ph, sulphates, alcohol, type_white]], | |
columns=['fixed_acidity','volatile_acidity','citric_acid','residual_sugar','chlorides','free_sulfur_dioxide','density','ph','sulphates','alcohol','type_white']) | |
print("Predicting") | |
print(df) | |
# 'res' is a list of predictions returned as the label. | |
res = model.predict(df) | |
return res[0] | |
demo = gr.Interface( | |
fn=wine_quality_class, | |
title="Wine Quality Prediction", | |
description="Predicts the quality of wine based on the input parameters", | |
allow_flagging="never", | |
inputs=[ | |
gr.inputs.Number(default=8.2, label="fixed acidity"), | |
gr.inputs.Number(default=0.28, label="volatile acidity"), | |
gr.inputs.Number(default=0.4, label="citric acid"), | |
gr.inputs.Number(default=2.4, label="residual sugar"), | |
gr.inputs.Number(default=0.052, label="chlorides"), | |
gr.inputs.Number(default=4, label="free sulfur dioxide"), | |
gr.inputs.Number(default=0.99356, label="density"), | |
gr.inputs.Number(default=3.33, label="ph"), | |
gr.inputs.Number(default=0.7, label="sulphates"), | |
gr.inputs.Number(default=12.8, label="alcohol"), | |
gr.inputs.Dropdown(["white", "red"], default="red", label="wine type") | |
], | |
outputs=gr.Textbox() | |
) | |
demo.launch(debug=True) | |