Redve commited on
Commit
b54ed8a
·
1 Parent(s): fc78036

Updated for wine

Browse files
Files changed (2) hide show
  1. app.py +52 -4
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,5 +1,53 @@
1
- def greet(name):
2
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
5
- iface.launch()
 
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=3)
14
+ model_dir = model.download()
15
+ model = joblib.load(model_dir + "/wine_model.pkl")
16
+ print("Model downloaded")
17
+
18
+ def wine_quality(type, fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol):
19
+ print("Calling function")
20
+ df = pd.DataFrame([[type, fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol]],
21
+ columns=['type', 'fixed acidity', 'volatile acidity', 'citric acid', 'residual sugar', 'chlorides',])
22
+ print("Predicting")
23
+ print(df)
24
+ # 'res' is a list of predictions returned as the label.
25
+ res = model.predict(df)
26
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
27
+ # the first element.
28
+ # print("Res: {0}").format(res)
29
+ print(res)
30
+
31
+ demo = gr.Interface(
32
+ fn=wine_quality,
33
+ title="Wine Quality Prediction",
34
+ description="Predict the quality of wine based on its features.",
35
+ allow_flagging="never",
36
+ inputs=[
37
+ gr.inputs.String(default="White", label="type"),
38
+ gr.inputs.Number(default=5.0, label="fixed acidity"),
39
+ gr.inputs.Number(default=5.0, label="volatile acidity"),
40
+ gr.inputs.Number(default=5.0, label="citric acid"),
41
+ gr.inputs.Number(default=5.0, label="residual sugar"),
42
+ gr.inputs.Number(default=5.0, label="chlorides"),
43
+ gr.inputs.Number(default=5.0, label="free sulfur dioxide"),
44
+ gr.inputs.Number(default=5.0, label="total sulfur dioxide"),
45
+ gr.inputs.Number(default=5.0, label="density"),
46
+ gr.inputs.Number(default=5.0, label="pH"),
47
+ gr.inputs.Number(default=5.0, label="sulphates"),
48
+ gr.inputs.Number(default=5.0, label="alcohol")
49
+ ],
50
+ outputs=gr.Image(type="pil"))
51
+
52
+ demo.launch(debug=True)
53
 
 
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn