SamuelM0422 commited on
Commit
576d46f
·
verified ·
1 Parent(s): e8f91b4

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +52 -0
  2. example_1.mp3 +0 -0
  3. example_2.mp3 +0 -0
  4. example_3.mp3 +0 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+ from pathlib import Path
5
+
6
+ examples = list(Path().rglob('*mp3'))
7
+
8
+ model_id = 'SamuelM0422/whisper-small-pt'
9
+ pipe = pipeline('automatic-speech-recognition', model=model_id)
10
+
11
+ def transcribe_speech(filepath):
12
+ output = pipe(
13
+ filepath,
14
+ max_new_tokens=256,
15
+ generate_kwargs={
16
+ 'task': 'transcribe',
17
+ 'language': 'portuguese'
18
+ },
19
+ chunck_length_s=30,
20
+ batch_size=8
21
+ )
22
+ return output['text']
23
+
24
+ demo = gr.Blocks()
25
+
26
+ title='Audio Transcriber (PT) 🎙️'
27
+ description='A fine-tuned Whisper model for the Portuguese language.'
28
+
29
+ mic_transcribe = gr.Interface(
30
+ fn=transcribe_speech,
31
+ inputs=gr.Audio(sources='microphone', type='filepath'),
32
+ outputs=gr.components.Textbox(),
33
+ flagging_mode='never',
34
+ examples=examples,
35
+ description=description
36
+ )
37
+
38
+ file_transcribe=gr.Interface(
39
+ fn=transcribe_speech,
40
+ inputs=gr.Audio(sources='upload', type='filepath'),
41
+ outputs=gr.components.Textbox(),
42
+ flagging_mode='never',
43
+ examples=examples,
44
+ description=description
45
+ )
46
+
47
+ with demo:
48
+ gr.TabbedInterface([mic_transcribe, file_transcribe], ['Transcribe Microphone', 'Transcribe Audio File'],
49
+ title=title)
50
+
51
+
52
+ demo.launch()
example_1.mp3 ADDED
Binary file (18.6 kB). View file
 
example_2.mp3 ADDED
Binary file (29.9 kB). View file
 
example_3.mp3 ADDED
Binary file (38.1 kB). View file