Spaces:
Runtime error
Runtime error
File size: 2,050 Bytes
450ea0f 23d5955 450ea0f 23d5955 450ea0f 3c580c9 450ea0f 23d5955 450ea0f 5f94fd6 450ea0f 5f94fd6 450ea0f 5f94fd6 72d4675 450ea0f 23d5955 450ea0f 23d5955 450ea0f 5f94fd6 23d5955 5f94fd6 23d5955 5f94fd6 23d5955 72d4675 450ea0f 23d5955 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import gradio as gr
import numpy as np
from PIL import Image
import requests
import pandas as pd
import hopsworks
import joblib
project = hopsworks.login()
fs = project.get_feature_store()
mr = project.get_model_registry()
model = mr.get_model("wine_model_final", version=3)
model_dir = model.download()
model = joblib.load(model_dir + "/wine_model.pkl")
def wine(volatile_acidity,citric_acid, chlorides, total_sulfur_dioxide, density, alcohol):
print("Calling function")
# if type=='White':
# type=1
# else:
# type=0
df = pd.DataFrame([[volatile_acidity, citric_acid, chlorides, total_sulfur_dioxide ,density, alcohol]],
columns=['volatile_acidity','citric_acid', 'chlorides', 'total_sulfur_dioxide','density', 'alcohol'])
print("Predicting")
print(df)
# 'res' is a list of predictions returned as the label.
res = model.predict(df)
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
# the first element.
print(res)
#TO_DO: Add images, change to url to the directory with our images
flower_url = "https://raw.githubusercontent.com/rezaqorbani/scalable-ml-and-dl-labs/main/lab1/wine/wine_images/" + str(res[0]) + ".png"
img = Image.open(requests.get(flower_url, stream=True).raw)
return img
demo = gr.Interface(
fn=wine,
title="Wine Quality Predictive Analytics",
description="Experiment with different input features to predict the wine quality.",
allow_flagging="never",
inputs=[
#gr.inputs.Radio(default='White', label="Wine type", choices=['White','Red']),
gr.inputs.Slider(0,1.6,label='Volatile Acidity'),
gr.inputs.Slider(0,1.7,label='Citric Acid'),
gr.inputs.Slider(0,0.7, label="Chlorides"),
gr.inputs.Slider(6,440,label='Total Sulfur Dioxide'),
gr.inputs.Slider(0.98,1.04, label="Density"),
gr.inputs.Number(default='10', label="Alcohol"),
],
outputs=gr.Image(type="pil"))
demo.launch() |