Spaces:
Runtime error
Runtime error
DurreSudoku
commited on
Commit
•
632ba03
1
Parent(s):
0776ff4
Upload 2 files
Browse files- app.py +65 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
import hopsworks
|
5 |
+
import joblib
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
|
9 |
+
project = hopsworks.login()
|
10 |
+
fs = project.get_feature_store()
|
11 |
+
|
12 |
+
mr = project.get_model_registry()
|
13 |
+
model = mr.get_model("wine_quality_model", version=1)
|
14 |
+
model_dir = model.download()
|
15 |
+
model = joblib.load(model_dir + "/wine_quality_model.pkl")
|
16 |
+
print("Model downloaded")
|
17 |
+
|
18 |
+
scaler = mr.get_model("wine_quality_scaler", version=1)
|
19 |
+
scaler_dir = model.download()
|
20 |
+
scaler = joblib.load(scaler_dir + "/wine_quality_scaler.pkl")
|
21 |
+
|
22 |
+
print("Scaler downloaded")
|
23 |
+
|
24 |
+
def wine_quality(fixed_acidity, volatile_acidity, citric_acid, residual_sugar,
|
25 |
+
chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density,
|
26 |
+
ph, sulphates, alcohol):
|
27 |
+
print("Calling Function...")
|
28 |
+
data = [fixed_acidity, volatile_acidity, citric_acid, residual_sugar,
|
29 |
+
chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density,
|
30 |
+
ph, sulphates, alcohol]
|
31 |
+
feature_cols = ['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar',
|
32 |
+
'chlorides', 'free_sulfur_dioxide', 'total_sulfur_dioxide', 'density',
|
33 |
+
'ph', 'sulphates', 'alcohol']
|
34 |
+
|
35 |
+
user_input_df = pd.DataFrame([data], columns=feature_cols)
|
36 |
+
|
37 |
+
scaled_input = scaler.transform(user_input_df)
|
38 |
+
|
39 |
+
prediction = model.predict(scaled_input)
|
40 |
+
print(prediction)
|
41 |
+
img = Image.open("/assets/" + str(prediction[0] + ".png"))
|
42 |
+
return img
|
43 |
+
|
44 |
+
demo = gr.Interface(
|
45 |
+
fn=wine_quality,
|
46 |
+
title="Wine Quality Predictive Analytics",
|
47 |
+
description="Experiment with different wine characteristics to predict its quality.",
|
48 |
+
allow_flagging="never",
|
49 |
+
inputs=[
|
50 |
+
gr.inputs.Number(default=2.0, label="Fixed Acidity"),
|
51 |
+
gr.inputs.Number(default=1.0, label="Volatile Acidity"),
|
52 |
+
gr.inputs.Number(default=2.0, label="Citric Acid"),
|
53 |
+
gr.inputs.Number(default=1.0, label="Residual Sugar"),
|
54 |
+
gr.inputs.Number(default=1.0, label="Chlorides"),
|
55 |
+
gr.inputs.Number(default=1.0, label="Free Sulfur Dioxide"),
|
56 |
+
gr.inputs.Number(default=1.0, label="Total Sulfur Dioxide"),
|
57 |
+
gr.inputs.Number(default=1.0, label="Density"),
|
58 |
+
gr.inputs.Number(default=1.0, label="pH"),
|
59 |
+
gr.inputs.Number(default=1.0, label="Sulphates"),
|
60 |
+
gr.inputs.Number(default=1.0, label="Alcohol"),
|
61 |
+
],
|
62 |
+
outputs=gr.Image(type="pil"))
|
63 |
+
|
64 |
+
|
65 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
httpx==0.24.1
|
2 |
+
hopsworks
|
3 |
+
joblib
|
4 |
+
scikit-learn
|