Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- '''
- where .JPG.txt AI tag files are like
- Tags for IMG_3150.JPG (Tag - Probability)
- child - 0.9972
- fun - 0.9727
- little - 0.9688
- people - 0.9647
- cute - 0.9637
- et cetera
- '''
- import os, sys
- import glob
- import simplejson as json
- from os.path import expanduser
- directory = expanduser('~\\pictures\\clarifai\\')
- JSONdirectory = expanduser('~\\pictures\\clarifai\\JSON\\')
- thumbsdirectory = expanduser('~\\pictures\\clarifai\\thumbs\\')
- lines_list = []
- data={}
- finaldata=[]
- emptyHolder = {}
- txts=glob.glob1(directory, "*.txt")
- with open(JSONdirectory+"data.JSON", 'w') as outfile:
- for txt in txts:
- lines_list = open(directory+txt).read().splitlines()[2:]
- data['Question']=emptyHolder
- data['img']={'filename':txt.replace('.JPG.txt', '.JPG')}
- data['thumb']={'filename':txt.replace('.JPG.txt', '.THUMB.JPEG')}
- data['Question']['content']={}
- for i in lines_list:
- data['Question']['content'][i.split(' - ')[0]]=i.split(' - ')[1]
- finaldata.append(data)
- json.dump({'Questions':finaldata}, outfile, sort_keys = True, indent = 4, ensure_ascii = False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement