jpdiazpardo commited on
Commit
5440420
1 Parent(s): 3972532

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -37,7 +37,7 @@ def format_timestamp(seconds: float, always_include_hours: bool = False, decimal
37
 
38
 
39
  def transcribe(file, task, return_timestamps):
40
- outputs = pipe(file, batch_size=BATCH_SIZE, return_timestamps=return_timestamps)
41
  text = outputs["text"]
42
  if return_timestamps:
43
  timestamps = outputs["chunks"]
@@ -49,10 +49,32 @@ def transcribe(file, task, return_timestamps):
49
  return text
50
 
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  file_transcribe = gr.Interface(
53
  fn=transcribe,
54
  inputs=[
55
- gr.inputs.Audio(source="upload", label="Audio file", type="filepath"),
 
56
  gr.inputs.Checkbox(default=False, label="Return timestamps"),
57
  ],
58
  outputs="text",
@@ -64,6 +86,8 @@ file_transcribe = gr.Interface(
64
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
65
  " of arbitrary length."
66
  ),
 
 
67
  allow_flagging="never",
68
  )
69
 
 
37
 
38
 
39
  def transcribe(file, task, return_timestamps):
40
+ outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=return_timestamps)
41
  text = outputs["text"]
42
  if return_timestamps:
43
  timestamps = outputs["chunks"]
 
49
  return text
50
 
51
 
52
+ demo = gr.Blocks()
53
+
54
+ mic_transcribe = gr.Interface(
55
+ fn=transcribe,
56
+ inputs=[
57
+ gr.inputs.Audio(source="microphone", type="filepath", optional=True),
58
+ gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
59
+ gr.inputs.Checkbox(default=False, label="Return timestamps"),
60
+ ],
61
+ outputs="text",
62
+ layout="horizontal",
63
+ theme="huggingface",
64
+ title="Whisper Demo: Transcribe Audio",
65
+ description=(
66
+ "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
67
+ f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
68
+ " of arbitrary length."
69
+ ),
70
+ allow_flagging="never",
71
+ )
72
+
73
  file_transcribe = gr.Interface(
74
  fn=transcribe,
75
  inputs=[
76
+ gr.inputs.Audio(source="upload", optional=True, label="Audio file", type="filepath"),
77
+ gr.inputs.Radio(["transcribe"], label="Task", default="transcribe"),
78
  gr.inputs.Checkbox(default=False, label="Return timestamps"),
79
  ],
80
  outputs="text",
 
86
  f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
87
  " of arbitrary length."
88
  ),
89
+
90
+ cache_examples=True,
91
  allow_flagging="never",
92
  )
93