Spaces:
Runtime error
Runtime error
Commit
·
3175c21
1
Parent(s):
cc46c30
up
Browse files- run_demo_ct2.py +18 -16
run_demo_ct2.py
CHANGED
|
@@ -160,23 +160,24 @@ def infer(model, filename, with_timestamps, return_df=False):
|
|
| 160 |
return text
|
| 161 |
|
| 162 |
|
| 163 |
-
def transcribe(microphone, file_upload, with_timestamps, model_name=DEFAULT_MODEL_NAME):
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
-
elif (microphone is None) and (file_upload is None):
|
| 172 |
-
|
| 173 |
|
| 174 |
-
|
| 175 |
|
| 176 |
model = maybe_load_cached_pipeline(model_name)
|
| 177 |
-
# text = model.transcribe(
|
| 178 |
-
# text = infer(model,
|
| 179 |
-
text = infer(model,
|
| 180 |
|
| 181 |
logger.info(f'Transcription by `{model_name}`:\n{text.to_json(orient="index", force_ascii=False, indent=2)}\n')
|
| 182 |
|
|
@@ -237,8 +238,9 @@ with gr.Blocks() as demo:
|
|
| 237 |
"""
|
| 238 |
)
|
| 239 |
|
| 240 |
-
microphone_input = gr.Audio(sources="microphone", type="filepath", label="Record")
|
| 241 |
-
upload_input = gr.Audio(sources="upload", type="filepath", label="Upload File")
|
|
|
|
| 242 |
with_timestamps_input = gr.Checkbox(label="With timestamps?")
|
| 243 |
|
| 244 |
microphone_transcribe_btn = gr.Button("Transcribe Audio")
|
|
@@ -255,7 +257,7 @@ with gr.Blocks() as demo:
|
|
| 255 |
)
|
| 256 |
|
| 257 |
microphone_transcribe_btn.click(
|
| 258 |
-
transcribe, inputs=[
|
| 259 |
)
|
| 260 |
|
| 261 |
# with gr.Tab("Transcribe YouTube"):
|
|
|
|
| 160 |
return text
|
| 161 |
|
| 162 |
|
| 163 |
+
# def transcribe(microphone, file_upload, with_timestamps, model_name=DEFAULT_MODEL_NAME):
|
| 164 |
+
def transcribe(audio_file_path, with_timestamps, model_name=DEFAULT_MODEL_NAME):
|
| 165 |
+
# warn_output = ""
|
| 166 |
+
# if (microphone is not None) and (file_upload is not None):
|
| 167 |
+
# warn_output = (
|
| 168 |
+
# "WARNING: You've uploaded an audio file and used the microphone. "
|
| 169 |
+
# "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
| 170 |
+
# )
|
| 171 |
|
| 172 |
+
# elif (microphone is None) and (file_upload is None):
|
| 173 |
+
# return "ERROR: You have to either use the microphone or upload an audio file"
|
| 174 |
|
| 175 |
+
# audio_file_path = microphone if microphone is not None else file_upload
|
| 176 |
|
| 177 |
model = maybe_load_cached_pipeline(model_name)
|
| 178 |
+
# text = model.transcribe(audio_file_path, **GEN_KWARGS)["text"]
|
| 179 |
+
# text = infer(model, audio_file_path, with_timestamps)
|
| 180 |
+
text = infer(model, audio_file_path, with_timestamps, return_df=True)
|
| 181 |
|
| 182 |
logger.info(f'Transcription by `{model_name}`:\n{text.to_json(orient="index", force_ascii=False, indent=2)}\n')
|
| 183 |
|
|
|
|
| 238 |
"""
|
| 239 |
)
|
| 240 |
|
| 241 |
+
# microphone_input = gr.Audio(sources="microphone", type="filepath", label="Record")
|
| 242 |
+
# upload_input = gr.Audio(sources="upload", type="filepath", label="Upload File")
|
| 243 |
+
audio_file_path = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Record or upload file")
|
| 244 |
with_timestamps_input = gr.Checkbox(label="With timestamps?")
|
| 245 |
|
| 246 |
microphone_transcribe_btn = gr.Button("Transcribe Audio")
|
|
|
|
| 257 |
)
|
| 258 |
|
| 259 |
microphone_transcribe_btn.click(
|
| 260 |
+
transcribe, inputs=[audio_file_path, with_timestamps_input], outputs=text_output_df2
|
| 261 |
)
|
| 262 |
|
| 263 |
# with gr.Tab("Transcribe YouTube"):
|