versae commited on
Commit
c1541fb
·
verified ·
1 Parent(s): f5e579f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -26
app.py CHANGED
@@ -17,31 +17,19 @@ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
17
  print(f"Using device: {device}")
18
 
19
  @spaces.GPU(duration=120)
20
- def transcribe(file): #microphone, file_upload):
21
- pipe = pipeline(
22
  task="automatic-speech-recognition",
23
  model=MODEL_NAME,
24
  chunk_length_s=30,
25
  device=device,
26
  token=auth_token,
27
  )
28
- pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
29
- #pipe.to(device)
30
- warn_output = ""
31
- # if (microphone is not None) and (file_upload is not None):
32
- # warn_output = (
33
- # "WARNING: You've uploaded an audio file and used the microphone. "
34
- # "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
35
- # )
36
-
37
- # elif (microphone is None) and (file_upload is None):
38
- # return "ERROR: You have to either use the microphone or upload an audio file"
39
-
40
- # file = microphone if microphone is not None else file_upload
41
 
 
42
  text = pipe(file)["text"]
43
-
44
- return warn_output + text
45
 
46
 
47
  def _return_yt_html_embed(yt_url):
@@ -54,15 +42,6 @@ def _return_yt_html_embed(yt_url):
54
 
55
 
56
  def yt_transcribe(yt_url):
57
- pipe = pipeline(
58
- task="automatic-speech-recognition",
59
- model=MODEL_NAME,
60
- chunk_length_s=30,
61
- device=device,
62
- token=auth_token,
63
- )
64
- pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
65
-
66
  yt = pt.YouTube(yt_url)
67
  html_embed_str = _return_yt_html_embed(yt_url)
68
  stream = yt.streams.filter(only_audio=True)[0]
 
17
  print(f"Using device: {device}")
18
 
19
  @spaces.GPU(duration=120)
20
+ def pipe(file):
21
+ asr
22
  task="automatic-speech-recognition",
23
  model=MODEL_NAME,
24
  chunk_length_s=30,
25
  device=device,
26
  token=auth_token,
27
  )
28
+ asr.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ def transcribe(file):
31
  text = pipe(file)["text"]
32
+ return text
 
33
 
34
 
35
  def _return_yt_html_embed(yt_url):
 
42
 
43
 
44
  def yt_transcribe(yt_url):
 
 
 
 
 
 
 
 
 
45
  yt = pt.YouTube(yt_url)
46
  html_embed_str = _return_yt_html_embed(yt_url)
47
  stream = yt.streams.filter(only_audio=True)[0]