|
import gradio as gr |
|
import hopsworks |
|
import joblib |
|
import pandas as pd |
|
from PIL import Image |
|
import requests |
|
|
|
project = hopsworks.login() |
|
fs = project.get_feature_store() |
|
|
|
mr = project.get_model_registry() |
|
model = mr.get_model("wine_model") |
|
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, total_sulfur_dioxide, ph, sulphates, alcohol, type): |
|
|
|
if type == "red": |
|
type = 0 |
|
else: |
|
type = 1 |
|
|
|
print("Calling function") |
|
df = pd.DataFrame([[fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, total_sulfur_dioxide, ph, sulphates, alcohol, type]], columns=['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar', 'chlorides', 'total_sulfur_dioxide', 'ph', 'sulphates', 'alcohol', 'type']) |
|
|
|
print("Predicting") |
|
print(df) |
|
|
|
res = model.predict(df) |
|
|
|
|
|
|
|
print(res) |
|
|
|
url = "https://raw.githubusercontent.com/pierrelefevre/scalable-ml/main/lab1/task2/img/" + str(int(res[0])) + ".png" |
|
img = Image.open(requests.get(url, stream=True).raw) |
|
|
|
return [res[0], img] |
|
|
|
iface = gr.Interface( |
|
fn=wine, |
|
title="Wine Quality Prediction", |
|
description="Predict the quality of a wine based on its features.", |
|
allow_flagging="never", |
|
inputs=[ |
|
gr.Number(label="fixed_acidity", value=7.293673375526557), |
|
gr.Number(label="volatile_acidity", value=0.3), |
|
gr.Number(label="citric_acid", value=0.31), |
|
gr.Number(label="residual_sugar", value=2.2), |
|
gr.Number(label="chlorides", value=0.036), |
|
gr.Number(label="total_sulfur_dioxide", value=95.04095161413584), |
|
gr.Number(label="ph", value=3.3185304801763884), |
|
gr.Number(label="sulphates", value=0.6691971203117211), |
|
gr.Number(label="alcohol", value=13.1), |
|
gr.Radio(["red", "white"], label="type", value="white") |
|
], |
|
outputs=[gr.Number(label="quality"), |
|
gr.Image(type="pil")]) |
|
|
|
iface.launch() |
|
|