kozak-vaclav commited on
Commit
805863b
1 Parent(s): 728ec5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -33,10 +33,17 @@ model_path = hf_hub_download(repo_id="kobrasoft/kobraspeech-rnn-cs", filename="k
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]
38
  # Use greedy search. For complex tasks, you can use beam search
39
- results = keras.backend.ctc_decode(pred, input_length=input_len, greedy=True)[0][0]
40
  # Iterate over the results and get back the text
41
  output_text = []
42
  for result in results:
 
33
  with tf.keras.utils.custom_object_scope({'CTCLoss': CTCLoss}):
34
  model = tf.keras.models.load_model(model_path)
35
 
36
+ num_to_char_path = hf_hub_download(repo_id="kobrasoft/kobraspeech-rnn-cs", filename="num_to_char.json")
37
+ with open(num_to_char_path, "rb") as f:
38
+ num_to_char = tf.keras.layers.StringLookup(vocabulary=pkl.load(f), oov_token="", invert=True)
39
+
40
+ def label_to_string(label):
41
+ return tf.strings.reduce_join(num_to_char(label)).numpy().decode()
42
+
43
  def decode_batch_predictions(pred):
44
  input_len = np.ones(pred.shape[0]) * pred.shape[1]
45
  # Use greedy search. For complex tasks, you can use beam search
46
+ results = tf.keras.backend.ctc_decode(pred, input_length=input_len, greedy=True)[0][0]
47
  # Iterate over the results and get back the text
48
  output_text = []
49
  for result in results: