image analysis running on the server "lev", sharing the basic same data. presently, the IA port is not exposed, but in interest of time, i am making a "pass-through" access to the IA api via a WB api call. (this is ultimately the model we want to use in production, so that wildbook can handle security and other issues, but as you will see, i have kind of done a very generic hack version of the same concept.) this consists of a small wb api "wrapper" call around the call you actually wish to be making of the IA data. perhaps examples would demonstrate best:
IA call: /api/annot/image/contributor/tag/json/?annot_uuid_list=[{"UUID":"8b595dc0-9c5a-4caf-9703-9f8ff017e824"}] becomes: http://lev.cs.rpi.edu:8080/ggr/ia?passthru=/api/annot/image/contributor/tag/json/&arg=annot_uuid_list%3D[{%22__UUID__%22:%228b595dc0-9c5a-4caf-9703-9f8ff017e824%22}]
IA call: /api/annot/age/months/json/?annot_uuid_list=[{"UUID":"8b595dc0-9c5a-4caf-9703-9f8ff017e824"}] becomes: http://lev.cs.rpi.edu:8080/ggr/ia?passthru=/api/annot/age/months/json/&arg=annot_uuid_list%3D[{%22__UUID__%22:%228b595dc0-9c5a-4caf-9703-9f8ff017e824%22}]
in other words, you pass two parameters, passthru and arg, which are just uri-encoded strings that represent the two sides of the "?" in the original call. (note that arg is optional.) the two examples above are "live", in the sense that you can click them and should get the json results as expected.
this should, technically, get you to any existing IA api call (provided i had jason p turn on all the right ones)... at least the ones that use GET. if you need any POST queries, let me know and i can pass those through as well.
In [18]:
import requests
import urllib
import GetPropertiesAPI as GP
from collections import OrderedDict
import importlib
importlib.reload(GP)
DOMAIN = 'http://lev.cs.rpi.edu:8080/ggr/ia'
In [ ]:
## /api/annot/image/contributor/tag/json/?annot_uuid_list=[{"__UUID__":"8b595dc0-9c5a-4caf-9703-9f8ff017e824"}]
param = urllib.parse.quote('annot_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' +urllib.parse.quote('"8b595dc0-9c5a-4caf-9703-9f8ff017e824"') + '}]'
# param = urllib.parse.urlencode(param)
In [ ]:
payload = OrderedDict([('passthru', u'/api/annot/age/months/json/'),
('asdasarg', param)])
response = requests.get(DOMAIN ,
params = payload
)
In [8]:
url = DOMAIN + '?passthru=' +"/api/annot/age/months/json" + '&arg=' + GP.ggr_annot_form_arg('3f814994-216c-4015-9af3-f286481414c0')
In [9]:
res = requests.get(url)
# "/api/annot/age/months/json" - age
# "/api/annot/sex/json/" - sex
# "/api/annot/name/rowid/json/" - NID
#
In [10]:
res.json()
Out[10]:
In [ ]:
url = DOMAIN + '?passthru=' +"/api/annot/age/months/json/" + '&arg=' + ggxr_form_arg("8b595dc0-9c5a-4caf-9703-9f8ff017e824")
In [ ]:
s = "abcd"
'\"%s\"' %s
In [ ]:
ggr_form_arg = lambda x : urllib.parse.quote('annot_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'
In [ ]:
ggr_image_form_arg = lambda x : urllib.parse.quote('image_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'
In [48]:
import UploadAndDetectIBEIS as UD, uuid
import requests, json, datetime, urllib, importlib
importlib.reload(UD)
import GetPropertiesAPI as GP
importlib.reload(GP)
Out[48]:
In [ ]:
data_dict = {
'gid_list': [1],
}
image_uuid_list = UD.get('api/image/uuid', data_dict)
image_uuid_dict = image_uuid_list[0]
image_uuid = uuid.UUID(image_uuid_dict['__UUID__'])
data_dict = {
'query_annot_uuid_list' : [1],
'query_annot_name_list' : [image_uuid]
}
res = requests.get('http://pachy.cs.uic.edu:5000/api/engine/query/graph/', data = data_dict)
res.json()
In [ ]:
data_dict = {
'aid_list': [1],
}
image_uuid_list = UD.get('api/annot/uuid', data_dict)
image_uuid_list
In [ ]:
res = requests.get('http://pachy.cs.uic.edu:5001/api/annot/uuid/',
data = dict(aid_list=['1']))
print(res.json())
res = requests.get('http://pachy.cs.uic.edu:5000/api/annot/uuid/',
data = dict(aid_list=['15441']))
print(res.json())
In [ ]:
url = "http://pachy.cs.uic.edu:5001/api/engine/query/graph/"
data_dict = {
'query_annot_uuid_list' : json.dumps([{'__UUID__': '2637b5e7-2a41-4aea-9dbd-dfe186cc8c8c'}]),
}
response = requests.request('POST', url, data=data_dict)
In [ ]:
response.json()
In [ ]:
d['json_result']['inference_dict']['cluster_dict']
In [ ]:
d['json_result']['inference_dict']['annot_pair_dict']
In [ ]:
re.findall(r'NEWNAME_(\d+)', 'NEWNAME_-6')
In [16]:
import os, json, re
In [ ]:
data_dict = {
'gid_list': list(range(1702, 1792)),
}
UD.delete('api/image',data_dict)
In [33]:
with open("../data/beauty_ggr.json", "r") as bty_ggr_fl:
bty_ggr= json.load(bty_ggr_fl)
keys = list(bty_ggr.keys())
In [16]:
import BuildConsolidatedFeaturesFile as BCF
import importlib
importlib.reload(BCF)
import urllib
In [58]:
uuid_annot_map = BCF.build_feature_file_ggr(None, "/tmp/test")
In [17]:
aid_uuid_list = [item for sublist in list(uuid_annot_map.values()) for item in sublist if item]
In [18]:
aid_uuid_list
Out[18]:
In [22]:
ggr_image_form_arg = lambda x : urllib.parse.quote('image_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}' + ',{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'
In [49]:
GP.ggr_image_form_arg('9849a3a0-a8de-4c0a-b5db-4fa690a3578e')
Out[49]:
In [27]:
ggr_image_form_arg = lambda x : urllib.parse.quote('image_uuid_list=') + '[{' + urllib.parse.quote('"__UUID__"') + ':' + urllib.parse.quote('\"%s\"' %x) + '}]'
In [46]:
ggr_image_form_arg('9849a3a0-a8de-4c0a-b5db-4fa690a3578e')
data = json.dumps({
"passthru" : "/api/image/annot/uuid",
"arg" : {
'image_uuid_list' : json.dumps([{"__UUID__" : "9849a3a0-a8de-4c0a-b5db-4fa690a3578e" }])
}
})
req = requests.request("GET", url=DOMAIN, data=data)
In [16]:
ggr_contrib_form_arg = lambda x : urllib.parse.quote('contributor_tag_list=') + '[' + urllib.parse.quote('\"%s\"' %x) + ']'
In [14]:
import json
DOMAIN + "?passthru=/api/contributor/gids/unixtime/?gid_list="+ json.dumps([1])
GP.ggr_get("/api/image/note/?gid_list=[1]")
Out[14]:
In [18]:
# GGR.get("/api/contributor/gids/unixtime")
ggr_contrib_form_arg("GGR,100,A,00000")
Out[18]:
In [19]:
GP.ggr_annot_form_arg('blah')
Out[19]:
In [22]:
url = DOMAIN + "?passthru=" + "/api/contributor/gids/unixtime" + "&arg=" + "contributor_tag_list%3D[%22GGR%2C100%2CA%2C00000%22]"
In [23]:
url
Out[23]:
In [24]:
# 45775b50-cb67-51d0-a6a6-3dd88f4fbde2
GP.ggr_get("/api/image/lon", GP.ggr_image_form_arg("45775b50-cb67-51d0-a6a6-3dd88f4fbde2"))
Out[24]:
In [34]:
import re
keys = [re.findall(r'(.*).jpg', key)[0] for key in keys]
key_dash = keys[:10]
In [43]:
uuid_gid_map = {GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %gid)['results'][0]["__UUID__"] : gid for gid in range(1,37434)}
In [40]:
for i in range(1,11):
print(GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %i)['results'][0]["__UUID__"])
In [52]:
with open("/tmp/uuid_gid_map.json", "w") as fl:
json.dump(uuid_gid_map, fl, indent=4)
uuid_gid_map
Out[52]:
In [45]:
ggr_gid_form_arg = lambda x : urllib.parse.quote('gid_list=') + '[' + urllib.parse.quote('\"%s\"' %x) + ']'
In [47]:
ggr_gid_form_arg("1")
Out[47]:
In [49]:
lat = GP.ggr_get("/api/image/lat", GP.ggr_gid_form_arg(1))
In [50]:
lat
Out[50]:
In [17]:
BCF.build_exif_ftrs_fl_ggr("../data/uuid_gid_map.json",
"../data/ggr_uuid_list.dat",
"/tmp/test_exif.json", 1, 10)
Out[17]:
In [57]:
len(keys)
Out[57]:
In [58]:
str(u'01e3b8d2-a80d-547d-8897-ebb900e00595')
Out[58]:
In [59]:
GP.ggr_get("/api/image/annot/uuid/json", GP.ggr_image_form_arg("c6d2bfe6-629b-dcf3-4329-987968a833ee"))
Out[59]:
In [60]:
with open("../data/uuid_gid_map.json", "r") as fl:
lst = list(json.load(fl).keys())
with open("../data/ggr_uuid_list.dat", "w") as f2:
f2.write("\n".join(lst))
In [19]:
uuid_gid_map = {GP.ggr_get("/api/image/uuid/?gid_list=[%i]" %gid)['results'][0]["__UUID__"] : gid for gid in range(1,40811)}
In [ ]:
import requests
import UploadAndDetectIBEIS as UD
data