danbrown commited on
Commit
67de853
β€’
1 Parent(s): 2199324

fixing script

Browse files
This view is limited to 50 files because it contains too many changes. Β  See raw diff
Files changed (50) hide show
  1. .DS_Store +0 -0
  2. .gitignore +2 -1
  3. scripts/create-jsonl.py β†’ create-jsonl.py +0 -0
  4. create-tar-file.py +38 -0
  5. {images β†’ data/images}/1.png +0 -0
  6. {images β†’ data/images}/10.png +0 -0
  7. {images β†’ data/images}/11.png +0 -0
  8. {images β†’ data/images}/12.png +0 -0
  9. {images β†’ data/images}/13.png +0 -0
  10. {images β†’ data/images}/14.png +0 -0
  11. {images β†’ data/images}/15.png +0 -0
  12. {images β†’ data/images}/16.png +0 -0
  13. {images β†’ data/images}/17.png +0 -0
  14. {images β†’ data/images}/18.png +0 -0
  15. {images β†’ data/images}/19.png +0 -0
  16. {images β†’ data/images}/2.png +0 -0
  17. {images β†’ data/images}/20.png +0 -0
  18. {images β†’ data/images}/21.png +0 -0
  19. {images β†’ data/images}/22.png +0 -0
  20. {images β†’ data/images}/23.png +0 -0
  21. {images β†’ data/images}/24.png +0 -0
  22. {images β†’ data/images}/25.png +0 -0
  23. {images β†’ data/images}/3.png +0 -0
  24. {images β†’ data/images}/4.png +0 -0
  25. {images β†’ data/images}/5.png +0 -0
  26. {images β†’ data/images}/6.png +0 -0
  27. {images β†’ data/images}/7.png +0 -0
  28. {images β†’ data/images}/8.png +0 -0
  29. {images β†’ data/images}/9.png +0 -0
  30. {texts β†’ data/texts}/1.txt +0 -0
  31. {texts β†’ data/texts}/10.txt +0 -0
  32. {texts β†’ data/texts}/11.txt +0 -0
  33. {texts β†’ data/texts}/12.txt +0 -0
  34. {texts β†’ data/texts}/13.txt +0 -0
  35. {texts β†’ data/texts}/14.txt +0 -0
  36. {texts β†’ data/texts}/15.txt +0 -0
  37. {texts β†’ data/texts}/16.txt +0 -0
  38. {texts β†’ data/texts}/17.txt +0 -0
  39. {texts β†’ data/texts}/18.txt +0 -0
  40. {texts β†’ data/texts}/19.txt +0 -0
  41. {texts β†’ data/texts}/2.txt +0 -0
  42. {texts β†’ data/texts}/20.txt +0 -0
  43. {texts β†’ data/texts}/21.txt +0 -0
  44. {texts β†’ data/texts}/22.txt +0 -0
  45. {texts β†’ data/texts}/23.txt +0 -0
  46. {texts β†’ data/texts}/24.txt +0 -0
  47. {texts β†’ data/texts}/25.txt +0 -0
  48. {texts β†’ data/texts}/3.txt +0 -0
  49. {texts β†’ data/texts}/4.txt +0 -0
  50. {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