eele commited on
Commit
b67ab35
·
1 Parent(s): 42d3540

Wine working

Browse files
Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image, ImageDraw
3
+ import requests
4
+ import hopsworks
5
+ import joblib
6
+ import pandas as pd
7
+
8
+ project = hopsworks.login()
9
+ fs = project.get_feature_store()
10
+
11
+
12
+ mr = project.get_model_registry()
13
+ model = mr.get_model("wine_model", version=1)
14
+ model_dir = model.download()
15
+ model = joblib.load(model_dir + "/wine_model.pkl")
16
+ print("Model downloaded")
17
+
18
+ def wine(alcohol, density, volatile_acidity, chlorides):
19
+ print("Calling function")
20
+ df = pd.DataFrame([[alcohol, density, volatile_acidity, chlorides]], columns=['alcohol', 'density', 'volatile_acidity', 'chlorides'])
21
+ print("Predicting")
22
+ print(df)
23
+ # 'res' is a list of predictions returned as the label.
24
+ res = model.predict(df)
25
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
26
+ # the first element.
27
+ # print("Res: {0}").format(res)
28
+ print(res)
29
+ img = Image.new('RGB', (100, 30), color = (73, 109, 137))
30
+ d = ImageDraw.Draw(img)
31
+ d.text((10,10), "Quality: " + str(res[0]), fill=(255,255,0))
32
+ return img
33
+
34
+ demo = gr.Interface(
35
+ fn=wine,
36
+ title="Wine Predictive Analytics",
37
+ description="Experiment with different wine configurations.",
38
+ allow_flagging="never",
39
+ inputs=[
40
+ gr.inputs.Number(default=10, label="alcohol"),
41
+ gr.inputs.Number(default=0.99, label="density"),
42
+ gr.inputs.Number(default=0.33,label="volatile_acidity"),
43
+ gr.inputs.Number(default=0.056, label="chlorides"),
44
+ ],
45
+ outputs=gr.Image(type="pil"))
46
+
47
+ demo.launch(debug=True)
48
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn==1.1.1
4
+ gradio==3.14