Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import hopsworks
|
3 |
+
import joblib
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
features = ['fixed_acidity',
|
7 |
+
'volatile_acidity',
|
8 |
+
'citric_acid',
|
9 |
+
'residual_sugar',
|
10 |
+
'chlorides',
|
11 |
+
'free_sulfur_dioxide',
|
12 |
+
'total_sulfur_dioxide',
|
13 |
+
'density',
|
14 |
+
'pH',
|
15 |
+
'sulphates',
|
16 |
+
'alcohol',
|
17 |
+
'is_white']
|
18 |
+
labels = ["Low", "Medium", "High"]
|
19 |
+
|
20 |
+
project = hopsworks.login()
|
21 |
+
fs = project.get_feature_store()
|
22 |
+
|
23 |
+
mr = project.get_model_registry()
|
24 |
+
model = mr.get_model("wine_model", version=1)
|
25 |
+
model_dir = model.download()
|
26 |
+
model = joblib.load(model_dir + "/wine_model.pkl")
|
27 |
+
print("Model downloaded")
|
28 |
+
|
29 |
+
|
30 |
+
def wine(fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
|
31 |
+
total_sulfur_dioxide, density, pH, sulphates, alcohol, white) -> str:
|
32 |
+
print("Calling function")
|
33 |
+
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
|
34 |
+
total_sulfur_dioxide, density, pH, sulphates, alcohol, white]], columns=features)
|
35 |
+
print("Predicting")
|
36 |
+
print(df)
|
37 |
+
# 'res' is a list of predictions returned as the label.
|
38 |
+
res = model.predict(df)
|
39 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
40 |
+
# the first element.
|
41 |
+
# print("Res: {0}").format(res)
|
42 |
+
print(res)
|
43 |
+
|
44 |
+
return f"{labels[res[0]]} quality"
|
45 |
+
|
46 |
+
|
47 |
+
demo = gr.Interface(
|
48 |
+
fn=wine,
|
49 |
+
title="Wine Quality Predictive Analytics",
|
50 |
+
description="Experiment with wine characteristics to get the wine quality (low, medium, high)",
|
51 |
+
allow_flagging="never",
|
52 |
+
inputs=[
|
53 |
+
gr.components.Number(label='fixed acidity'),
|
54 |
+
gr.components.Number(label='volatile acidity'),
|
55 |
+
gr.components.Number(label='citric acid'),
|
56 |
+
gr.components.Number(label='residual sugar'),
|
57 |
+
gr.components.Number(label='chlorides'),
|
58 |
+
gr.components.Number(label='free sulfur dioxide'),
|
59 |
+
gr.components.Number(label='total sulfur dioxide'),
|
60 |
+
gr.components.Number(label='density'),
|
61 |
+
gr.components.Number(label='pH'),
|
62 |
+
gr.components.Number(label='sulphates'),
|
63 |
+
gr.components.Number(label='alcohol'),
|
64 |
+
gr.components.Checkbox(label='is white'),
|
65 |
+
],
|
66 |
+
outputs=gr.Text())
|
67 |
+
|
68 |
+
demo.launch(debug=True)
|