Spaces:
Runtime error
Runtime error
Commit
·
d2b7611
1
Parent(s):
21d01f5
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import os
|
| 3 |
+
import warnings
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
from huggingface_hub import hf_hub_download
|
| 8 |
+
|
| 9 |
+
warnings.filterwarnings("ignore")
|
| 10 |
+
TOKEN = os.environ['TOKEN']
|
| 11 |
+
REPO_ID = "SimonRaviv/wine-quality"
|
| 12 |
+
MODEL_FILENAME = "sklearn_model.joblib"
|
| 13 |
+
|
| 14 |
+
model_file_path = hf_hub_download(REPO_ID, MODEL_FILENAME, use_auth_token=TOKEN)
|
| 15 |
+
model = joblib.load(model_file_path)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def predict(data):
|
| 19 |
+
prediction = model.predict(data.to_numpy()).tolist()
|
| 20 |
+
prediction = [[p] for p in prediction]
|
| 21 |
+
return prediction
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
headers = [
|
| 25 |
+
"fixed acidity",
|
| 26 |
+
"volatile acidity",
|
| 27 |
+
"citric acid",
|
| 28 |
+
"residual sugar",
|
| 29 |
+
"chlorides",
|
| 30 |
+
"free sulfur dioxide",
|
| 31 |
+
"total sulfur dioxide",
|
| 32 |
+
"density",
|
| 33 |
+
"pH",
|
| 34 |
+
"sulphates",
|
| 35 |
+
"alcohol",
|
| 36 |
+
]
|
| 37 |
+
default = [
|
| 38 |
+
[7.4, 0.7, 0, 1.9, 0.076, 11, 34, 0.9978, 3.51, 0.56, 9.4],
|
| 39 |
+
[7.8, 0.88, 0, 2.6, 0.098, 25, 67, 0.9968, 3.2, 0.68, 9.8],
|
| 40 |
+
[7.8, 0.76, 0.04, 2.3, 0.092, 15, 54, 0.997, 3.26, 0.65, 9.8],
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
inputs = gr.inputs.Dataframe(
|
| 44 |
+
row_count=(3, "dynamic"),
|
| 45 |
+
col_count=(11, "dynamic"),
|
| 46 |
+
headers=headers,
|
| 47 |
+
default=default)
|
| 48 |
+
outputs = gr.outputs.Dataframe(type="numpy", headers=["Quality"])
|
| 49 |
+
|
| 50 |
+
interface = gr.Interface(
|
| 51 |
+
fn=predict,
|
| 52 |
+
title="Wine Quality predictor with SKLearn",
|
| 53 |
+
inputs=inputs,
|
| 54 |
+
outputs=outputs
|
| 55 |
+
)
|
| 56 |
+
interface.launch()
|