aym1king commited on
Commit
0f278ae
1 Parent(s): 70b8d26

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +5 -5
  2. app.py +63 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Wine
3
- emoji:
4
- colorFrom: gray
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 4.7.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
1
  ---
2
+ title: Iris
3
+ emoji: 🐢
4
+ colorFrom: purple
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 3.14.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import numpy as np
8
+
9
+ project = hopsworks.login()
10
+ fs = project.get_feature_store()
11
+
12
+
13
+ mr = project.get_model_registry()
14
+ model = mr.get_model("wine_model", version=1)
15
+ model_dir = model.download()
16
+ model = joblib.load(model_dir + "/wine_model.pkl")
17
+ print("Model downloaded")
18
+
19
+ def wine(type, fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol):
20
+ print("Calling function")
21
+ # df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
22
+ if type == "red" or type == "RED" or type == "Red":
23
+ type = 1
24
+ elif type == "white" or type=="WHITE" or type == "White":
25
+ type = 0
26
+
27
+ df = pd.DataFrame([[type, fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol]],
28
+ columns=['type', 'fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar', 'chlorides', 'free_sulfur_dioxide', 'total_sulfur_dioxide', 'density', 'pH', 'sulphates', 'alcohol'])
29
+ print("Predicting")
30
+ print(df)
31
+ # 'res' is a list of predictions returned as the label.
32
+ res = np.round(model.predict(df))
33
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
34
+ # the first element.
35
+ # print("Res: {0}").format(res)
36
+ print(res)
37
+ wine_url = "https://raw.githubusercontent.com/aym1king/serverless-intro/master/wine/wine_imgs/" + str(res[0]) + ".png"
38
+ img = Image.open(requests.get(wine_url, stream=True).raw)
39
+ return img
40
+
41
+ demo = gr.Interface(
42
+ fn=wine,
43
+ title="Wine Quality Predictive Analytics",
44
+ description="Experiment with wine features to predict which quality it has.",
45
+ allow_flagging="never",
46
+ inputs=[
47
+ gr.inputs.Number(default="white", label="type (white or red)"),
48
+ gr.inputs.Number(default=7.3, label="fixed acidity"),
49
+ gr.inputs.Number(default=0.4, label="volatile acidity"),
50
+ gr.inputs.Number(default=0.3, label="citric acid"),
51
+ gr.inputs.Number(default=5.8, label="residual sugar"),
52
+ gr.inputs.Number(default=0.1, label="chlorides"),
53
+ gr.inputs.Number(default=30, label="free sulfur dioxide"),
54
+ gr.inputs.Number(default=120, label="total sulfur dioxide"),
55
+ gr.inputs.Number(default=1.0, label="density"),
56
+ gr.inputs.Number(default=3.2, label="pH"),
57
+ gr.inputs.Number(default=0.5, label="sulphates"),
58
+ gr.inputs.Number(default=9.8, label="alcohol"),
59
+ ],
60
+ outputs=gr.Image(type="pil"))
61
+
62
+ demo.launch(debug=True)
63
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn==1.3.0