gvlassis commited on
Commit
e7e1253
1 Parent(s): 70565f3

Fixed main.py

Browse files
Files changed (1) hide show
  1. src/main.py +24 -15
src/main.py CHANGED
@@ -1,22 +1,31 @@
 
1
  import datasets
2
- import glob
3
 
4
- # List all .txt files in the current directory
5
- txt_files = glob.glob("*.txt")
 
 
6
 
7
- print(txt_files)
8
-
9
- # Read each file and store its content in a list
10
  texts = []
11
- for file_path in txt_files:
12
- with open(file_path, 'r') as file:
13
- texts.append(file.read())
 
 
14
 
15
- # Create a Hugging Face dataset from the list of texts
16
  dataset = datasets.Dataset.from_dict({"text": texts})
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- dataset_splits = datasets.DatasetDict({
19
- 'train': train_split,
20
- 'validation': validation_split,
21
- 'test': test_split
22
- })
 
1
+ import os
2
  import datasets
 
3
 
4
+ script_path = os.path.abspath(__file__)
5
+ src_path = os.path.dirname(script_path)
6
+ root_path = os.path.dirname(src_path)
7
+ res_path = root_path+"/res"
8
 
 
 
 
9
  texts = []
10
+ for name in os.listdir(res_path):
11
+ if name.endswith(".txt"):
12
+ with open(res_path+"/"+name, "r") as file:
13
+ text = file.read()
14
+ texts.append(text)
15
 
 
16
  dataset = datasets.Dataset.from_dict({"text": texts})
17
+ dataset = dataset.train_test_split(train_size=None, test_size=4, shuffle=False)
18
+
19
+ train_val_dataset = dataset["train"]
20
+ train_val_dataset = train_val_dataset.train_test_split(train_size=None, test_size=2, shuffle=False)
21
+
22
+ train_dataset = train_val_dataset["train"]
23
+ val_dataset = train_val_dataset["test"]
24
+ test_dataset = dataset["test"]
25
+ dataset = datasets.DatasetDict({
26
+ "train": train_dataset,
27
+ "val": val_dataset,
28
+ "test": test_dataset
29
+ })
30
 
31
+ dataset.push_to_hub("shakespearefirstfolio")