Create app..py
Browse files
app..py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(Type, valoatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
|
| 19 |
+
total_sulfur_dioxide, density, ph, suplhates, alcohol):
|
| 20 |
+
#Maps type to int with default white
|
| 21 |
+
if Type=="red":
|
| 22 |
+
Type=1
|
| 23 |
+
else:
|
| 24 |
+
Type=0
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
print("Calling function")
|
| 28 |
+
df = pd.DataFrame([[Type, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide,
|
| 29 |
+
total_sulfur_dioxide, density, ph, sulphates, alcohol]],
|
| 30 |
+
columns=["type", "volatile_acidity", "citric_acid", "residual_sugar", "chlorides",
|
| 31 |
+
"free_sulfur_dioxide", "total_sulfur_dioxide", "density", "ph", "sulphates", "alcohol"])
|
| 32 |
+
print("Predicting")
|
| 33 |
+
print(df)
|
| 34 |
+
res = model.predict(df)
|
| 35 |
+
print(res)
|
| 36 |
+
|
| 37 |
+
return "Predicted quality: "+str(res[0])
|
| 38 |
+
|
| 39 |
+
demo = gr.Interface(
|
| 40 |
+
fn=wine,
|
| 41 |
+
title="Wine Quality Predictive Analytics",
|
| 42 |
+
description="Experiment with features to predict wine quality.",
|
| 43 |
+
allow_flagging="never",
|
| 44 |
+
inputs=[
|
| 45 |
+
ge.inputs.Textbox(default="white", label="Type"),
|
| 46 |
+
gr.inputs.Number(default=0.34, label="Volatile acidity"),
|
| 47 |
+
gr.inputs.Number(default=0.32, label="Citric acid"),
|
| 48 |
+
gr.inputs.Number(default=5.4, label="Residual sugar"),
|
| 49 |
+
gr.inputs.Number(default=0.056, label="Chlorides"),
|
| 50 |
+
gr.inputs.Number(default=31.0, label="Free sulfur dioxide"),
|
| 51 |
+
gr.inputs.Number(default=116.0, label="Total sulfur dioxide"),
|
| 52 |
+
gr.inputs.Number(default=0.995, label="Density"),
|
| 53 |
+
gr.inputs.Number(default=3.2, label="pH"),
|
| 54 |
+
gr.inputs.Number(default=0.53, label="Sulphates"),
|
| 55 |
+
gr.inputs.Number(default=10.5, label="Alcohol precentage"),
|
| 56 |
+
gr.inputs.Number(default=0.056, label="Chlorides"),
|
| 57 |
+
],
|
| 58 |
+
outputs=gr.Label())
|
| 59 |
+
|
| 60 |
+
demo.launch(debug=True)
|
| 61 |
+
|