ihanif commited on
Commit
796f6f8
1 Parent(s): 838b360

Use wav2vec params for the pipeline

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -4,19 +4,24 @@ import gradio as gr
4
  import pytube as pt
5
  from transformers import pipeline
6
  from huggingface_hub import model_info
 
7
 
8
- MODEL_NAME = "ihanif/wav2vec2-xls-r-300m-pashto" #this always needs to stay in line 8 :D sorry for the hackiness
9
  lang = "ps"
10
 
 
 
 
 
11
  device = 0 if torch.cuda.is_available() else "cpu"
12
  pipe = pipeline(
13
  task="automatic-speech-recognition",
14
  model=MODEL_NAME,
15
- chunk_length_s=30,
16
  device=device,
17
  )
18
 
19
- pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
20
 
21
  def transcribe(microphone, file_upload):
22
  warn_output = ""
@@ -32,6 +37,7 @@ def transcribe(microphone, file_upload):
32
  file = microphone if microphone is not None else file_upload
33
 
34
  text = pipe(file)["text"]
 
35
 
36
  return warn_output + text
37
 
 
4
  import pytube as pt
5
  from transformers import pipeline
6
  from huggingface_hub import model_info
7
+ #from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
8
 
9
+ MODEL_NAME = "ihanif/wav2vec2-xls-r-300m-pashto"
10
  lang = "ps"
11
 
12
+ #load pre-trained model and tokenizer
13
+ #processor = Wav2Vec2Processor.from_pretrained(MODEL_NAME)
14
+ #model = Wav2Vec2ForCTC.from_pretrained(MODEL_NAME)
15
+
16
  device = 0 if torch.cuda.is_available() else "cpu"
17
  pipe = pipeline(
18
  task="automatic-speech-recognition",
19
  model=MODEL_NAME,
20
+ #chunk_length_s=30,
21
  device=device,
22
  )
23
 
24
+ #pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
25
 
26
  def transcribe(microphone, file_upload):
27
  warn_output = ""
 
37
  file = microphone if microphone is not None else file_upload
38
 
39
  text = pipe(file)["text"]
40
+ #transcription = wav2vec_model(audio)["text"]
41
 
42
  return warn_output + text
43