File size: 1,054 Bytes
dad2a9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import whisper
import os

# Load the Whisper model
model = whisper.load_model("base")

def transcribe_audio(audio_file):
    # Transcribe the audio
    result = model.transcribe(audio_file.name)
    
    # Get the base name of the file (without extension) for the output file
    output_filename = os.path.splitext(os.path.basename(audio_file.name))[0] + ".txt"
    
    # Save the transcript to a text file with the same name as the input file
    with open(output_filename, "w") as text_file:
        text_file.write(result["text"])
    
    return result["text"], output_filename

# Create Gradio interface
iface = gr.Interface(
    fn=transcribe_audio,
    inputs=gr.File(label="Upload Audio File"),
    outputs=[
        gr.Textbox(label="Transcription"),
        gr.File(label="Download Transcript")
    ],
    title="Audio Transcription Tool",
    description="Upload an audio file (WAV, MP3, etc.) to get its transcription. The transcript will be displayed and available for download."
)

# Launch the interface
iface.launch()