Download src/generate_hf_data.py from sattycodes/my-tts-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/datasets/sattycodes/my-tts-dataset/resolve/main/src/generate_hf_data.py
- Command line
-
hf download hf://datasets/sattycodes/my-tts-dataset/src/generate_hf_data.py
-
curl -L -o generate_hf_data.py https://huggingface.co/datasets/sattycodes/my-tts-dataset/resolve/main/src/generate_hf_data.py
1.06 kB
| import os | |
| from datasets import load_dataset | |
| BASE_DIR = "/home/cloud/StyleTTS2-fine-tuning" | |
| OUTPUT_DIR = os.path.join(BASE_DIR, "Data") | |
| OUTPUT_FILE = os.path.join(OUTPUT_DIR, "OOD.txt") | |
| HF_DATASET_ID = "agentlans/high-quality-english-sentences" | |
| os.makedirs(OUTPUT_DIR, exist_ok=True) | |
| def download_and_save_text(): | |
| print(f"Downloading first 10,000 lines from {HF_DATASET_ID}...") | |
| ds = load_dataset(HF_DATASET_ID, split="train[8000:18000]") | |
| text_column = "text" | |
| if "sentence" in ds.column_names: | |
| text_column = "sentence" | |
| elif "content" in ds.column_names: | |
| text_column = "content" | |
| print(f"Extracting to {OUTPUT_FILE}...") | |
| with open(OUTPUT_FILE, "w", encoding="utf-8") as f: | |
| for row in ds: | |
| line = row[text_column] | |
| if line and isinstance(line, str): | |
| clean_line = line.strip() | |
| if clean_line: | |
| f.write(clean_line + "\n") | |
| print(f"Saved {len(ds)} lines to {OUTPUT_FILE}") | |
| if __name__ == "__main__": | |
| download_and_save_text() |