sas / app.py
noumanjavaid's picture
initial commit
ee32aa6 verified
# This Gradio app allows users to upload an audio file and get a transcription.
import gradio as gr
# Define the function to transcribe the audio file.
def transcribe_audio(audio_file):
# Check if the file exists and is not too large
if not os.path.exists(audio_file):
raise gr.Error(f"Error: File {audio_file} not found")
file_size = os.path.getsize(audio_file) / (1024 * 1024) # Convert to MB
print(f"Processing file: {audio_file} ({file_size:.2f} MB)")
try:
start_time = time.time()
with open(audio_file, "rb") as file:
# Simulate the transcription process
transcription = {
"text": "This is a simulated transcription of the uploaded audio file."
}
elapsed = time.time() - start_time
print(f"Transcription completed in {elapsed:.2f} seconds")
print("\nTranscribed text:")
print(transcription["text"])
return transcription["text"]
except Exception as e:
raise gr.Error(f"Error during transcription: {str(e)}")
# Create a Gradio interface that takes an audio file as input and returns the transcription as output.
with gr.Blocks() as demo:
audio_input = gr.Audio(label="Upload Audio File", type="filepath")
transcription_output = gr.Textbox(label="Transcribed Text")
transcribe_button = gr.Button("Transcribe")
# Attach the transcribe_audio function to the button click event.
transcribe_button.click(fn=transcribe_audio, inputs=audio_input, outputs=transcription_output)
# Launch the interface.
demo.launch(show_error=True)