File size: 2,078 Bytes
706b0ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a747208
706b0ec
a747208
 
 
706b0ec
 
 
 
 
 
 
 
 
4c3a182
6186436
706b0ec
 
bc7b153
 
 
 
 
 
 
 
 
 
 
706b0ec
8462ac3
 
706b0ec
 
 
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
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)