3koozy's picture
Update app.py
565084e
raw
history blame
1.39 kB
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()