Matthijs Hollemans commited on
Commit
bbb7e65
โ€ข
1 Parent(s): caaf71e

limit input length

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -27,6 +27,10 @@ def predict(text, speaker):
27
 
28
  inputs = processor(text=text, return_tensors="pt")
29
 
 
 
 
 
30
  if speaker == "Surprise Me!":
31
  # load one of the provided speaker embeddings at random
32
  idx = np.random.randint(len(speaker_embeddings))
@@ -47,7 +51,7 @@ def predict(text, speaker):
47
 
48
  speaker_embedding = torch.tensor(speaker_embedding).unsqueeze(0)
49
 
50
- speech = model.generate_speech(inputs["input_ids"], speaker_embedding, vocoder=vocoder)
51
 
52
  speech = (speech.numpy() * 32767).astype(np.int16)
53
  return (16000, speech)
 
27
 
28
  inputs = processor(text=text, return_tensors="pt")
29
 
30
+ # limit input length
31
+ input_ids = inputs["input_ids"]
32
+ input_ids = input_ids[..., :model.config.max_text_positions]
33
+
34
  if speaker == "Surprise Me!":
35
  # load one of the provided speaker embeddings at random
36
  idx = np.random.randint(len(speaker_embeddings))
 
51
 
52
  speaker_embedding = torch.tensor(speaker_embedding).unsqueeze(0)
53
 
54
+ speech = model.generate_speech(input_ids, speaker_embedding, vocoder=vocoder)
55
 
56
  speech = (speech.numpy() * 32767).astype(np.int16)
57
  return (16000, speech)