Spaces:
Runtime error
Runtime error
File size: 1,464 Bytes
dad2a9b 48103d0 dad2a9b bdc7600 48103d0 dad4b00 bdc7600 48103d0 d09d492 48103d0 d09d492 48103d0 dad4b00 48103d0 bdc7600 48103d0 d09d492 48103d0 bdc7600 48103d0 bdc7600 48103d0 dad4b00 d09d492 48103d0 |
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 |
import gradio as gr
import whisper
import os
model = whisper.load_model("base")
def transcribe_audio(audio_file):
# Check if file is uploaded
if audio_file is None:
return "Error: Please upload an audio file.", None
# Get the file path - in newer Gradio versions, audio_file might be a string path directly
file_path = audio_file if isinstance(audio_file, str) else audio_file.name
# Check file size (25MB limit)
if os.path.getsize(file_path) > 25 * 1024 * 1024:
return "Error: File size exceeds 25MB limit.", None
try:
result = model.transcribe(file_path)
output_filename = os.path.splitext(os.path.basename(file_path))[0] + ".txt"
with open(output_filename, "w") as text_file:
text_file.write(result["text"])
return result["text"], output_filename
except Exception as e:
return f"Error during transcription: {str(e)}", None
iface = gr.Interface(
fn=transcribe_audio,
inputs=gr.File(label="Upload Audio File (Max 25MB)", file_types=["audio"]),
outputs=[
gr.Textbox(label="Transcription"),
gr.File(label="Download Transcript")
],
title="Free Transcript Maker",
description="Upload an audio file (WAV, MP3, etc.) up to 25MB to get its transcription. The transcript will be displayed and available for download. Please use responsibly."
)
if __name__ == "__main__":
iface.launch() |