maercaestro
commited on
Commit
·
f7813f0
1
Parent(s):
5947582
Upload 3 files
Browse files- convert.py +23 -0
- train.csv +0 -0
- works.txt +0 -0
convert.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
|
3 |
+
# Replace 'input.txt' with the path to your input text file
|
4 |
+
input_file = 'works.txt'
|
5 |
+
|
6 |
+
# Replace 'output.csv' with the desired output CSV file path
|
7 |
+
output_file = 'train.csv'
|
8 |
+
|
9 |
+
# Read the text file and split it into paragraphs
|
10 |
+
with open(input_file, 'r', encoding='utf-8') as file:
|
11 |
+
paragraphs = file.read().split('\n\n') # Adjust the split pattern based on your paragraph format
|
12 |
+
|
13 |
+
# Create a CSV writer and write the paragraphs into the CSV file
|
14 |
+
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
|
15 |
+
csv_writer = csv.writer(csvfile)
|
16 |
+
|
17 |
+
# Use a loop to write prompt and continuation in separate columns
|
18 |
+
for i in range(len(paragraphs)):
|
19 |
+
prompt = ' '.join(paragraphs[i:i + 2]) # Combine two paragraphs for the prompt
|
20 |
+
continuation = ' '.join(paragraphs[i + 2:i + 7]) # Combine five paragraphs for the continuation
|
21 |
+
|
22 |
+
# Write the prompt and continuation in separate columns
|
23 |
+
csv_writer.writerow([prompt.strip(), continuation.strip()])
|
train.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
works.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|