Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,34 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
5 |
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
# print(f'{tokenizer.pad_token=}')
|
12 |
-
# print(f'{tokenizer.pad_token_id=}')
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
print(f'{tokenize_batch=}')
|
32 |
-
print('Done')
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
|
|
|
4 |
|
5 |
+
# Load the processor and model
|
6 |
+
processor = AutoProcessor.from_pretrained("NbAiLab/nb-whisper-large-verbatim")
|
7 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained("NbAiLab/nb-whisper-large-verbatim")
|
8 |
|
9 |
+
# Ensure the pad token is set
|
10 |
+
if processor.tokenizer.pad_token_id is None:
|
11 |
+
processor.tokenizer.pad_token = processor.tokenizer.eos_token
|
|
|
|
|
12 |
|
13 |
+
# Move the model to the appropriate device
|
14 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
+
model = model.to(device)
|
16 |
|
17 |
+
def transcribe_text(raw_text):
|
18 |
+
# Tokenize the input text
|
19 |
+
tokenize_batch = processor.tokenizer(raw_text, padding="max_length", max_length=5, truncation=True, return_tensors="pt")
|
20 |
+
|
21 |
+
# Output the tokenized result for inspection
|
22 |
+
return tokenize_batch
|
23 |
|
24 |
+
# Gradio interface
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=transcribe_text,
|
27 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
|
28 |
+
outputs="json",
|
29 |
+
title="Whisper Model Tokenization",
|
30 |
+
description="Test the EOS and PAD tokens for NbAiLab/nb-whisper-large-verbatim model."
|
31 |
+
)
|
32 |
|
33 |
+
if __name__ == "__main__":
|
34 |
+
iface.launch()
|
|
|
|