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()