franciscombaa commited on
Commit
e1563a8
·
1 Parent(s): 7b22f19

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
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
+ mr = project.get_model_registry()
12
+ model = mr.get_model("wine_model", version=1)
13
+ model_dir = model.download()
14
+ model = joblib.load(model_dir + "/wine_model.pkl")
15
+ print("Model downloaded")
16
+
17
+
18
+ def wine(type, fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, density,
19
+ ph, sulphates, alcohol):
20
+ print("Calling function")
21
+ # df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
22
+ df = pd.DataFrame([[type, fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides,
23
+ free_sulfur_dioxide, density, ph, sulphates, alcohol]],
24
+ columns=["type", "fixed_acidity", "volatile_acidity", "citric_acid", "residual_sugar", "chlorides"
25
+ , "free_sulfur_dioxide", "density", "ph", "sulphates", "alcohol"])
26
+ print("Predicting")
27
+ print(df)
28
+ # 'res' is a list of predictions returned as the label.
29
+ res = model.predict(df)
30
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
31
+ # the first element.
32
+ # print("Res: {0}").format(res)
33
+ print(res)
34
+
35
+
36
+ demo = gr.Interface(
37
+ fn=wine,
38
+ title="Wine quality predictive analytics",
39
+ description="Experiment with different properties of wine to predict what is its quality.",
40
+ allow_flagging="never",
41
+ inputs=[
42
+ gr.inputs.Number(default=1, label="wine color (1 for red, 0 for white)"),
43
+ gr.inputs.Number(default=8.0, label="fixed acidity (g/L)"),
44
+ gr.inputs.Number(default=8.0, label="volatile acidity (g/L)"),
45
+ gr.inputs.Number(default=8.0, label="citric acid (g/L)"),
46
+ gr.inputs.Number(default=2.5, label="residual sugar (g/L)"),
47
+ gr.inputs.Number(default=2.5, label="chlorides (g/L)"),
48
+ gr.inputs.Number(default=16.0, label="free_sulfur_dioxide (mg/l)"),
49
+ gr.inputs.Number(default=46.0, label="density (g/mL)"),
50
+ gr.inputs.Number(default=46.0, label="ph"),
51
+ gr.inputs.Number(default=46.0, label="sulphates (mg/L)"),
52
+ gr.inputs.Number(default=10.0, label="alcohol(°)"),
53
+ ],
54
+ outputs=gr.Image(type="pil"))
55
+
56
+ demo.launch(debug=True)