Spaces:
Runtime error
Runtime error
import modal | |
from PIL import Image | |
import gradio as gr | |
MODEL_VERSION = 6 | |
LOCAL = True | |
if LOCAL == False: | |
hopsworks_image = modal.Image.debian_slim(python_version='3.9').pip_install(["gradio", "requests", "hopsworks", "joblib", "pandas", "scikit-learn==1.1.1"]) | |
stub = modal.Stub("wine_prediction_user_interface") | |
def f(): | |
g() | |
def g(): | |
import requests | |
import hopsworks | |
import joblib | |
import pandas as pd | |
project = hopsworks.login() | |
fs = project.get_feature_store() | |
mr = project.get_model_registry() | |
model = mr.get_model("wine_model", version=MODEL_VERSION) | |
model_dir = model.download() | |
model = joblib.load(model_dir + "/wine_model.pkl") | |
print("Model downloaded") | |
def wine(fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, | |
total_sulfar_dioxide, density, ph, sulphates, alcohol, color): | |
print("Calling function") | |
# df = pd.DataFrame([[sepal_length],[sepal_width],[petal_length],[petal_width]], | |
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, | |
total_sulfar_dioxide, density, ph, sulphates, alcohol, color]], | |
columns=['fixed_acidity', 'volatile_acidity', 'citric_aicd', 'residual_sugar', 'chlorides', 'free_sulfur_dioxide', | |
'total_sulfur_dioxide', 'density', 'ph', 'sulphates', 'alcohol', 'color']) | |
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: {0}").format(res) | |
print(res) | |
return res | |
demo = gr.Interface( | |
fn=wine, | |
title="Wine Quality Predictive Analytics", | |
description="Experiment with several parameters to predict the quality of wine.", | |
allow_flagging="never", | |
inputs=[ | |
gr.Number(value=1.0, label="fixed_acidity [3.8,15.9]"), | |
gr.Number(value=1.0, label="volatile_acidity [0.1,1.6]"), | |
gr.Number(value=1.0, label="citric_aicd [0.0,1.6]"), | |
gr.Number(value=1.0, label="residual_sugar [0.6,65.8]"), | |
gr.Number(value=1.0, label="chlorides [0.0,0.6]"), | |
gr.Number(value=1.0, label="free_sulfur_dioxide [1.0,289.0]"), | |
gr.Number(value=1.0, label="total_sulfur_dioxide [6.0,440.0]"), | |
gr.Number(value=1.0, label="density [0.9,1.0]"), | |
gr.Number(value=1.0, label="ph [2.7,4.0]"), | |
gr.Number(value=1.0, label="sulphates [0.2,2.0]"), | |
gr.Number(value=1.0, label="alcohol [8.0,14.9]"), | |
gr.Number(value=1.0, label="color (0:red, 1:white)"), | |
], | |
outputs=gr.Number(label="predicted quality")) | |
demo.launch(debug=True) | |
if __name__ == "__main__": | |
if LOCAL == True : | |
g() | |
else: | |
modal.runner.deploy_stub(stub) | |
with stub.run(): | |
f.remote() |