asahi417 commited on
Commit
e328088
1 Parent(s): 9f1456e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -38,10 +38,10 @@ def transcribe(inputs, prompt):
38
  if inputs is None:
39
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
40
  generate_kwargs = {"language": "japanese", "task": "transcribe"}
41
- if prompt:
42
- generate_kwargs['prompt_ids'] = pipe.tokenizer.get_prompt_ids(prompt, return_tensors='pt').to(device)
43
- return pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs=generate_kwargs)["text"]
44
-
45
 
46
  def _return_yt_html_embed(yt_url):
47
  video_id = yt_url.split("?v=")[-1]
@@ -83,10 +83,10 @@ def yt_transcribe(yt_url, prompt, max_filesize=75.0):
83
  inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
84
  inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
85
  generate_kwargs = {"language": "japanese", "task": "transcribe"}
86
- if prompt:
87
- generate_kwargs['prompt_ids'] = pipe.tokenizer.get_prompt_ids(prompt, return_tensors='pt').to(device)
88
- text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs=generate_kwargs)["text"]
89
- return html_embed_str, text
90
 
91
 
92
  demo = gr.Blocks()
 
38
  if inputs is None:
39
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
40
  generate_kwargs = {"language": "japanese", "task": "transcribe"}
41
+ prompt = "。" if not prompt else prompt
42
+ generate_kwargs['prompt_ids'] = pipe.tokenizer.get_prompt_ids(prompt, return_tensors='pt').to(device)
43
+ result = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs=generate_kwargs)["text"]
44
+ return result['text'][1 + len(prompt) + 1:]
45
 
46
  def _return_yt_html_embed(yt_url):
47
  video_id = yt_url.split("?v=")[-1]
 
83
  inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
84
  inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
85
  generate_kwargs = {"language": "japanese", "task": "transcribe"}
86
+ prompt = "。" if not prompt else prompt
87
+ generate_kwargs['prompt_ids'] = pipe.tokenizer.get_prompt_ids(prompt, return_tensors='pt').to(device)
88
+ result = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs=generate_kwargs)["text"]
89
+ return html_embed_str, result['text'][1 + len(prompt) + 1:]
90
 
91
 
92
  demo = gr.Blocks()