File size: 2,551 Bytes
33da774
 
 
 
 
 
 
e3edf58
33da774
 
 
 
 
 
 
 
 
 
 
 
 
e8478cb
33da774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8967e8e
 
 
 
 
 
 
 
 
 
 
33da774
 
 
 
 
 
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
import gradio as gr
from PIL import Image
import requests
import hopsworks
import joblib
import pandas as pd

project = hopsworks.login(project = "Scalable_ML_lab1")
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(fixed_acidity, volatile_acidity, citric_acid, residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,ph,sulphates,alchohol):
    print("Calling function")
#     df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]], 
    df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,ph,sulphates,alchohol]], 
                      columns=['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar','chlorides','free_sulfur_dioxide','total_sulfur_dioxide','density','ph','sulphates','alchohol'])
    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: {0}").format(res)
    print(res)
    # flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
    image_url = "https://raw.githubusercontent.com/GGmorello/serverless-ml/main/lab1/wine/numbers/" + str(res[0]) + ".png"
    img = Image.open(requests.get(image_url, stream=True).raw)            
    return img
        
demo = gr.Interface(
    fn=wine,
    title="Wine Quality Predictive Analytics",
    description="Experiment with the wine features to predict the quality of the wine",
    allow_flagging="never",
    inputs=[
        gr.Number(value=8.22, label="fixed_acidity"),
        gr.Number(value=0.54, label="volatile_acidity"),
        gr.Number(value=0.26, label="citric_acid"),
        gr.Number(value=2.58, label="residual_sugar"),
        gr.Number(value=0.09, label="chlorides"),
        gr.Number(value=16.76, label="free_sulfur_dioxide"),
        gr.Number(value=47.93, label="total_sulfur_dioxide"),
        gr.Number(value=0.996, label="density"),
        gr.Number(value=3.31, label="ph"),
        gr.Number(value=0.66, label="sulphates"),
        gr.Number(value=10.36, label="alchohol")


        ],
    outputs=gr.Image(type="pil"))

demo.launch(debug=True)