import torch import gradio as gr import whisper import os # 確保 Whisper 模塊被正確加載 print("Whisper module contents:", dir(whisper)) # 加載 Whisper 模型 model = whisper.load_model("large-v2", device="cuda" if torch.cuda.is_available() else "cpu") def transcribe(audio_file): audio_path = audio_file result = model.transcribe(audio_path) text = result["text"] base_name = os.path.splitext(os.path.basename(audio_path))[0] transcript_file_path = f"txt/{base_name}_transcript.txt" os.makedirs("txt", exist_ok=True) with open(transcript_file_path, "w") as file: file.write(text) return text, transcript_file_path TITLE = """