PrinceDeepakSiddharth12 commited on
Commit
4a6c7eb
·
verified ·
1 Parent(s): 1c4e54e

Upload 6 files

Browse files
final_app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import pandas as pd
4
+ from sklearn.compose import ColumnTransformer
5
+ from sklearn.pipeline import Pipeline
6
+ import numpy as np
7
+ import pandas as pd
8
+ from sklearn.preprocessing import StandardScaler
9
+ from sklearn.preprocessing import OneHotEncoder
10
+
11
+ # Load the model and preprocessor
12
+ model = pickle.load(open('model.pkl', 'rb'))
13
+ preprocessor = pickle.load(open('preprocess_pipeline.pkl', 'rb'))
14
+
15
+
16
+
17
+ def call_gradio(Sex, Equipment, Age, BodyweightKg, BestSquatKg, Bestbenchkg):
18
+ # Convert inputs to appropriate data types
19
+ Age = float(Age)
20
+ BodyweightKg = float(BodyweightKg)
21
+ BestSquatKg = float(BestSquatKg)
22
+ Bestbenchkg = float(Bestbenchkg)
23
+
24
+ # Create a DataFrame with the input data
25
+ df_x = pd.DataFrame({
26
+ 'Sex': [Sex],
27
+ 'Equipment': [Equipment],
28
+ 'Age': [Age],
29
+ 'BodyweightKg': [BodyweightKg],
30
+ 'BestSquatKg': [BestSquatKg],
31
+ 'Bestbench(kg)': [Bestbenchkg],
32
+ })
33
+
34
+ # Define the categorical and numerical feature lists
35
+ categorical_features = ['Sex', 'Equipment']
36
+ numerical_features = df_x.drop(categorical_features, axis=1).columns.tolist()
37
+
38
+ # Ensure that the preprocessor is fitted
39
+ if not hasattr(preprocessor, 'transformers_'):
40
+ raise RuntimeError("The preprocessor is not fitted yet. Fit the preprocessor before calling this function.")
41
+
42
+
43
+ # Transform the data using the preprocessor
44
+ X_processed = preprocessor.transform(df_x)
45
+
46
+ # Access the OneHotEncoder directly to get feature names
47
+ ohe = preprocessor.named_transformers_['cat'].named_steps['onehot']
48
+ cat_feature_names = ohe.get_feature_names_out(categorical_features)
49
+
50
+ # Combine numerical features and one-hot encoded feature names
51
+ all_feature_names = numerical_features + list(cat_feature_names)
52
+
53
+ # Create a DataFrame with processed features
54
+ X_processed_df = pd.DataFrame(X_processed, columns=all_feature_names)
55
+
56
+ # Predict using the model
57
+ y_pred = model.predict(X_processed_df)
58
+
59
+ max_kg = int(y_pred[0])
60
+ return max_kg
61
+
62
+ # Define Gradio inputs and outputs
63
+ sex_dropdown = gr.Dropdown(choices=['M', 'F'], label="Sex", info="Select Male or Female")
64
+ equipment_dropdown = gr.Dropdown(choices=['Raw', 'Wraps', 'Single-ply', 'Multi-ply'], label="Equipment", info="Select the equipment used for the competition.")
65
+ age_textbox = gr.Textbox(lines=1, label="Age", info="Enter your Age")
66
+ bodyweight_kg_textbox = gr.Textbox(lines=1, label="BodyweightKg", info="Enter your Bodyweight in Kg")
67
+ best_squat_kg_textbox = gr.Textbox(lines=1, label="BestSquatKg", info="Enter your Best Squat in Kg")
68
+ best_bench_kg_textbox = gr.Textbox(lines=1, label="BestbenchKg", info="Enter your Best Bench in Kg")
69
+
70
+ # Custom description with image and footer
71
+ description = """
72
+ <div style='text-align: center;'>
73
+ <h1 style='font-size: 50px;'>PowerLift Muscle Map</h1> <!-- Title with increased font size -->
74
+ <p>Use this model to estimate your best Deadlift (kg) based on your selected features. Input your details and see the predicted weight (kg) you could lift.</p>
75
+ <p><strong>Output:</strong> Estimated Best Deadlift (kg)</p>
76
+ <br>
77
+ <p style='font-size: 10px; color: #555;'>❤️ PDS</p>
78
+ </div>
79
+ """
80
+
81
+ # Create and launch Gradio interface
82
+ iface = gr.Interface(
83
+ fn=call_gradio,
84
+ inputs=[sex_dropdown, equipment_dropdown, age_textbox, bodyweight_kg_textbox, best_squat_kg_textbox, best_bench_kg_textbox],
85
+ outputs="number",
86
+ description=description,
87
+ )
88
+
89
+ iface.launch()
gym_powerlifting_cleaned_data.csv ADDED
The diff for this file is too large to render. See raw diff
 
gym_powerlifting_correct.csv ADDED
The diff for this file is too large to render. See raw diff
 
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b07ccdd1ad7e48ecfdaee76e7d8ac51374809937f03178c0c82d49d6ede0df1f
3
+ size 239405
powerlifting_muscle_map.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
preprocess_pipeline.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ab474759d5dceeecd966e7ec35eb4839f07c6e4f43a2929872ad75f001c170b
3
+ size 1995