Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image | |
import requests | |
import hopsworks | |
import joblib | |
import pandas as pd | |
project = hopsworks.login() | |
fs = project.get_feature_store() | |
mr = project.get_model_registry() | |
model_red = mr.get_model("wine_red_model", version=1) | |
model_dir_red = model_red.download() | |
model_red = joblib.load(model_dir_red + "/wine_red_model.pkl") | |
print("Red Model downloaded") | |
model_white = mr.get_model("wine_white_model", version=1) | |
model_dir_white = model_white.download() | |
model_white = joblib.load(model_dir_white + "/wine_white_model.pkl") | |
print("White Model downloaded") | |
def wine(category, alcohol, chlorides, density, volatil_acidity,fixed_acidity, citric_acid,total_sulfur_dioxide): | |
print("Calling function") | |
df = pd.DataFrame([[alcohol, chlorides, density, volatil_acidity,fixed_acidity, citric_acid,total_sulfur_dioxide]], | |
columns=['alcohol','chlorides','density','volatil_acidity','fixed_acidity','citric_acid','total_sulfur_dioxide']) | |
print("Predicting") | |
print(df) | |
if category == "red": | |
res = model_red.predict(df) | |
print(res) | |
wine_url = "https://raw.githubusercontent.com/Anniyuku/wine_quality/main/" + res[0] + ".png" | |
img = Image.open(requests.get(wine_url, stream=True).raw) | |
else : | |
res = model_white.predict(df) | |
print(res) | |
wine_url = "https://raw.githubusercontent.com/Anniyuku/wine_quality/main/" + res[0] + ".png" | |
img = Image.open(requests.get(wine_url, stream=True).raw) | |
return img | |
demo = gr.Interface( | |
fn=wine, | |
title="Wine Predictive Analytics", | |
description="Experiment with type, alcohol, chlorides, density, volatil_acidity, fixed_acidity, citric_acid, total_sulfur_dioxide to predict which flower it is.", | |
allow_flagging="never", | |
inputs=[ | |
gr.inputs.Radio(choices=["white","red"], label='category'), | |
gr.inputs.Number(default=12.4, label="alcohol"), | |
gr.inputs.Number(default=0.04, label="chlorides"), | |
gr.inputs.Number(default=0.99, label="density"), | |
gr.inputs.Number(default=0.16, label="volatil_acidity"), | |
gr.inputs.Number(default=6.60, label="fixed_acidity"), | |
gr.inputs.Number(default=0.40, label="citric_acid"), | |
gr.inputs.Number(default=143, label="total_sulfur_dioxide"), | |
], | |
outputs=gr.Image(type="pil")) | |
demo.launch(debug=True) | |