Spaces:
Build error
Build error
File size: 1,228 Bytes
36bec1c a66dfeb ec72da9 2bacaf7 a66dfeb ec72da9 2bacaf7 a66dfeb ec72da9 a66dfeb ec72da9 a66dfeb 2bacaf7 a66dfeb |
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 |
import gradio as gr
import os
import whisper
# Load the Whisper model
model = whisper.load_model("base")
# Function to process the uploaded audio file and perform transcription
def process_audio(upload):
# Save the uploaded audio file
file_path = "uploaded_audio.mp3"
upload.save(file_path)
# Load the audio file and perform preprocessing
audio = whisper.load_audio(file_path)
audio = whisper.pad_or_trim(audio)
mel = whisper.log_mel_spectrogram(audio).to(model.device)
# Detect the spoken language
_, probs = model.detect_language(mel)
detected_language = max(probs, key=probs.get)
# Perform transcription using Whisper ASR
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)
transcription = result.text
return transcription
# Create an audio input component for uploading the audio file
audio_input = gr.inputs.Audio(label="Upload Audio", type="file")
# Create a text output component for displaying the transcription
text_output = gr.outputs.Textbox(label="Transcription")
# Create a Gradio interface
gr.Interface(fn=process_audio, inputs=audio_input, outputs=text_output, title="Audio Transcription").launch()
|