def img_recognize(): start = timer() if not os.path.exists(app.config['UPLOAD_FOLDER']): os.makedirs(app.config['UPLOAD_FOLDER']) file = request.files['file'] # TODO : #if file and allowed_file(file.filename): filename = secure_filename(file.filename) img_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) file.save(img_path) # Use Inception Model inception.data_dir = app.config['INCEPTION_MODEL'] inception.maybe_download() model = inception.Inception() pred = model.classify(image_path=img_path) scores = model.get_scores(pred=pred, k=5) model.close() #Getting environment variable or using default localhost hostname=os.getenv('JDG_HOSTNAME','0.0.0.0') remote_cache = RemoteCache(host=hostname) times = datetime.datetime.now().strftime("%B-%d-%Y-%I:%M%p") key= filename remote_cache.put("last_transaction", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) remote_cache.put(key, json.dumps({'pred':scores, 'timestamp': times , 'filename': filename}) ) print remote_cache.stats() print "Key: %s" % key # Send data resp = {'pred': scores} end = timer() total=end - start remote_cache.put( "time_taken" , str(total) ) return Response( json.dumps(resp), status=200, mimetype="application/json")
class HotRodCacheClient(CacheClient): """HotRod cache client implementation.""" def __init__(self, config): super(HotRodCacheClient, self).__init__(config["host"], config["port"], config["cache"]) self.config = config if config["hotrod.use_river_string_keys"] in TRUE_STR_VALUES: self.river_keys = RiverStringCodec() else: self.river_keys = None if self.cache_name == DEFAULT_CACHE_NAME: self.cache_name = ""; self.remote_cache = RemoteCache(self.host, int(self.port), self.cache_name) return def _optionally_encode_key(self, key_unmarshalled): if self.river_keys == None: return key_unmarshalled; else: return self.river_keys.encode(key_unmarshalled) def put(self, key, value, version=None, lifespan=None, max_idle=None, put_if_absent=False): key = self._optionally_encode_key(key) if lifespan == None: lifespan=0 if max_idle == None: max_idle=0 try: if (version == None): if (put_if_absent): retval = self.remote_cache.put_if_absent(key, value, lifespan, max_idle) if retval: return else: raise ConflictError else: self.remote_cache.put(key, value, lifespan, max_idle) else: numversion = None try: numversion = int(version) except ValueError: self._error("hotrod client only accepts numeric versions") retval = self.remote_cache.replace_with_version(key, value, numversion, lifespan, max_idle) if retval == 1: return elif retval == 0: raise NotFoundError elif retval == -1: raise ConflictError else: self._error("unexpected return value from hotrod client") except RemoteCacheError as e: self._error(e.args) def get(self, key, get_version=False): try: value = None version = None key = self._optionally_encode_key(key) if get_version: version, value = self.remote_cache.get_versioned(key) else: value = self.remote_cache.get(key) if value == None: raise NotFoundError if get_version: return version, value else: return value except RemoteCacheError as e: self._error(e.args) def delete(self, key, version=None): try: key = self._optionally_encode_key(key) if version == None: retval = self.remote_cache.remove(key) if retval: return else: raise NotFoundError else: numversion = None try: numversion = int(version) except ValueError: self._error("hotrod client only accepts numeric versions") retval = self.remote_cache.remove_with_version(key, numversion) if retval == 1: return elif retval == 0: raise NotFoundError elif retval == -1: raise ConflictError else: self._error("unexpected return value from hotrod client") except RemoteCacheError as e: self._error(e.args) def clear(self): self.remote_cache.clear() def exists(self, key): try: key = self._optionally_encode_key(key) if not self.remote_cache.contains_key(key): raise NotFoundError except RemoteCacheError as e: self._error(e.args)
def main(): remote_cache = RemoteCache() for i in range(0, NUM_ENTRIES): value = random.randint(0, MAX_VAL) remote_cache.put(str(i), str(value))
def main(): remote_cache = RemoteCache() for i in range(0, NUM_ENTRIES): value = random.randint(0, MAX_VAL) remote_cache.put(str(i),str(value))