Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,13 +69,20 @@ def extract_features(audio_data, sample_rate, max_pad_len=174):
|
|
| 69 |
|
| 70 |
# Initialize model and label encoder
|
| 71 |
device = torch.device('cpu') # Use CPU for deployment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
authorized_users = ['user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7']
|
| 73 |
|
| 74 |
-
# Initialize label encoder with
|
| 75 |
label_encoder = LabelEncoder()
|
| 76 |
-
#
|
| 77 |
-
all_users = ['user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7'] # Add all your users here
|
| 78 |
-
label_encoder.fit(all_users)
|
| 79 |
|
| 80 |
# Load model
|
| 81 |
model = None
|
|
@@ -141,7 +148,7 @@ def predict_voice(audio_file, confidence_threshold=0.7):
|
|
| 141 |
f"❌ Access Denied - Unauthorized User",
|
| 142 |
predicted_user,
|
| 143 |
confidence_score,
|
| 144 |
-
f"User '{predicted_user}' not in authorized list"
|
| 145 |
)
|
| 146 |
|
| 147 |
return (
|
|
@@ -163,7 +170,11 @@ def create_interface():
|
|
| 163 |
|
| 164 |
This system uses advanced voice recognition to control access. Upload an audio file to test the system.
|
| 165 |
|
|
|
|
|
|
|
| 166 |
**Authorized Users:** user1, user2, user3, user4, user5, user6, user7
|
|
|
|
|
|
|
| 167 |
"""
|
| 168 |
)
|
| 169 |
|
|
@@ -217,7 +228,10 @@ def create_interface():
|
|
| 217 |
3. **Set Threshold**: Adjust the confidence threshold (higher = more strict)
|
| 218 |
4. **Analyze**: Click 'Analyze Voice' to process the audio
|
| 219 |
|
| 220 |
-
The system will
|
|
|
|
|
|
|
|
|
|
| 221 |
"""
|
| 222 |
)
|
| 223 |
|
|
|
|
| 69 |
|
| 70 |
# Initialize model and label encoder
|
| 71 |
device = torch.device('cpu') # Use CPU for deployment
|
| 72 |
+
|
| 73 |
+
# FIXED: Use all 26 users that the model was trained on (from your training log)
|
| 74 |
+
all_users = [
|
| 75 |
+
'user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7', 'user8', 'user9', 'user10',
|
| 76 |
+
'user11', 'user12', 'user13', 'user14', 'user15', 'user16', 'user17', 'user19', 'user20',
|
| 77 |
+
'user21', 'user22', 'user23', 'user24', 'user25', 'user26', 'user27'
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
# Define which users are authorized for access (you can customize this)
|
| 81 |
authorized_users = ['user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7']
|
| 82 |
|
| 83 |
+
# Initialize label encoder with ALL classes the model was trained on
|
| 84 |
label_encoder = LabelEncoder()
|
| 85 |
+
label_encoder.fit(sorted(all_users)) # Sort to ensure consistent ordering
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# Load model
|
| 88 |
model = None
|
|
|
|
| 148 |
f"❌ Access Denied - Unauthorized User",
|
| 149 |
predicted_user,
|
| 150 |
confidence_score,
|
| 151 |
+
f"User '{predicted_user}' recognized but not in authorized list"
|
| 152 |
)
|
| 153 |
|
| 154 |
return (
|
|
|
|
| 170 |
|
| 171 |
This system uses advanced voice recognition to control access. Upload an audio file to test the system.
|
| 172 |
|
| 173 |
+
**Model Training:** Trained on 26 users (user1-user27, excluding user18)
|
| 174 |
+
|
| 175 |
**Authorized Users:** user1, user2, user3, user4, user5, user6, user7
|
| 176 |
+
|
| 177 |
+
**Note:** The system can recognize all 26 users but only grants access to authorized ones.
|
| 178 |
"""
|
| 179 |
)
|
| 180 |
|
|
|
|
| 228 |
3. **Set Threshold**: Adjust the confidence threshold (higher = more strict)
|
| 229 |
4. **Analyze**: Click 'Analyze Voice' to process the audio
|
| 230 |
|
| 231 |
+
The system will:
|
| 232 |
+
- Recognize the speaker among 26 trained users
|
| 233 |
+
- Check if they're in the authorized list
|
| 234 |
+
- Grant/deny access based on confidence and authorization
|
| 235 |
"""
|
| 236 |
)
|
| 237 |
|