|
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_model", version=1) |
|
model_dir = model.download() |
|
model = joblib.load(model_dir + "/wine_model.pkl") |
|
print("Model downloaded") |
|
|
|
def wine(type, volatile_acidity, citric_acid, chlorides, density, sulphates, alcohol): |
|
print("Calling function") |
|
df = pd.DataFrame([[type, volatile_acidity, citric_acid, chlorides, density, sulphates, alcohol]], |
|
columns=['type', 'volatile_acidity', 'citric_acid', 'chlorides', 'density', 'sulphates', 'alcohol']) |
|
print("Predicting") |
|
print(df) |
|
|
|
res = model.predict(df) |
|
|
|
|
|
print(f"Res: {res[0]}") |
|
|
|
return res[0] |
|
|
|
demo = gr.Interface( |
|
fn=wine, |
|
title="Wine Quality Predictive Analytics", |
|
description="Experiment with type (red/white), volatile acidity, citric acid, chlorides, density, sulphates, alcohol, quality to predict the wine's quality.", |
|
allow_flagging="never", |
|
inputs=[ |
|
gr.Number(value=1.0, label="wine type (red = 1, white = 0)"), |
|
gr.Number(value=1.0, label="Volatile acidity"), |
|
gr.Number(value=1.0, label="citric_acid"), |
|
gr.Number(value=1.0, label="chlorides"), |
|
gr.Number(value=1.0, label="density"), |
|
gr.Number(value=1.0, label='sulphates'), |
|
gr.Number(value=1.0, label='alcohol'), |
|
], |
|
outputs=gr.Number(label="quality")) |
|
|
|
demo.launch(debug=True) |
|
|
|
|