fixing script
Browse filesThis view is limited to 50 files because it contains too many changes. Β
See raw diff
- .DS_Store +0 -0
- .gitignore +2 -1
- scripts/create-jsonl.py β create-jsonl.py +0 -0
- create-tar-file.py +38 -0
- {images β data/images}/1.png +0 -0
- {images β data/images}/10.png +0 -0
- {images β data/images}/11.png +0 -0
- {images β data/images}/12.png +0 -0
- {images β data/images}/13.png +0 -0
- {images β data/images}/14.png +0 -0
- {images β data/images}/15.png +0 -0
- {images β data/images}/16.png +0 -0
- {images β data/images}/17.png +0 -0
- {images β data/images}/18.png +0 -0
- {images β data/images}/19.png +0 -0
- {images β data/images}/2.png +0 -0
- {images β data/images}/20.png +0 -0
- {images β data/images}/21.png +0 -0
- {images β data/images}/22.png +0 -0
- {images β data/images}/23.png +0 -0
- {images β data/images}/24.png +0 -0
- {images β data/images}/25.png +0 -0
- {images β data/images}/3.png +0 -0
- {images β data/images}/4.png +0 -0
- {images β data/images}/5.png +0 -0
- {images β data/images}/6.png +0 -0
- {images β data/images}/7.png +0 -0
- {images β data/images}/8.png +0 -0
- {images β data/images}/9.png +0 -0
- {texts β data/texts}/1.txt +0 -0
- {texts β data/texts}/10.txt +0 -0
- {texts β data/texts}/11.txt +0 -0
- {texts β data/texts}/12.txt +0 -0
- {texts β data/texts}/13.txt +0 -0
- {texts β data/texts}/14.txt +0 -0
- {texts β data/texts}/15.txt +0 -0
- {texts β data/texts}/16.txt +0 -0
- {texts β data/texts}/17.txt +0 -0
- {texts β data/texts}/18.txt +0 -0
- {texts β data/texts}/19.txt +0 -0
- {texts β data/texts}/2.txt +0 -0
- {texts β data/texts}/20.txt +0 -0
- {texts β data/texts}/21.txt +0 -0
- {texts β data/texts}/22.txt +0 -0
- {texts β data/texts}/23.txt +0 -0
- {texts β data/texts}/24.txt +0 -0
- {texts β data/texts}/25.txt +0 -0
- {texts β data/texts}/3.txt +0 -0
- {texts β data/texts}/4.txt +0 -0
- {texts β data/texts}/5.txt +0 -0
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
.gitignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
__pycache__
|
| 2 |
-
other
|
|
|
|
|
|
| 1 |
__pycache__
|
| 2 |
+
other
|
| 3 |
+
temp
|
scripts/create-jsonl.py β create-jsonl.py
RENAMED
|
File without changes
|
create-tar-file.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tarfile
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
|
| 5 |
+
IMAGE_EXTENSION = '.png'
|
| 6 |
+
|
| 7 |
+
# this script create a 'temp' folder and rename all images to its description, then add the folder to a tar file
|
| 8 |
+
if __name__ == "__main__":
|
| 9 |
+
|
| 10 |
+
# remove the temp folder if it exists
|
| 11 |
+
if os.path.exists('./temp'):
|
| 12 |
+
for filename in os.listdir('./temp'): # empty the folder
|
| 13 |
+
os.remove('./temp/' + filename)
|
| 14 |
+
os.rmdir('./temp') # remove the folder
|
| 15 |
+
|
| 16 |
+
# create the folder again
|
| 17 |
+
os.makedirs('./temp')
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# copy all images to the temp folder
|
| 21 |
+
for filename in os.listdir('./data/images'):
|
| 22 |
+
# get the matching text file on the 'texts' folder, if not found, skip
|
| 23 |
+
text_filename = filename[:-len(IMAGE_EXTENSION)] + '.txt'
|
| 24 |
+
if not os.path.exists('./data/texts/' + text_filename):
|
| 25 |
+
continue
|
| 26 |
+
|
| 27 |
+
# read the text file
|
| 28 |
+
with open('./data/texts/' + text_filename, 'r') as f:
|
| 29 |
+
description = f.read()
|
| 30 |
+
|
| 31 |
+
# copy the images to the temp folder, renaming it to the description replacing spaces with underscores
|
| 32 |
+
shutil.copyfile('./data/images/' + filename, './temp/' + description.replace(' ', '_') + IMAGE_EXTENSION)
|
| 33 |
+
|
| 34 |
+
# create a tar file with only the temp folder images
|
| 35 |
+
with tarfile.open( "./images.tar.gz", "w:gz") as tar:
|
| 36 |
+
for filename in os.listdir('./temp'):
|
| 37 |
+
tar.add('./temp/' + filename, arcname=filename)
|
| 38 |
+
|
{images β data/images}/1.png
RENAMED
|
File without changes
|
{images β data/images}/10.png
RENAMED
|
File without changes
|
{images β data/images}/11.png
RENAMED
|
File without changes
|
{images β data/images}/12.png
RENAMED
|
File without changes
|
{images β data/images}/13.png
RENAMED
|
File without changes
|
{images β data/images}/14.png
RENAMED
|
File without changes
|
{images β data/images}/15.png
RENAMED
|
File without changes
|
{images β data/images}/16.png
RENAMED
|
File without changes
|
{images β data/images}/17.png
RENAMED
|
File without changes
|
{images β data/images}/18.png
RENAMED
|
File without changes
|
{images β data/images}/19.png
RENAMED
|
File without changes
|
{images β data/images}/2.png
RENAMED
|
File without changes
|
{images β data/images}/20.png
RENAMED
|
File without changes
|
{images β data/images}/21.png
RENAMED
|
File without changes
|
{images β data/images}/22.png
RENAMED
|
File without changes
|
{images β data/images}/23.png
RENAMED
|
File without changes
|
{images β data/images}/24.png
RENAMED
|
File without changes
|
{images β data/images}/25.png
RENAMED
|
File without changes
|
{images β data/images}/3.png
RENAMED
|
File without changes
|
{images β data/images}/4.png
RENAMED
|
File without changes
|
{images β data/images}/5.png
RENAMED
|
File without changes
|
{images β data/images}/6.png
RENAMED
|
File without changes
|
{images β data/images}/7.png
RENAMED
|
File without changes
|
{images β data/images}/8.png
RENAMED
|
File without changes
|
{images β data/images}/9.png
RENAMED
|
File without changes
|
{texts β data/texts}/1.txt
RENAMED
|
File without changes
|
{texts β data/texts}/10.txt
RENAMED
|
File without changes
|
{texts β data/texts}/11.txt
RENAMED
|
File without changes
|
{texts β data/texts}/12.txt
RENAMED
|
File without changes
|
{texts β data/texts}/13.txt
RENAMED
|
File without changes
|
{texts β data/texts}/14.txt
RENAMED
|
File without changes
|
{texts β data/texts}/15.txt
RENAMED
|
File without changes
|
{texts β data/texts}/16.txt
RENAMED
|
File without changes
|
{texts β data/texts}/17.txt
RENAMED
|
File without changes
|
{texts β data/texts}/18.txt
RENAMED
|
File without changes
|
{texts β data/texts}/19.txt
RENAMED
|
File without changes
|
{texts β data/texts}/2.txt
RENAMED
|
File without changes
|
{texts β data/texts}/20.txt
RENAMED
|
File without changes
|
{texts β data/texts}/21.txt
RENAMED
|
File without changes
|
{texts β data/texts}/22.txt
RENAMED
|
File without changes
|
{texts β data/texts}/23.txt
RENAMED
|
File without changes
|
{texts β data/texts}/24.txt
RENAMED
|
File without changes
|
{texts β data/texts}/25.txt
RENAMED
|
File without changes
|
{texts β data/texts}/3.txt
RENAMED
|
File without changes
|
{texts β data/texts}/4.txt
RENAMED
|
File without changes
|
{texts β data/texts}/5.txt
RENAMED
|
File without changes
|