Spaces:
Runtime error
Runtime error
File size: 1,388 Bytes
7f6fa29 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import pandas as pd
import numpy as np
from IPython.display import display
from sklearn import preprocessing
from sklearn.neighbors import KNeighborsRegressor
from sklearn.neural_network import MLPRegressor
from sklearn.preprocessing import OneHotEncoder
from pickle import dump, load
import gradio as gr
# load the model
mlp_model = load(open('mlp_classifier.pkl', 'rb'))
# load the scaler
my_scaler = load(open('scaler.pkl', 'rb'))
hot_enc_scaler = load(open('hot_enc.pkl', 'rb'))
def predict_value(age,height_cm,weight_kg,overall,potential,nationality,club):
#pre-processing:
numerical_features = [[age,height_cm,weight_kg,overall,potential]]
catagorical_features = [[nationality,club]]
numerical_features = my_scaler.transform(numerical_features)
catagorical_features = hot_enc_scaler.transform(catagorical_features).toarray()
sample_player = np.concatenate((numerical_features[0], catagorical_features[0]), axis=0)
#predict:
predicted_value = mlp_model.predict(sample_player.reshape(1, -1))
return predicted_value
demo = gr.Interface(
fn=predict_value,
inputs=[gr.Slider(15, 60),gr.Slider(100, 200),gr.Slider(0, 100),gr.Slider(0, 100),gr.Slider(0, 100),
gr.inputs.Dropdown(["Argentina" , "Saudi Arabia", "England"]),
gr.inputs.Dropdown(["FC Barcelona" , "Juventus", "Liverpool"])],
outputs=["number"])
demo.launch() |