Spaces:
Sleeping
Sleeping
File size: 2,500 Bytes
3cdeba6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import gradio as gr
from pyscript import Transcriptor
import os
transcriptor = Transcriptor(model_size="small")
demo_dir = "audio-test"
demo_files = {
"Short Sample": os.path.join(demo_dir, "harvard.wav"),
"Noise Sample": os.path.join(demo_dir, "jackhammer.wav"),
"Meeting Sample 1 person": os.path.join(demo_dir, "meeting-clip1.wav"),
"Meeting Sample 2 people": os.path.join(demo_dir, "meeting-clip2.wav"),
}
def process_audio(audio_path, enhancement):
if audio_path is None:
raise ValueError("Please provide an audio file.")
transcription = transcriptor.transcribe_audio(audio_path, enhanced=enhancement)
return str(transcription)
def create_download(text):
os.makedirs(".temp", exist_ok=True)
temp_file = ".temp/transcription.txt"
with open(temp_file, "w", encoding="utf-8") as f:
f.write(text)
return temp_file
interface = gr.Interface(
fn=process_audio,
inputs=[
gr.Audio(sources=["upload", "microphone"], type="filepath", label="Audio"),
gr.Radio(choices=[True, False], value=False, label="Audio Enhancement", info="Enable for noisy audio")
],
outputs=gr.Textbox(
label="Complete Transcription",
interactive=True,
info="You can edit the transcription here"
),
title="๐๏ธ Audio Transcription Tool",
description="""
โ ๏ธ **Performance Notice**: This application performs intensive computations that are optimized for GPU usage.
If running on CPU only, transcription may take significantly longer (5-10x slower). For the best experience,
using a system with GPU is recommended.
Upload an audio file or record directly to get a transcription.
""",
examples=[
[demo_files["Short Sample"], False],
[demo_files["Noise Sample"], True],
[demo_files["Meeting Sample 1 person"], False],
[demo_files["Meeting Sample 2 people"], False],
],
cache_examples=True,
cache_mode="eager",
allow_flagging="never"
)
with gr.Blocks() as demo:
interface.render()
with gr.Column():
download_button = gr.Button("๐ฅ Download Edited Transcription")
file_output = gr.File(label="Download Transcription")
textbox = interface.output_components[0]
download_button.click(fn=create_download, inputs=[textbox], outputs=[file_output])
if __name__ == "__main__":
demo.launch(share=False)
|