Download preview.py from leafstudiosDot/incotel-simchat-dataset: direct link, hf CLI and curl.
- Browser
- Download file 930 Bytes
-
https://huggingface.co/datasets/leafstudiosDot/incotel-simchat-dataset/resolve/main/preview.py
- Command line
-
hf download hf://datasets/leafstudiosDot/incotel-simchat-dataset/preview.py
-
curl -L -o preview.py https://huggingface.co/datasets/leafstudiosDot/incotel-simchat-dataset/resolve/main/preview.py
930 Bytes
| import json | |
| input_file = "./dialogues.txt" | |
| output_file = "./dialogues.jsonl" | |
| with open(input_file, "r", encoding="utf-8") as f_in, \ | |
| open(output_file, "w", encoding="utf-8") as f_out: | |
| lines = f_in.readlines() | |
| i = 0 | |
| while i < len(lines): | |
| line = lines[i].strip() | |
| if line.startswith("C:"): | |
| prompt = line[2:].strip() | |
| # Look ahead for the next S: line | |
| j = i + 1 | |
| while j < len(lines) and not lines[j].strip().startswith("S:"): | |
| j += 1 | |
| if j < len(lines): | |
| response = lines[j].strip()[2:].strip() | |
| json_obj = {"prompt": prompt, "response": response} | |
| f_out.write(json.dumps(json_obj, ensure_ascii=False) + "\n") | |
| i = j + 1 | |
| else: | |
| i += 1 | |
| else: | |
| i += 1 | |
| print(f"Converted {input_file} → {output_file} successfully!") | |