Add wine quality prediction model to app.py and
Browse files- app.py +44 -3
- requirements.txt +4 -0
app.py
CHANGED
@@ -1,7 +1,48 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import hopsworks
|
3 |
+
import joblib
|
4 |
+
import pandas as pd
|
5 |
|
6 |
+
project = hopsworks.login()
|
7 |
+
fs = project.get_feature_store()
|
8 |
+
|
9 |
+
mr = project.get_model_registry()
|
10 |
+
model = mr.get_model("wine_model", version=1)
|
11 |
+
model_dir = model.download()
|
12 |
+
model = joblib.load(model_dir + "/wine_model.pkl")
|
13 |
+
print("Model downloaded")
|
14 |
+
|
15 |
+
def wine(alcohol, chlorides, citric_acid, fixed_acidity, ph, residual_sugar, sulphates, total_sulfur_dioxide, type, volatile_acidity):
|
16 |
+
print("Calling function")
|
17 |
+
df = pd.DataFrame([[alcohol, chlorides, citric_acid, fixed_acidity, ph, residual_sugar, sulphates, total_sulfur_dioxide, type, volatile_acidity]],
|
18 |
+
columns=['alcohol', 'chlorides', 'citric_acid', 'fixed_acidity', 'ph', 'residual_sugar', 'sulphates', 'total_sulfur_dioxide', 'type', 'volatile_acidity'])
|
19 |
+
print("Predicting")
|
20 |
+
print(df)
|
21 |
+
# 'res' is a list of predictions returned as the label.
|
22 |
+
res = model.predict(df)
|
23 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
24 |
+
# the first element.
|
25 |
+
|
26 |
+
print(res)
|
27 |
+
return res[0]
|
28 |
+
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=wine,
|
31 |
+
title="Wine Quality Prediction",
|
32 |
+
description="Predict the quality of a wine based on its features.",
|
33 |
+
allow_flagging="never",
|
34 |
+
inputs=[
|
35 |
+
gr.inputs.Number(label="alcohol"),
|
36 |
+
gr.inputs.Number(label="chlorides"),
|
37 |
+
gr.inputs.Number(label="citric acid"),
|
38 |
+
gr.inputs.Number(label="fixed acidity"),
|
39 |
+
gr.inputs.Number(label="ph"),
|
40 |
+
gr.inputs.Number(label="residual sugar"),
|
41 |
+
gr.inputs.Number(label="sulphates"),
|
42 |
+
gr.inputs.Number(label="total sulfur dioxide"),
|
43 |
+
gr.inputs.Number(label="type"),
|
44 |
+
gr.inputs.Number(label="volatile acidity"),
|
45 |
+
],
|
46 |
+
outputs=gr.Number(type="number"))
|
47 |
|
|
|
48 |
iface.launch()
|
requirements.txt
CHANGED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
hopsworks
|
3 |
+
joblib
|
4 |
+
pandas
|