Upload 3 files
Browse files- README.md +5 -5
- app.py +69 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Wine
|
| 3 |
+
emoji: 🐠
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.4.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
Created on Sun Nov 19 17:34:34 2023
|
| 4 |
+
|
| 5 |
+
@author: Antares
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
from PIL import Image
|
| 10 |
+
import requests
|
| 11 |
+
import hopsworks
|
| 12 |
+
import joblib
|
| 13 |
+
import pandas as pd
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
project = hopsworks.login()
|
| 17 |
+
fs = project.get_feature_store()
|
| 18 |
+
|
| 19 |
+
mr = project.get_model_registry()
|
| 20 |
+
model = mr.get_model("wine_model", version=1)
|
| 21 |
+
model_dir = model.download()
|
| 22 |
+
model = joblib.load(model_dir + "/wine_model.pkl")
|
| 23 |
+
print("Model downloaded")
|
| 24 |
+
|
| 25 |
+
def wine(ttype,fixed_acidity,volatile_acidity,citric_acid,residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,ph,sulphates,alcohol):
|
| 26 |
+
print("Calling function")
|
| 27 |
+
if(ttype=="White/0"):
|
| 28 |
+
ttype = int(0)
|
| 29 |
+
else:
|
| 30 |
+
ttype = int(1)
|
| 31 |
+
#df = [ttype],[fixed_acidity],[volatile_acidity],[citric_acid],[residual_sugar],[chlorides],[free_sulfur_dioxide],[total_sulfur_dioxide],[density],[ph],[sulphates],[alcohol]])
|
| 32 |
+
df = pd.DataFrame([[ttype,fixed_acidity,volatile_acidity,citric_acid,residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,ph,sulphates,alcohol]],
|
| 33 |
+
columns=["type","fixed_acidity","volatile_acidity","citric_acid","residual_sugar","chlorides","free_sulfur_dioxide","total_sulfur_dioxide","density","ph","sulphates","alcohol"])
|
| 34 |
+
print("Predicting")
|
| 35 |
+
print(df)
|
| 36 |
+
# 'res' is a list of predictions returned as the label.
|
| 37 |
+
res = model.predict(df)
|
| 38 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
| 39 |
+
# the first element.
|
| 40 |
+
# print("Res: {0}").format(res)
|
| 41 |
+
print('res:',res)
|
| 42 |
+
#flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
|
| 43 |
+
#img = Image.open(requests.get(flower_url, stream=True).raw)
|
| 44 |
+
return res
|
| 45 |
+
|
| 46 |
+
demo = gr.Interface(
|
| 47 |
+
fn=wine,
|
| 48 |
+
title="Wine Quality Predictive Analytics",
|
| 49 |
+
description="Experiment with 12 wine attributes to predict what quality it is.",
|
| 50 |
+
allow_flagging="never",
|
| 51 |
+
inputs=[
|
| 52 |
+
gr.inputs.Radio(["White/0", "Red/1"], label="type"),
|
| 53 |
+
gr.inputs.Number(default=1.0, label="fixed_acidity"),
|
| 54 |
+
gr.inputs.Number(default=1.0, label="volatile_acidity"),
|
| 55 |
+
gr.inputs.Number(default=1.0, label="citric_acid"),
|
| 56 |
+
gr.inputs.Number(default=1.0, label="residual_sugar"),
|
| 57 |
+
gr.inputs.Number(default=1.0, label="chlorides"),
|
| 58 |
+
gr.inputs.Number(default=1.0, label="free_sulfur_dioxide"),
|
| 59 |
+
gr.inputs.Number(default=1.0, label="total_sulfur_dioxide"),
|
| 60 |
+
gr.inputs.Number(default=1.0, label="density"),
|
| 61 |
+
gr.inputs.Number(default=1.0, label="ph"),
|
| 62 |
+
gr.inputs.Number(default=1.0, label="sulphates"),
|
| 63 |
+
gr.inputs.Number(default=1.0, label="alcohol"),
|
| 64 |
+
],
|
| 65 |
+
|
| 66 |
+
outputs=gr.Number(label="quality"))
|
| 67 |
+
|
| 68 |
+
demo.launch(debug=True,share = True)
|
| 69 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
hopsworks
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn==1.1.1
|