Spaces:
Sleeping
Sleeping
kozak-vaclav
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -19,9 +19,19 @@ def extract_mel_spectrogram(audio) -> np.ndarray:
|
|
19 |
#spectrogram = np.expand_dims(spectrogram, axis=-1) # Adding channel dimension for the model
|
20 |
return spectrogram
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Download model from Hugging Face Hub
|
23 |
model_path = hf_hub_download(repo_id="kobrasoft/kobraspeech-rnn-cs", filename="kobraspeech.17-40.19.keras")
|
24 |
-
|
|
|
25 |
|
26 |
def decode_batch_predictions(pred):
|
27 |
input_len = np.ones(pred.shape[0]) * pred.shape[1]
|
|
|
19 |
#spectrogram = np.expand_dims(spectrogram, axis=-1) # Adding channel dimension for the model
|
20 |
return spectrogram
|
21 |
|
22 |
+
def CTCLoss(y_true, y_pred):
|
23 |
+
# Compute the training-time loss value
|
24 |
+
batch_len = tf.cast(tf.shape(y_true)[0], dtype="int64")
|
25 |
+
input_length = tf.math.reduce_sum(tf.cast(tf.not_equal(tf.reduce_max(y_pred, axis=2), 0), dtype="int64"), axis=1, keepdims=True)
|
26 |
+
label_length = tf.math.reduce_sum(tf.cast(tf.not_equal(y_true, -1), dtype="int64"), axis=1, keepdims=True)
|
27 |
+
|
28 |
+
loss = tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_length, label_length)
|
29 |
+
return loss
|
30 |
+
|
31 |
# Download model from Hugging Face Hub
|
32 |
model_path = hf_hub_download(repo_id="kobrasoft/kobraspeech-rnn-cs", filename="kobraspeech.17-40.19.keras")
|
33 |
+
with tf.keras.utils.custom_object_scope({'CTCLoss': CTCLoss}):
|
34 |
+
model = tf.keras.models.load_model(model_path)
|
35 |
|
36 |
def decode_batch_predictions(pred):
|
37 |
input_len = np.ones(pred.shape[0]) * pred.shape[1]
|