File size: 1,552 Bytes
13ca372
 
 
 
 
 
760220f
13ca372
 
 
 
 
 
5b98c1d
13ca372
 
 
 
 
 
 
4ea649b
13ca372
 
 
 
 
 
 
 
 
 
 
 
7587400
 
 
 
 
760220f
13ca372
 
cf45ba6
13ca372
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
import gradio as gr
from PIL import Image
import requests
import hopsworks
import joblib
import pandas as pd
import random

project = hopsworks.login(project="zeihers_mart")
fs = project.get_feature_store()


mr = project.get_model_registry()
model = mr.get_model("wine_model", version=3)
model_dir = model.download()
model = joblib.load(model_dir + "/wine_model.pkl")
print("Model downloaded")

def wine(alcohol, volatile_acidity, total_sulfur_dioxide, chlorides, density):
    print("Calling function")
    df = pd.DataFrame([[alcohol, volatile_acidity, total_sulfur_dioxide, chlorides, density]], 
                      columns=["alcohol", "volatile_acidity", "total_sulfur_dioxide", "chlorides", "density"])
    print("Predicting")
    print(df)
    res = model.predict(df) 
    print(res)
    return res[0]
        
demo = gr.Interface(
    fn=wine,
    title="Wine Predictive Analytics",
    description="Experiment with inputs to predict wine quality.",
    allow_flagging="never",
    inputs=[
        gr.Number(precision=3, value=random.uniform(8.0, 14.9), label="alcohol"),
        gr.Number(precision=3, value=random.uniform(0.08, 1.58), step=0.1, label="volatile acidity"),
        gr.Number(precision=3, value=random.uniform(6.0, 440.0), label="total sulfur dioxide"),
        gr.Number(precision=3, value=random.uniform(0.009, 0.611), step=0.01, label="chlorides"),
        gr.Number(precision=3, value=random.uniform(0.987, 1.039), step=0.01, label="density"),
    ],
    outputs=gr.Number(label="Prediction"))

demo.launch(debug=True)