import os, glob, json, time from huggingface_hub import HfApi, snapshot_download AUDIO_REPO = "Mat021007/law5008-lecture-audio" OUT_REPO = "Mat021007/law5008-lecture-transcripts" api = HfApi() api.create_repo(OUT_REPO, repo_type="dataset", private=True, exist_ok=True) # Download real audio (resolves Git-LFS to actual bytes; the volume mount may serve pointers) local = snapshot_download(AUDIO_REPO, repo_type="dataset", allow_patterns=["*.mp3"]) paths = sorted(glob.glob(os.path.join(local, "*.mp3"))) print("audio files:", [(os.path.basename(p), os.path.getsize(p)) for p in paths], flush=True) from faster_whisper import WhisperModel print("loading large-v3 ...", flush=True) model = WhisperModel("large-v3", device="cuda", compute_type="float16") PROMPT = ("LAW5008 Principles of Equity. Breach of confidence. Coco v AN Clark; " "O'Brien v Komesaroff; Ocular Sciences; Franklin v Giddins; Foster v Mountford; " "ABC v Lenah Game Meats; Australian Football League v The Age; Smith Kline; " "Castrol v EmTech; Giller v Procopets; AB v CD; Corrs Pavey; Gummow J; Kellam J; " "Megarry J; iniquity; equitable compensation; account of profits; Lord Cairns Act.") for path in paths: name = os.path.splitext(os.path.basename(path))[0] sz = os.path.getsize(path) if sz < 100_000: print(f"SKIP {name}: file too small ({sz} bytes) — likely a pointer", flush=True) continue t0 = time.time() print(f"transcribing {name} ({sz} bytes) ...", flush=True) segments, info = model.transcribe(path, language="en", initial_prompt=PROMPT, vad_filter=False, condition_on_previous_text=False) print(f" detected duration: {getattr(info, 'duration', '?')}s", flush=True) lines, seg_json = [], [] for s in segments: mm, ss = int(s.start // 60), int(s.start % 60) lines.append(f"[{mm:02d}:{ss:02d}] {s.text.strip()}") seg_json.append({"start": round(s.start, 2), "end": round(s.end, 2), "text": s.text}) open(f"/tmp/{name}.txt", "w").write("\n".join(lines)) json.dump(seg_json, open(f"/tmp/{name}.json", "w")) api.upload_file(path_or_fileobj=f"/tmp/{name}.txt", path_in_repo=f"{name}.txt", repo_id=OUT_REPO, repo_type="dataset") api.upload_file(path_or_fileobj=f"/tmp/{name}.json", path_in_repo=f"{name}.json", repo_id=OUT_REPO, repo_type="dataset") print(f"DONE {name} in {time.time()-t0:.0f}s, {len(lines)} segments", flush=True) print("ALL DONE", flush=True)