Spaces:
Runtime error
Runtime error
Commit
·
23e29f0
1
Parent(s):
7af5817
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_red = mr.get_model("wine_red_model", version=2)
|
14 |
+
model_dir_red = model_red.download()
|
15 |
+
model_red = joblib.load(model_dir + "/wine_red_model.pkl")
|
16 |
+
print("Red Model downloaded")
|
17 |
+
|
18 |
+
model_white = mr.get_model("wine_white_model", version=2)
|
19 |
+
model_dir_white = model_white.download()
|
20 |
+
model_white = joblib.load(model_dir_white + "/wine_white_model.pkl")
|
21 |
+
print("White Model downloaded")
|
22 |
+
|
23 |
+
def wine(alcohol, chlorides, density, type, volatil_acidity):
|
24 |
+
print("Calling function")
|
25 |
+
df = pd.DataFrame([[type, alcohol, chlorides, density, volatil_acidity]],
|
26 |
+
columns=['type','alcohol','chlorides','density','volatil_acidity','fixed_acidity','citric_acid','total_sulfur_dioxide'])
|
27 |
+
print("Predicting")
|
28 |
+
print(df)
|
29 |
+
|
30 |
+
if type == "red":
|
31 |
+
res = model_red.predict(df)
|
32 |
+
print(res)
|
33 |
+
wine_url = "https://raw.githubusercontent.com/Anniyuku/wine_quality/main/" + res[0] + ".png"
|
34 |
+
img = Image.open(requests.get(wine_url, stream=True).raw)
|
35 |
+
else :
|
36 |
+
res = model_white.predict(df)
|
37 |
+
print(res)
|
38 |
+
wine_url = "https://raw.githubusercontent.com/Anniyuku/wine_quality/main/" + res[0] + ".png"
|
39 |
+
img = Image.open(requests.get(wine_url, stream=True).raw)
|
40 |
+
return img
|
41 |
+
|
42 |
+
demo = gr.Interface(
|
43 |
+
fn=wine,
|
44 |
+
title="Wine Predictive Analytics",
|
45 |
+
description="Experiment with type, alcohol, chlorides, density, volatil_acidity, fixed_acidity, citric_acid, total_sulfur_dioxide to predict which flower it is.",
|
46 |
+
allow_flagging="never",
|
47 |
+
inputs=[
|
48 |
+
gr.inputs.Radio(choices=['red', 'white'], label='Type'),
|
49 |
+
gr.inputs.Number(default=9.00, label="alcohol"),
|
50 |
+
gr.inputs.Number(default=0.60, label="chlorides"),
|
51 |
+
gr.inputs.Number(default=1.00, label="density"),
|
52 |
+
gr.inputs.Number(default=1.00, label="volatil_acidity"),
|
53 |
+
gr.inputs.Number(default=1.00, label="fixed_acidity"),
|
54 |
+
gr.inputs.Number(default=1.00, label="citric_acid"),
|
55 |
+
gr.inputs.Number(default=1.00, label="total_sulfur_dioxide"),
|
56 |
+
],
|
57 |
+
outputs=gr.Image(type="pil"))
|
58 |
+
|
59 |
+
demo.launch(debug=True)
|
60 |
+
|