File size: 1,493 Bytes
7cde01d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fd7e4e
7cde01d
 
 
 
 
 
 
 
 
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
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=2)
model_dir = model.download()
model = joblib.load(model_dir + "/wine_model.pkl")
print("Model downloaded")

def wine(alcohol, chlorides, density, type, volatil_acidity):
    print("Calling function")
    df = pd.DataFrame([[alcohol, chlorides, density, type, volatil_acidity]], 
                      columns=['alcohol','chlorides','density','type','volatil_acidity'])
    print("Predicting")
    print(df)
    res = model.predict(df) 
    print(res)
    wine_url = "https://raw.githubusercontent.com/Anniyuku/wine_quality/main/" + res[0] + ".png"
    img = Image.open(requests.get(wine_url, stream=True).raw)            
    return img
        
demo = gr.Interface(
    fn=wine,
    title="Wine Predictive Analytics",
    description="Experiment with alcohol, chlorides, density, type, volatil_acidity to predict which flower it is.",
    allow_flagging="never",
    inputs=[
        gr.inputs.Number(default=10.00, label="alcohol"),
        gr.inputs.Number(default=0.60, label="chlorides"),
        gr.inputs.Number(default=1.00, label="density"),
        gr.inputs.Number(default=1.00, label="type"),
        gr.inputs.Number(default=1.00, label="volatil_acidity"),
        ],
    outputs=gr.Image(type="pil"))

demo.launch(debug=True)