DrishtiSharma commited on
Commit
be5f920
1 Parent(s): c511e50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -17,15 +17,22 @@ feature_extractor = AutoFeatureExtractor.from_pretrained(
17
  )
18
  sampling_rate = feature_extractor.sampling_rate
19
 
20
- asr = pipeline(
21
- "automatic-speech-recognition", model="anuragshas/wav2vec2-xls-r-1b-hi-with-lm"
22
- )
 
 
 
23
 
24
 
25
  def predict_and_ctc_lm_decode(input_file):
26
  speech = load_and_fix_data(input_file, sampling_rate)
27
  transcribed_text = asr(speech, chunk_length_s=5, stride_length_s=1)
28
- return transcribed_text["text"]
 
 
 
 
29
 
30
 
31
  gr.Interface(
@@ -35,9 +42,8 @@ gr.Interface(
35
  ],
36
  outputs=[gr.outputs.Textbox()],
37
  examples=[["example1.wav"]],
38
- title="Hindi ASR using Wav2Vec2-1B with LM",
39
- article="<p><center><img src='https://visitor-badge.glitch.me/badge?page_id=anuragshas/Hindi_ASR' alt='visitor badge'></center></p>",
40
- description="Built during Robust Speech Event",
41
  layout="horizontal",
42
  theme="huggingface",
43
  ).launch(enable_queue=True, cache_examples=True)
 
17
  )
18
  sampling_rate = feature_extractor.sampling_rate
19
 
20
+ asr = pipeline("automatic-speech-recognition", model="anuragshas/wav2vec2-xls-r-1b-hi-with-lm")
21
+
22
+
23
+
24
+ model = AutoModelForSeq2SeqLM.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
25
+ tokenizer = AutoTokenizer.from_pretrained('hackathon-pln-es/t5-small-spanish-nahuatl')
26
 
27
 
28
  def predict_and_ctc_lm_decode(input_file):
29
  speech = load_and_fix_data(input_file, sampling_rate)
30
  transcribed_text = asr(speech, chunk_length_s=5, stride_length_s=1)
31
+ transcribed_text = transcribed_text["text"]
32
+ input_ids = tokenizer('translate Spanish to Nahuatl: ' + transcribed_text, return_tensors='pt').input_ids
33
+ outputs = model.generate(input_ids, max_length=512)
34
+ outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
35
+ return outputs
36
 
37
 
38
  gr.Interface(
 
42
  ],
43
  outputs=[gr.outputs.Textbox()],
44
  examples=[["example1.wav"]],
45
+ title="Spanish-Audio-Transcriptions-to-Nahuatl-Translation",
46
+ article="<p><center><img src='........e'></center></p>",
 
47
  layout="horizontal",
48
  theme="huggingface",
49
  ).launch(enable_queue=True, cache_examples=True)