File size: 2,751 Bytes
33da774
 
 
 
 
 
 
e3edf58
33da774
 
 
 
86b84c9
33da774
 
 
 
 
 
 
 
99e9a29
33da774
 
 
 
 
 
 
ca0f60d
 
33da774
 
a607105
 
0e86b33
2bfd5fc
0e86b33
a63b73c
33da774
 
 
 
 
 
 
a63b73c
 
 
 
 
 
 
 
 
 
 
33da774
 
 
a63b73c
 
1b4ae40
33da774
5fc7bb4
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
63
64
65
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=5)
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','alcohol'])
    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("the whole prediction", res)
    print("prediction[0]",res[0])
    # 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"
    resp = requests.get(image_url, stream=True)
    print("image request: ",resp)
    img = Image.open(resp.raw)
    newsize = (100, 100)
    img1 = img.resize(newsize)
    return img1
        
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=9.1, label="fixed_acidity"),
        gr.Number(value=0.3, label="volatile_acidity"),
        gr.Number(value=0.41, label="citric_acid"),
        gr.Number(value=2, label="residual_sugar"),
        gr.Number(value=0.068, label="chlorides"),
        gr.Number(value=10, label="free_sulfur_dioxide"),
        gr.Number(value=24, label="total_sulfur_dioxide"),
        gr.Number(value=0.99523, label="density"),
        gr.Number(value=3.27, label="ph"),
        gr.Number(value=0.85, label="sulphates"),
        gr.Number(value=11.7, label="alcohol")


        ],
    outputs=gr.Image(type="pil")
    #outputs = gr.Number(label = "quality")
)

demo.launch(debug=True,share = True)