Spaces:
Runtime error
Runtime error
Commit
·
b21c366
1
Parent(s):
9fb11ce
Update public-apps/whisper-chat-app.livemd
Browse files
public-apps/whisper-chat-app.livemd
CHANGED
@@ -22,16 +22,21 @@ This chat is open to anyone, be polite and act responsibly. :) Note chat history
|
|
22 |
|
23 |
```elixir
|
24 |
{:ok, model_info} =
|
25 |
-
Bumblebee.load_model({:hf, "openai/whisper-
|
26 |
|
27 |
-
{:ok, featurizer} = Bumblebee.load_featurizer({:hf, "openai/whisper-
|
28 |
-
{:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "openai/whisper-
|
29 |
|
30 |
serving =
|
31 |
Bumblebee.Audio.speech_to_text(model_info, featurizer, tokenizer,
|
32 |
max_new_tokens: 100,
|
33 |
compile: [batch_size: 8],
|
34 |
-
defn_options: [compiler: EXLA]
|
|
|
|
|
|
|
|
|
|
|
35 |
)
|
36 |
|
37 |
Kino.start_child({Nx.Serving, serving: serving, name: WhisperChat})
|
@@ -51,8 +56,13 @@ Kino.async_listen(form, fn %{data: %{audio: audio, name: name}, origin: origin}
|
|
51 |
|> Nx.reshape({:auto, audio.num_channels})
|
52 |
|> Nx.mean(axes: [1])
|
53 |
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
56 |
Kino.Frame.append(frame, content, temporary: true)
|
57 |
else
|
58 |
content = Kino.Markdown.new("*Error! Name and Audio are required*")
|
|
|
22 |
|
23 |
```elixir
|
24 |
{:ok, model_info} =
|
25 |
+
Bumblebee.load_model({:hf, "openai/whisper-small"}, log_params_diff: false)
|
26 |
|
27 |
+
{:ok, featurizer} = Bumblebee.load_featurizer({:hf, "openai/whisper-small"})
|
28 |
+
{:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "openai/whisper-small"})
|
29 |
|
30 |
serving =
|
31 |
Bumblebee.Audio.speech_to_text(model_info, featurizer, tokenizer,
|
32 |
max_new_tokens: 100,
|
33 |
compile: [batch_size: 8],
|
34 |
+
defn_options: [compiler: EXLA],
|
35 |
+
forced_token_ids: [
|
36 |
+
{1, Bumblebee.Tokenizer.token_to_id(tokenizer, "<|pt|>")},
|
37 |
+
{2, Bumblebee.Tokenizer.token_to_id(tokenizer, "<|transcribe|>")},
|
38 |
+
{3, Bumblebee.Tokenizer.token_to_id(tokenizer, "<|notimestamps|>")}
|
39 |
+
]
|
40 |
)
|
41 |
|
42 |
Kino.start_child({Nx.Serving, serving: serving, name: WhisperChat})
|
|
|
56 |
|> Nx.reshape({:auto, audio.num_channels})
|
57 |
|> Nx.mean(axes: [1])
|
58 |
|
59 |
+
{time, your_func_result} = :timer.tc(&Nx.Serving.batched_run/2, [WhisperChat, audio])
|
60 |
+
|
61 |
+
%{results: [%{text: generated_text}]} = your_func_result
|
62 |
+
|
63 |
+
content =
|
64 |
+
Kino.Markdown.new("**#{name}** (in #{time / (1000 * 1000)} seconds) : #{generated_text}")
|
65 |
+
|
66 |
Kino.Frame.append(frame, content, temporary: true)
|
67 |
else
|
68 |
content = Kino.Markdown.new("*Error! Name and Audio are required*")
|