podcast-sponsor-remove

Attempt at identify sponsored segments in audio transcripts and removing them.
Log | Files | Refs

commit 950c077309aff3036bdd2ab618983089faef41de
parent 2db3b781c15b45bc3f0771ad2ef30d6d88352adb
Author: vin <git@vineetk.net>
Date:   Sat, 19 Jul 2025 12:36:46 -0400

save output in data/, not where podcasts are

Diffstat:
Mmain.py | 18++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/main.py b/main.py @@ -14,6 +14,8 @@ client = openai.OpenAI( ) MODEL = "deepseek/deepseek-chat-v3-0324" +#MODEL = "deepseek/deepseek-chat-v3-0324:free" + SYSTEM_PROMPT_TEMPLATE = """ You are an expert podcast content analyzer. Your task is to identify and extract pre-recorded dynamic advertising segments from podcast transcripts. These ads typically have a distinct tone shift, often using more direct, persuasive language, and frequently include calls to action, product mentions, or specific brand names. @@ -258,25 +260,33 @@ def process_file(input_file: str, output_file: str): if ad_timestamps_str.startswith("[") or "no output" in ad_timestamps_str.lower() or "no ad" in ad_timestamps_str.lower(): ad_timestamps_str = "" + + promptid = os.path.dirname(input_file).split('/')[-1] + "_" + promptid += os.path.splitext(os.path.basename(output_file))[0].replace(" ", "") + f"_chunk{i}" + # Split by newlines in case the model returns multiple segments found_timestamps = [ts.strip() for ts in ad_timestamps_str.split('\n') if ts.strip()] - all_ad_timestamps.append({"id": f"{"".join(input_file.split(".")[:-1])}_chunk{i}", f"text": "Instruction: Identify the timestamp range of the pre-recorded ad in the following transcript. Output only the HH:MM:SS.mmm-HH:MM:SS.mmm range.\n\nTranscript:\n" + user_prompt, "target": "\n".join(found_timestamps)}) + all_ad_timestamps.append({"id": promptid, f"text": "Instruction: Identify the timestamp range of the pre-recorded ad in the following transcript. Output only the HH:MM:SS.mmm-HH:MM:SS.mmm range.\n\nTranscript:\n" + user_prompt, "target": "\n".join(found_timestamps)}) with open(output_file, "w") as f: for s in all_ad_timestamps: f.write(json.dumps(s) + "\n") def main(): - os.makedirs("data/") + os.makedirs("data/", exist_ok=True) paths = sys.argv[1:] for p in paths: - out = "data/" + os.path.splitext(os.path.basename(p))[0] + ".jsonl" + out = "data/" + out += os.path.dirname(p).split('/')[-1] + "_" + out += os.path.splitext(os.path.basename(p))[0] + ".jsonl" if os.path.isfile(out): paths.remove(p) print(paths) for p in tqdm(paths): - out = "data/" + os.path.splitext(os.path.basename(p))[0] + ".jsonl" + out = "data/" + out += os.path.dirname(p).split('/')[-1] + "_" + out += os.path.splitext(os.path.basename(p))[0] + ".jsonl" process_file(p, out) if __name__ == "__main__":