File size: 2,255 Bytes
c636255
c944c9c
 
 
da81044
 
c636255
c944c9c
 
 
 
1ddb0f2
c944c9c
 
 
 
46dcc1c
 
 
 
 
 
 
c944c9c
ef19888
46dcc1c
c944c9c
 
 
 
 
 
 
 
da81044
c21e5ab
da81044
 
 
c944c9c
 
 
 
 
 
 
b85cb6a
 
 
 
 
 
 
 
 
 
c944c9c
da81044
 
c636255
 
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
54
55
56
57
58
59
60
61
62
import gradio as gr
import hopsworks
import joblib
import pandas as pd
from PIL import Image
import requests

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)

    url = "https://raw.githubusercontent.com/pierrelefevre/scalable-ml/main/lab1/task2/img/" + str(int(res[0])) + ".png"
    img = Image.open(requests.get(url, stream=True).raw)            

    return [res[0], img]

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", value=7.293673375526557),
        gr.Number(label="volatile_acidity", value=0.3),
        gr.Number(label="citric_acid", value=0.31),
        gr.Number(label="residual_sugar", value=2.2),
        gr.Number(label="chlorides", value=0.036),
        gr.Number(label="total_sulfur_dioxide", value=95.04095161413584),
        gr.Number(label="ph", value=3.3185304801763884),
        gr.Number(label="sulphates", value=0.6691971203117211),
        gr.Number(label="alcohol", value=13.1),
        gr.Radio(["red", "white"], label="type", value="white")
        ],
    outputs=[gr.Number(label="quality"), 
             gr.Image(type="pil")])

iface.launch()