def api_learn_add_del_route(op): if not op in allowed_endpoints: abort(404) session['username'] = database.get_username(request.form['interface'], request.form['username']) if session['username'] == None: abort (403) session['logged_in'] = True print '@@@@@@@@', session['username'] options = {} if not op == 'query': options = generic_learn_route(op, request.form, request.files['file'] if 'file' in request.files else None) else: try: # Retrieve knowledge. if 'type' in request.form and request.form['type'] == 'text': options['text'] = database.get_text(session['username']) elif 'type' in request.form and request.form['type'] == 'image': options['pictures'] = database.get_images(session['username']) else: options['pictures'] = database.get_images(session['username']) options['text'] = database.get_text(session['username']) except Exception as e: log(e) options['errno'] = 500 options['error'] = str(e) if 'errno' in options: return json.dumps(options), options['errno'] return json.dumps(options), 200
def api_learn_add_del_route(op): if not op in allowed_endpoints: abort(404) session['username'] = database.get_username(request.form['interface'], request.form['username']) if session['username'] == None: abort(403) session['logged_in'] = True print '@@@@@@@@', session['username'] options = {} if not op == 'query': options = generic_learn_route( op, request.form, request.files['file'] if 'file' in request.files else None) else: try: # Retrieve knowledge. if 'type' in request.form and request.form['type'] == 'text': options['text'] = database.get_text(session['username']) elif 'type' in request.form and request.form['type'] == 'image': options['pictures'] = database.get_images(session['username']) else: options['pictures'] = database.get_images(session['username']) options['text'] = database.get_text(session['username']) except Exception as e: log(e) options['errno'] = 500 options['error'] = str(e) if 'errno' in options: return json.dumps(options), options['errno'] return json.dumps(options), 200
def api_infer_route(): session['username'] = database.get_username(request.form['interface'], request.form['username']) if session['username'] == None: abort (403) session['logged_in'] = True print '@@@@@@@@', session['username'] options = generic_infer_route(request.form, request.files['file'] if 'file' in request.files else None) if 'errno' in options: return json.dumps(options), options['errno'] return json.dumps(options), 200