Spaces:
Runtime error
Runtime error
Commit
·
ccbece9
1
Parent(s):
4a5c4bb
Update app
Browse files
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,fixed_acidity,volatile_acidity,citric_acid,residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,pH,sulphates,alcohol,quality):
|
19 |
+
print("Calling function")
|
20 |
+
df = pd.DataFrame([[_type,fixed_acidity,volatile_acidity,citric_acid,residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,pH,sulphates,alcohol,quality]],
|
21 |
+
columns=['_type','fixed_acidity','volatile_acidity','citric_acid','residual_sugar','chlorides','free_sulfur_dioxide','total_sulfur_dioxide','density','pH','sulphates','alcohol','quality'])
|
22 |
+
print("Predicting")
|
23 |
+
print(df)
|
24 |
+
# 'res' is a list of predictions returned as the label.
|
25 |
+
res = model.predict(df)
|
26 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
27 |
+
# the first element.
|
28 |
+
# print("Res: {0}").format(res)
|
29 |
+
print(res)
|
30 |
+
# flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
|
31 |
+
# img = Image.open(requests.get(flower_url, stream=True).raw)
|
32 |
+
return res
|
33 |
+
|
34 |
+
demo = gr.Interface(
|
35 |
+
fn=wine,
|
36 |
+
title="Wine Predictive Analytics",
|
37 |
+
description="Experiment with wine features to predict which quality of wine it is.",
|
38 |
+
allow_flagging="never",
|
39 |
+
inputs=[
|
40 |
+
gr.Number(value=0, label="_type 0 for white, 1 for red"),
|
41 |
+
gr.Number(value=7.0, label="fixed_acidity"),
|
42 |
+
gr.Number(value=0.0, label="volatile_acidity"),
|
43 |
+
gr.Number(value=0.0, label="citric_acid"),
|
44 |
+
gr.Number(value=5.0, label="residual_sugar"),
|
45 |
+
gr.Number(value=0.0, label="chlorides"),
|
46 |
+
gr.Number(value=30.0, label="free_sulfur_dioxide"),
|
47 |
+
gr.Number(value=115.0, label="total_sulfur_dioxide"),
|
48 |
+
gr.Number(value=1.0, label="density"),
|
49 |
+
gr.Number(value=3.0, label="pH"),
|
50 |
+
gr.Number(value=0.0, label="sulphates"),
|
51 |
+
gr.Number(value=10.0, label="alcohol")
|
52 |
+
],
|
53 |
+
outputs=gr.outputs.Label(label="Predicted Wine Quality"),
|
54 |
+
)
|
55 |
+
|
56 |
+
demo.launch(debug=True)
|
57 |
+
|