Sleepyp00 commited on
Commit
185da07
·
1 Parent(s): a73ba7e
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +57 -0
  3. requirements.txt +9 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: WinePrediction
3
- emoji:
4
  colorFrom: pink
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 4.2.0
8
  app_file: app.py
 
1
  ---
2
+ title: Wine
3
+ emoji: 🚀
4
  colorFrom: pink
5
+ colorTo: red
6
  sdk: gradio
7
  sdk_version: 4.2.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ #from gradio.components import inputs
3
+ from PIL import Image
4
+ import requests
5
+ import hopsworks
6
+ import io
7
+ import joblib
8
+ import pandas as pd
9
+
10
+ project = hopsworks.login()
11
+ fs = project.get_feature_store()
12
+
13
+
14
+ mr = project.get_model_registry()
15
+ model = mr.get_model("wine_model", version=1)
16
+ model_dir = model.download()
17
+ model = joblib.load(model_dir + "/wine_model.json")
18
+ print("Model downloaded")
19
+
20
+ def wine(volatile_acidity,
21
+ residual_sugar,
22
+ chlorides,
23
+ free_sulfur_dioxide,
24
+ alcohol):
25
+ print("Calling function")
26
+ df = pd.DataFrame([[volatile_acidity, residual_sugar, chlorides, free_sulfur_dioxide, alcohol]],
27
+ columns=["volatile_acidity", "residual_sugar", "chlorides", "free_sulfur_dioxide", "alcohol"])
28
+ print("Predicting")
29
+ print(df)
30
+ # 'res' is a list of predictions returned as the label.
31
+ res = model.predict(df)
32
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
33
+ # the first element.
34
+ # print("Res: {0}").format(res)
35
+ print(res[0])
36
+ wine_url = "https://github.com/jordicotxet/id2223/blob/63fe7d525afa1cfb626c9fa7513e2cc886e22d41/Wine/wine_dataset/" + str(res[0]) + ".jpg?raw=true"
37
+ print(wine_url)
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 few main wine characteristics to predict which quality it is.",
45
+ allow_flagging="never",
46
+ inputs=[
47
+ gr.Slider(minimum=0, maximum=1.5, step=0.01, value=0.2, label="volatile acidity"),
48
+ gr.Slider(minimum=0, maximum=100, step=0.1, value=5.9, label="residual sugar"),
49
+ gr.Slider(minimum=0, maximum=0.5, step=0.001, value=0.046, label="chlorides"),
50
+ gr.Slider(minimum=0, maximum=400, step=1, value=35, label="free_sulfur_dioxide"),
51
+ gr.Slider(minimum=2, maximum=15, step=0.1, value=10.6, label="alcohol (in %)"),
52
+ ],
53
+ examples=[[0.5, 0.8, 0.034, 46, 9.2],[0.42, 4.1, 0.03, 31, 12.8], [0.7, 67.1, 0.219, 275, 10.7]],
54
+ outputs=gr.Image(type="pil", height=400, width=400))
55
+
56
+ demo.launch(debug=True)
57
+
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #If you have windows, install twofish
2
+ twofish
3
+ hopsworks
4
+ joblib
5
+ scikit-learn==1.1.1
6
+ seaborn
7
+ dataframe-image
8
+ modal
9
+ gradio==3.14