Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +90 -0
- requirements.txt +53 -0
- scaler.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
|
6 |
+
# Function to load the scaler
|
7 |
+
def load_scaler():
|
8 |
+
with open('scaler.pkl', 'rb') as file:
|
9 |
+
scaler = pickle.load(file)
|
10 |
+
return scaler
|
11 |
+
|
12 |
+
# Function to preprocess user input
|
13 |
+
def preprocess_input(user_input, scaler):
|
14 |
+
user_input_df = pd.DataFrame([user_input], columns=feature_names)
|
15 |
+
scaled_input = scaler.transform(user_input_df)
|
16 |
+
return pd.DataFrame(scaled_input, columns=user_input_df.columns)
|
17 |
+
|
18 |
+
# Function to load the model
|
19 |
+
def load_model():
|
20 |
+
model_path = hf_hub_download(repo_id="elladeandra/sports-prediction", filename="ensemble_model.pkl")
|
21 |
+
with open(model_path, 'rb') as file:
|
22 |
+
model = pickle.load(file)
|
23 |
+
return model
|
24 |
+
|
25 |
+
# Define feature names
|
26 |
+
feature_names = ['value_eur', 'age', 'potential', 'movement_reactions', 'wage_eur']
|
27 |
+
|
28 |
+
# Streamlit app title and description
|
29 |
+
st.title('Football Player Rating Predictor')
|
30 |
+
st.markdown("""
|
31 |
+
This application predicts the rating of a football player based on their attributes using an ensemble model.
|
32 |
+
The model combines Random Forest, Gradient Boosting, and XGBoost algorithms for robust predictions.
|
33 |
+
""")
|
34 |
+
|
35 |
+
# Sidebar for user input
|
36 |
+
st.sidebar.header('Input Player Attributes')
|
37 |
+
def get_user_input():
|
38 |
+
value_eur = st.sidebar.number_input('Market Value (EUR)', min_value=0, max_value=int(1e9), value=int(1e6))
|
39 |
+
wage_eur = st.sidebar.number_input('Weekly Wage (EUR)', min_value=0, max_value=int(1e9), value=int(1e6))
|
40 |
+
age = st.sidebar.slider('Player Age', 16, 40, 25)
|
41 |
+
potential = st.sidebar.slider('Potential Score', 1, 100, 50)
|
42 |
+
movement_reactions = st.sidebar.slider('Reactions', 1, 100, 50)
|
43 |
+
|
44 |
+
data = {
|
45 |
+
'value_eur': value_eur,
|
46 |
+
'wage_eur': wage_eur,
|
47 |
+
'age': age,
|
48 |
+
'potential': potential,
|
49 |
+
'movement_reactions': movement_reactions
|
50 |
+
}
|
51 |
+
return data
|
52 |
+
|
53 |
+
user_input = get_user_input()
|
54 |
+
|
55 |
+
try:
|
56 |
+
# Load scaler and preprocess input
|
57 |
+
scaler = load_scaler()
|
58 |
+
scaled_input = preprocess_input(user_input, scaler)
|
59 |
+
|
60 |
+
# Load model and predict
|
61 |
+
model = load_model()
|
62 |
+
predicted_rating = model.predict(scaled_input)
|
63 |
+
|
64 |
+
# Display prediction
|
65 |
+
st.subheader('Predicted Player Rating')
|
66 |
+
st.write(f"Estimated Rating: {predicted_rating[0]:.1f}")
|
67 |
+
|
68 |
+
# Explanation section
|
69 |
+
if st.button('About the Prediction'):
|
70 |
+
st.markdown("""
|
71 |
+
This application uses an ensemble model combining Random Forest, Gradient Boosting, and XGBoost algorithms to predict football player ratings.
|
72 |
+
|
73 |
+
The model is trained on data from the FIFA video game series, which includes attributes such as age, potential, market value, and reaction times.
|
74 |
+
|
75 |
+
**Note**: This is a demo project and should not be used for professional scouting or analysis purposes.
|
76 |
+
""")
|
77 |
+
|
78 |
+
except Exception as e:
|
79 |
+
st.error(f"An error occurred: {e}")
|
80 |
+
|
81 |
+
# Additional features for better user experience
|
82 |
+
if st.sidebar.button('Reset Inputs'):
|
83 |
+
st.experimental_rerun()
|
84 |
+
|
85 |
+
st.sidebar.markdown("""
|
86 |
+
**Instructions**:
|
87 |
+
- Adjust the player attributes using the input fields.
|
88 |
+
- Click the 'Predict' button to see the estimated rating.
|
89 |
+
- Use the 'About the Prediction' button for more information.
|
90 |
+
""")
|
requirements.txt
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.3.0
|
2 |
+
attrs==23.2.0
|
3 |
+
blinker==1.8.2
|
4 |
+
cachetools==5.3.3
|
5 |
+
certifi==2024.6.2
|
6 |
+
charset-normalizer==3.3.2
|
7 |
+
click==8.1.7
|
8 |
+
filelock==3.15.4
|
9 |
+
fsspec==2024.6.0
|
10 |
+
gitdb==4.0.11
|
11 |
+
GitPython==3.1.43
|
12 |
+
huggingface-hub==0.23.4
|
13 |
+
idna==3.7
|
14 |
+
Jinja2==3.1.4
|
15 |
+
joblib==1.4.2
|
16 |
+
jsonschema==4.22.0
|
17 |
+
jsonschema-specifications==2023.12.1
|
18 |
+
llvmlite==0.41.1
|
19 |
+
markdown-it-py==3.0.0
|
20 |
+
MarkupSafe==2.1.5
|
21 |
+
mdurl==0.1.2
|
22 |
+
numba==0.58.1
|
23 |
+
numpy==1.25.2
|
24 |
+
packaging==24.1
|
25 |
+
pandas==2.2.2
|
26 |
+
pillow==10.3.0
|
27 |
+
protobuf==5.27.1
|
28 |
+
pyarrow==16.1.0
|
29 |
+
pydeck==0.9.1
|
30 |
+
Pygments==2.18.0
|
31 |
+
python-dateutil==2.9.0.post0
|
32 |
+
pytz==2024.1
|
33 |
+
PyYAML==6.0.1
|
34 |
+
referencing==0.35.1
|
35 |
+
requests==2.32.3
|
36 |
+
rich==13.7.1
|
37 |
+
rpds-py==0.18.1
|
38 |
+
scikit-learn==1.2.2
|
39 |
+
scipy==1.13.1
|
40 |
+
six==1.16.0
|
41 |
+
sklearn-pandas==2.2.0
|
42 |
+
smmap==5.0.1
|
43 |
+
streamlit==1.36.0
|
44 |
+
tenacity==8.4.1
|
45 |
+
threadpoolctl==3.5.0
|
46 |
+
toml==0.10.2
|
47 |
+
toolz==0.12.1
|
48 |
+
tornado==6.4.1
|
49 |
+
tqdm==4.66.4
|
50 |
+
typing_extensions==4.12.2
|
51 |
+
tzdata==2024.1
|
52 |
+
urllib3==2.2.2
|
53 |
+
xgboost==2.0.3
|
scaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:51618a02bb9ce18f78466307260c7634cf8b2114983b3472bb8275ce894fa2f0
|
3 |
+
size 718
|