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