Maria Halvarsson commited on
Commit
6540c98
·
1 Parent(s): bd520f2
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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(type, volatile_acidity, citric_acid, chlorides, density, sulphates, alcohol):
19
+ print("Calling function")
20
+ # df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
21
+ df = pd.DataFrame([[type, volatile_acidity, citric_acid, chlorides, density, sulphates, alcohol]],
22
+ columns=['type', 'volatile_acidity', 'citric_acid', 'chlorides', 'density', 'sulphates', 'alcohol'])
23
+ print("Predicting")
24
+ print(df)
25
+ # 'res' is a list of predictions returned as the label.
26
+ result = model.predict(df)
27
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
28
+ # the first element.
29
+ # print("Res: {0}").format(res)
30
+ print(result)
31
+ #flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
32
+ #img = Image.open(requests.get(flower_url, stream=True).raw)
33
+ #return img
34
+
35
+ demo = gr.Interface(
36
+ fn=wine,
37
+ title="Wine Quality Predictive Analytics",
38
+ description="Experiment with type (red/white), volatile acidity, citric acid, chlorides, density, sulphates, alcohol, quality to predict the wine's quality.",
39
+ allow_flagging="never",
40
+ inputs=[
41
+ gr.inputs.Number(default=1.0, label="wine type (red = 1, white = 0)"),
42
+ gr.inputs.Number(default=1.0, label="Volatile acidity"),
43
+ gr.inputs.Number(default=1.0, label="citric_acid"),
44
+ gr.inputs.Number(default=1.0, label="chlorides"),
45
+ gr.inputs.Number(default=1.0, label="density"),
46
+ gr.inputs.Number(default=1.0, label='sulphates'),
47
+ gr.inputs.Number(default=1.0, label='alcohol'),
48
+ ],
49
+ outputs=gr.Number(type="quality"))
50
+
51
+ demo.launch(debug=True)
52
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn==1.1.1