Spaces:
Running
Running
camparchimedes
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,75 +1,32 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
import torch
|
4 |
-
from transformers import
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
attention_mask = attention_mask.to(device)
|
34 |
-
|
35 |
-
tokenizer.pad_token != tokenizer.eos_token
|
36 |
-
|
37 |
-
with torch.no_grad():
|
38 |
-
output = model.generate(
|
39 |
-
inputs.input_features,
|
40 |
-
max_length=1024, # Increase max_length for longer outputs
|
41 |
-
num_beams=7,
|
42 |
-
task="transcribe",
|
43 |
-
attention_mask=attention_mask,
|
44 |
-
forced_decoder_ids=None, # forced_decoder_ids must not be set
|
45 |
-
language="no"
|
46 |
-
)
|
47 |
-
transcription += " ".join(processor.batch_decode(output, skip_special_tokens=True)) + " "
|
48 |
-
|
49 |
-
return transcription.strip()
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
# HTML |banner image
|
55 |
-
banner_html = """
|
56 |
-
<div style="text-align: center;">
|
57 |
-
<img src="https://huggingface.co/spaces/camparchimedes/ola_s-audioshop/resolve/main/Olas_AudioSwitch_Shop.png" width="87%" height="auto"/>
|
58 |
-
</div>
|
59 |
-
"""
|
60 |
-
|
61 |
-
# Gradio interface
|
62 |
-
iface = gr.Blocks()
|
63 |
-
|
64 |
-
with iface:
|
65 |
-
gr.HTML(banner_html)
|
66 |
-
gr.Markdown("# ππ―π’ππ’π ππππ ππΌπΎπ¦Ύβ‘ @{NbAiLab/whisper-norwegian-medium}\nUpload audio file:β")
|
67 |
-
audio_input = gr.Audio(type="filepath")
|
68 |
-
batch_size_input = gr.Slider(minimum=1, maximum=16, step=1, label="Batch Size")
|
69 |
-
transcription_output = gr.Textbox()
|
70 |
-
transcribe_button = gr.Button("Transcribe")
|
71 |
-
|
72 |
-
transcribe_button.click(fn=transcribe_audio, inputs=[audio_input, batch_size_input], outputs=transcription_output)
|
73 |
-
|
74 |
-
# Launch interface
|
75 |
-
iface.launch(share=True, debug=True)
|
|
|
1 |
+
def test_eos_pad():
|
2 |
+
from datasets import load_dataset
|
3 |
+
import torch
|
4 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
5 |
+
|
6 |
+
raw_text_batch = 'a'
|
7 |
+
|
8 |
+
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
9 |
+
# print(f'{tokenizer.eos_token=}')
|
10 |
+
# print(f'{tokenizer.eos_token_id=}')
|
11 |
+
# print(f'{tokenizer.pad_token=}')
|
12 |
+
# print(f'{tokenizer.pad_token_id=}')
|
13 |
+
|
14 |
+
# print(f'{raw_text_batch=}')
|
15 |
+
# tokenize_batch = tokenizer(raw_text_batch, padding="max_length", max_length=5, truncation=True, return_tensors="pt")
|
16 |
+
# print(f'{tokenize_batch=}')
|
17 |
+
|
18 |
+
if tokenizer.pad_token_id is None:
|
19 |
+
tokenizer.pad_token = tokenizer.eos_token
|
20 |
+
probe_network = GPT2LMHeadModel.from_pretrained("gpt2")
|
21 |
+
device = torch.device(f"cuda:{0}" if torch.cuda.is_available() else "cpu")
|
22 |
+
probe_network = probe_network.to(device)
|
23 |
+
|
24 |
+
print(f'{tokenizer.eos_token=}')
|
25 |
+
print(f'{tokenizer.eos_token_id=}')
|
26 |
+
print(f'{tokenizer.pad_token=}')
|
27 |
+
print(f'{tokenizer.pad_token_id=}')
|
28 |
+
|
29 |
+
print(f'{raw_text_batch=}')
|
30 |
+
tokenize_batch = tokenizer(raw_text_batch, padding="max_length", max_length=5, truncation=True, return_tensors="pt")
|
31 |
+
print(f'{tokenize_batch=}')
|
32 |
+
print('Done')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|