import streamlit as st import pandas as pd import numpy as np import seaborn as sns import json import transformers # Load model with open('list_num_columns.txt', 'r') as file_1: list_num_cols = json.load(file_1) with open('list_cat_columns.txt', 'r') as file_2: list_cat_cols = json.load(file_2) with open('model_scaler.pkl', 'rb') as file_3: model_scaler = pickle.load(file_3) with open('model_encoder.pkl', 'rb') as file_4: model_encoder = pickle.load(file_4) with open('model_lin_reg.pkl', 'rb') as file_5: model_lin_reg = pickle.load(file_5) with st.form('form_fifa_2022'): name = st.text_input('Name', value='', help='Player name') age = st.number_input('Age', min_value=12, max_value=48, value=28, step=2, help='Player age') weight = st.number_input('Weight', min_value=30, max_value=100, value=80, help='Player weight') height = st.number_input('Height', min_value=140, max_value=210, value=180, help='Player height') price = st.slider('Price', 0, 200000000, 0) st.markdown('---') defense = st.radio('Defending Work Rate', ('Low','Medium','High'), index=1) attack = st.radio('Attacking Work Rate', ('Low','Medium','High'), index=1) st.markdown('---') pace = st.number_input('Pace', 0, 100, 50) shoot = st.number_input('Shooting', 0, 100, 50) passing = st.number_input('Passing', 0, 100, 50) dribble = st.number_input('Dribbling', 0, 100, 50) defend = st.number_input('Defending', 0, 100, 50) physical = st.number_input('Phisicality', 0, 100, 50) st.markdown('---') submitted = st.form_submit_button('Predict') data_inf = { 'Name': name, 'Age': age, 'Weight': weight, 'Height': height, 'Price': price, 'AttackRate': attack, 'DefenseRate': defense, 'PaceTotal': pace, 'ShootingTotal': shoot, 'PassingTotal': passing, 'DribblingTotal': dribble, 'DefendingTotal': defend, 'PhysicalityTotal': physical } data_inf = pd.DataFrame([data_inf]) st.dataframe(data_inf) if submitted: # Numeric-Categoric split data_inf_num = data_inf[list_num_cols] data_inf_cat = data_inf[list_cat_cols] # Numeric data_inf_num_scaled = model_scaler.transform(data_inf_num) # Categoric data_inf_cat_encoded = model_encoder.transform(data_inf_cat) # Concatenate data_inf_final = np.concatenate([data_inf_num_scaled,data_inf_cat_encoded], axis=1) # Predict y_inf_pred = model_lin_reg.predict(data_inf_final) # Show prediction st.write('# Rating: ', str(int(y_inf_pred)))