Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(fixed_acidity, volatile_acidity, citric_acid, residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,ph,sulphates,alchohol):
|
19 |
+
print("Calling function")
|
20 |
+
# df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]],
|
21 |
+
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,ph,sulphates,alchohol]],
|
22 |
+
columns=['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar,chlorides','free_sulfur_dioxide','total_sulfur_dioxide','density,ph,sulphates','alchohol'])
|
23 |
+
print("Predicting")
|
24 |
+
print(df)
|
25 |
+
# 'res' is a list of predictions returned as the label.
|
26 |
+
res = model.predict(df)
|
27 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
28 |
+
# the first element.
|
29 |
+
# print("Res: {0}").format(res)
|
30 |
+
print(res)
|
31 |
+
# flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
|
32 |
+
image_url = "https://raw.githubusercontent.com/GGmorello/serverless-ml/main/lab1/wine/numbers/" + str(res[0]) + ".png"
|
33 |
+
img = Image.open(requests.get(image_url, stream=True).raw)
|
34 |
+
return img
|
35 |
+
|
36 |
+
demo = gr.Interface(
|
37 |
+
fn=wine,
|
38 |
+
title="Wine Quality Predictive Analytics",
|
39 |
+
description="Experiment with the wine features to predict the quality of the wine",
|
40 |
+
allow_flagging="never",
|
41 |
+
inputs=[
|
42 |
+
gr.Number(default=2.0, label="fixed_acidity"),
|
43 |
+
gr.Number(default=1.0, label="volatile_acidity"),
|
44 |
+
gr.Number(default=2.0, label="citric_acid"),
|
45 |
+
gr.Number(default=1.0, label="residual_sugar"),
|
46 |
+
gr.Number(default=1.0, label="chlorides"),
|
47 |
+
gr.Number(default=1.0, label="free_sulfur_dioxide"),
|
48 |
+
gr.Number(default=1.0, label="total_sulfur_dioxide"),
|
49 |
+
gr.Number(default=1.0, label="density"),
|
50 |
+
gr.Number(default=1.0, label="ph"),
|
51 |
+
gr.Number(default=1.0, label="sulphates"),
|
52 |
+
gr.Number(default=1.0, label="alchohol")
|
53 |
+
|
54 |
+
|
55 |
+
],
|
56 |
+
outputs=gr.Image(type="pil"))
|
57 |
+
|
58 |
+
demo.launch(debug=True)
|