Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. '''
  3. where .JPG.txt AI tag files are like
  4. Tags for IMG_3150.JPG (Tag - Probability)
  5. child - 0.9972
  6. fun - 0.9727
  7. little - 0.9688
  8. people - 0.9647
  9. cute - 0.9637
  10. et cetera
  11. '''
  12. import os, sys
  13. import glob
  14. import simplejson as json
  15. from os.path import expanduser
  16. directory = expanduser('~\\pictures\\clarifai\\')
  17. JSONdirectory = expanduser('~\\pictures\\clarifai\\JSON\\')
  18. thumbsdirectory = expanduser('~\\pictures\\clarifai\\thumbs\\')
  19. lines_list = []
  20. data={}
  21. finaldata=[]
  22. emptyHolder = {}
  23.  
  24. txts=glob.glob1(directory, "*.txt")
  25. with open(JSONdirectory+"data.JSON", 'w') as outfile:
  26. for txt in txts:
  27. lines_list = open(directory+txt).read().splitlines()[2:]
  28. data['Question']=emptyHolder
  29. data['img']={'filename':txt.replace('.JPG.txt', '.JPG')}
  30. data['thumb']={'filename':txt.replace('.JPG.txt', '.THUMB.JPEG')}
  31. data['Question']['content']={}
  32. for i in lines_list:
  33. data['Question']['content'][i.split(' - ')[0]]=i.split(' - ')[1]
  34. finaldata.append(data)
  35. json.dump({'Questions':finaldata}, outfile, sort_keys = True, indent = 4, ensure_ascii = False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement