Spaces:
Runtime error
Runtime error
Commit
·
ccdda20
1
Parent(s):
aed5e69
Upload 2 files
Browse files- app.py +45 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=2)
|
| 14 |
+
model_dir = model.download()
|
| 15 |
+
model = joblib.load(model_dir + "/wine_model.pkl")
|
| 16 |
+
print("Model downloaded")
|
| 17 |
+
|
| 18 |
+
def wine(alcohol, chlorides, density, type, volatil_acidity):
|
| 19 |
+
print("Calling function")
|
| 20 |
+
df = pd.DataFrame([[alcohol, chlorides, density, type, volatil_acidity]],
|
| 21 |
+
columns=['alcohol','chlorides','density','type','volatil_acidity'])
|
| 22 |
+
print("Predicting")
|
| 23 |
+
print(df)
|
| 24 |
+
res = model.predict(df)
|
| 25 |
+
print(res)
|
| 26 |
+
wine_url = "https://raw.githubusercontent.com/Anniyuku/wine_quality/main/" + res[0] + ".png"
|
| 27 |
+
img = Image.open(requests.get(wine_url, stream=True).raw)
|
| 28 |
+
return img
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=wine,
|
| 32 |
+
title="Wine Predictive Analytics",
|
| 33 |
+
description="Experiment with alcohol, chlorides, density, type, volatil_acidity to predict which flower it is.",
|
| 34 |
+
allow_flagging="never",
|
| 35 |
+
inputs=[
|
| 36 |
+
gr.inputs.Number(default=9.00, label="alcohol"),
|
| 37 |
+
gr.inputs.Number(default=0.60, label="chlorides"),
|
| 38 |
+
gr.inputs.Number(default=1.00, label="density"),
|
| 39 |
+
gr.inputs.Number(default=1.00, label="type"),
|
| 40 |
+
gr.inputs.Number(default=1.00, label="volatil_acidity"),
|
| 41 |
+
],
|
| 42 |
+
outputs=gr.Image(type="pil"))
|
| 43 |
+
|
| 44 |
+
demo.launch(debug=True)
|
| 45 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
hopsworks
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn==1.1.3
|
| 4 |
+
gradio==3.14
|