|
import hashlib |
|
import json |
|
import tqdm |
|
import os |
|
import pandas as pd |
|
|
|
|
|
|
|
PATH = "/work/fast_data_yinghao/SDD" |
|
existed_uuid_list = set() |
|
|
|
pd_list = pd.read_csv(f"{PATH}/song_describer.csv") |
|
caption_dict = pd_list.set_index('caption_id')['caption'].to_dict() |
|
path_dict = pd_list.set_index('caption_id')['path'].to_dict() |
|
for split in [ "test"]: |
|
data_samples = [] |
|
|
|
for key in tqdm.tqdm(caption_dict.keys()): |
|
audio_path = os.path.join(f"{PATH}", f"audio/{path_dict[key]}") |
|
if not audio_path.endswith('.wav'): |
|
audio_path = audio_path.split(".")[0] + ".wav" |
|
data_sample = { |
|
"instruction": "Please provide the caption of the given audio.", |
|
"input": f"<|SOA|>{path_dict[key]}<|EOA|>", |
|
"output": caption_dict[key], |
|
"uuid": "", |
|
"audioid": f"{audio_path}", |
|
"split": [split], |
|
"task_type": {"major": ["global_MIR"], "minor": ["music_captioning"]}, |
|
"domain": "music", |
|
"source": "Youtubet", |
|
"other": {} |
|
} |
|
|
|
uuid_string = f"{data_sample['instruction']}#{data_sample['input']}#{data_sample['output']}" |
|
unique_id = hashlib.md5(uuid_string.encode()).hexdigest()[:16] |
|
if unique_id in existed_uuid_list: |
|
sha1_hash = hashlib.sha1(uuid_string.encode()).hexdigest()[:16] |
|
unique_id = hashlib.md5((unique_id + sha1_hash).encode()).hexdigest()[:16] |
|
existed_uuid_list.add(unique_id) |
|
data_sample["uuid"] = f"{unique_id}" |
|
|
|
|
|
data_samples.append(data_sample) |
|
|
|
|
|
|
|
|
|
output_file_path = f'{PATH}/sdd_{split}.jsonl' |
|
with open(output_file_path, 'w') as outfile: |
|
|
|
json.dump(data_samples, outfile) |
|
|
|
|
|
outfile.close() |
|
|