Spaces:
Sleeping
Sleeping
Niharmahesh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,35 +3,26 @@ import cv2
|
|
3 |
import numpy as np
|
4 |
import mediapipe as mp
|
5 |
import pickle
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
except Exception as e:
|
19 |
-
st.error(f"Error loading model from {file_path}: {e}")
|
20 |
-
return None
|
21 |
|
22 |
models = {
|
23 |
-
'Random Forest':
|
24 |
-
'SVM':
|
25 |
-
'Hard Voting':
|
26 |
-
'Soft Voting':
|
27 |
}
|
28 |
|
29 |
-
# Load label encoder
|
30 |
-
label_encoder = load_model(os.path.join(models_dir, 'label_encoder.pkl'))
|
31 |
-
if label_encoder is None:
|
32 |
-
st.error("Failed to load label encoder. Exiting.")
|
33 |
-
st.stop()
|
34 |
-
|
35 |
# Initialize MediaPipe Hands
|
36 |
mp_hands = mp.solutions.hands
|
37 |
hands = mp_hands.Hands(static_image_mode=True, max_num_hands=1, min_detection_confidence=0.5)
|
@@ -67,8 +58,6 @@ def predict_alphabet(image):
|
|
67 |
predictions = {}
|
68 |
|
69 |
for model_name, model in models.items():
|
70 |
-
if model is None:
|
71 |
-
continue
|
72 |
prediction, probability = get_model_predictions(data_aux, model)
|
73 |
predictions[model_name] = (prediction, probability)
|
74 |
|
|
|
3 |
import numpy as np
|
4 |
import mediapipe as mp
|
5 |
import pickle
|
6 |
+
|
7 |
+
# Load models directly
|
8 |
+
with open('random_forest_model.pkl', 'rb') as file:
|
9 |
+
random_forest_model = pickle.load(file)
|
10 |
+
with open('svm_model.pkl', 'rb') as file:
|
11 |
+
svm_model = pickle.load(file)
|
12 |
+
with open('hard_voting_classifier.pkl', 'rb') as file:
|
13 |
+
hard_voting_model = pickle.load(file)
|
14 |
+
with open('soft_voting_classifier.pkl', 'rb') as file:
|
15 |
+
soft_voting_model = pickle.load(file)
|
16 |
+
with open('label_encoder.pkl', 'rb') as file:
|
17 |
+
label_encoder = pickle.load(file)
|
|
|
|
|
|
|
18 |
|
19 |
models = {
|
20 |
+
'Random Forest': random_forest_model,
|
21 |
+
'SVM': svm_model,
|
22 |
+
'Hard Voting': hard_voting_model,
|
23 |
+
'Soft Voting': soft_voting_model
|
24 |
}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Initialize MediaPipe Hands
|
27 |
mp_hands = mp.solutions.hands
|
28 |
hands = mp_hands.Hands(static_image_mode=True, max_num_hands=1, min_detection_confidence=0.5)
|
|
|
58 |
predictions = {}
|
59 |
|
60 |
for model_name, model in models.items():
|
|
|
|
|
61 |
prediction, probability = get_model_predictions(data_aux, model)
|
62 |
predictions[model_name] = (prediction, probability)
|
63 |
|