Robin Goran commited on
Commit ·
707703b
1
Parent(s): 45414c7
Add application file
Browse files- app.py +59 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=1)
|
| 14 |
+
model_dir = model.download()
|
| 15 |
+
model = joblib.load(model_dir + "/wine_model.pkl")
|
| 16 |
+
print("Model downloaded")
|
| 17 |
+
|
| 18 |
+
def wine_predictor(fixed_acidity, volatile_acidity, citric_acid, residual_sugar,
|
| 19 |
+
chlorides,total_sulfur_dioxide, pH, sulphates,
|
| 20 |
+
alcohol, sulfur_dioxide_ratio, isRedWine):
|
| 21 |
+
|
| 22 |
+
type_red = isRedWine
|
| 23 |
+
type_white = not type_red
|
| 24 |
+
|
| 25 |
+
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar,
|
| 26 |
+
chlorides,total_sulfur_dioxide, pH, sulphates,
|
| 27 |
+
alcohol, type_red, type_white, sulfur_dioxide_ratio]],
|
| 28 |
+
columns=["fixed_acidity", "volatile_acidity", "citric_acid", "residual_sugar",
|
| 29 |
+
"chlorides","total_sulfur_dioxide", "ph", "sulphates",
|
| 30 |
+
"alcohol","type_red", "type_white","sulfur_dioxide_ratio"])
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
res = model.predict(df)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
return res[0]
|
| 37 |
+
|
| 38 |
+
demo = gr.Interface(
|
| 39 |
+
fn=wine_predictor,
|
| 40 |
+
title="Wine Predictive Analytics",
|
| 41 |
+
description="Experiment with sepal/petal lengths/widths to predict which flower it is.",
|
| 42 |
+
allow_flagging="never",
|
| 43 |
+
inputs=[
|
| 44 |
+
gr.inputs.Number(default=7.0, label="fixed acidity"),
|
| 45 |
+
gr.inputs.Number(default=0.3, label="volatile acidity"),
|
| 46 |
+
gr.inputs.Number(default=0.3, label="citric acid"),
|
| 47 |
+
gr.inputs.Number(default=5.0, label="residual sugar"),
|
| 48 |
+
gr.inputs.Number(default=0.05, label="chlorides"),
|
| 49 |
+
gr.inputs.Number(default=114, label="total_sulfur_dioxide"),
|
| 50 |
+
gr.inputs.Number(default=3.2, label="pH"),
|
| 51 |
+
gr.inputs.Number(default=0.5, label="sulphates"),
|
| 52 |
+
gr.inputs.Number(default=10, label="alcohol"),
|
| 53 |
+
gr.inputs.Number(default=0.3, label="sulfur dioxide free-total ratio"),
|
| 54 |
+
gr.inputs.Checkbox(label="Red wine?")
|
| 55 |
+
],
|
| 56 |
+
outputs=gr.Textbox(placeholder="Quality"))
|
| 57 |
+
|
| 58 |
+
demo.launch(debug=True)
|
| 59 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
hopsworks
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn==1.1.1
|