def infer_route(): options = {} if os.environ.get('ASR_ADDR_PORT'): options['asr_addr_port'] = os.environ.get('ASR_ADDR_PORT') else: options['asr_addr_port'] = 'ws://*****:*****@@@@@@@@@@', speech_input image_input = [upload_file.read()] if upload_file else None lucida_id = session['username'] # Check if context is saved for Lucida user # If not, classify query, otherwise restore session if lucida_id not in Config.SESSION: services_needed = \ query_classifier.predict(speech_input, upload_file) speech_input = [speech_input] else: services_needed = Config.SESSION[lucida_id]['graph'] Config.SESSION[lucida_id]['data']['text'].append( speech_input) speech_input = Config.SESSION[lucida_id]['data']['text'] options['result'] = thrift_client.infer(lucida_id, \ services_needed, speech_input, image_input) log('Result ' + options['result']) # Check if Calendar service is needed. # If so, JavaScript needs to receive the parsed dates. if services_needed.has_service('CA'): options['dates'] = options['result'] options['result'] = None return render_template('infer.html', **options) else: raise RuntimeError('Did you click the Ask button?') except Exception as e: log(e) if str(e) == 'TSocket read 0 bytes': e = 'Back-end service encountered a problem' options['error'] = e return render_template('infer.html', **options) # Display. return render_template('infer.html', **options)
def generic_infer_route(form, upload_file): options = {} if os.environ.get('ASR_ADDR_PORT'): options['asr_addr_port'] = os.environ.get('ASR_ADDR_PORT') else: options['asr_addr_port'] = 'ws://localhost:' + port_dic["cmd_port"] try: # Deal with POST requests. if request.method == 'POST': if not upload_file is None and upload_file.filename != '': check_image_extension(upload_file) # Classify the query. speech_input = form['speech_input'] if 'speech_input' in form \ else '' print 'Query: ', speech_input image_input = [upload_file.read()] if upload_file else None lucida_id = session['username'] # Check if context is saved for Lucida user # If not, classify query, otherwise restore session if lucida_id not in Config.SESSION: services_needed = query_classifier.predict( speech_input, upload_file) speech_input = [speech_input] else: services_needed = Config.SESSION[lucida_id]['graph'] Config.SESSION[lucida_id]['data']['text'].append(speech_input) speech_input = Config.SESSION[lucida_id]['data']['text'] node = services_needed.get_node(0) try: options['result'] = thrift_client.infer( lucida_id, node.service_name, speech_input, image_input) except Exception as ex: print "Exception raised while trying to infer", ex.message options['error'] = str(ex) raise if 'result' in options: log('Result ' + options['result']) # Check if Calendar service is needed. # If so, JavaScript needs to receive the parsed dates. if services_needed.has_service('CAWF'): options['dates'] = options['result'] options['result'] = None else: options['error'] = "Result was empty." except Exception as e: log(e) options['errno'] = "Unknown" options['error'] = str(e.message) if 'code' in e and re.match("^4\d\d$", str(e.code)): options['errno'] = e.code if str(e) == 'TSocket read 0 bytes': options['error'] = 'Back-end service encountered a problem' if str(e).startswith('Could not connect to'): options['error'] = 'Back-end service is not running' return options
def generic_infer_route(form, upload_file): options = {} if os.environ.get('ASR_ADDR_PORT'): options['asr_addr_port'] = os.environ.get('ASR_ADDR_PORT') else: options['asr_addr_port'] = 'ws://*****:*****@@@@@@@@@@', speech_input image_input = [upload_file.read()] if upload_file else None lucida_id = session['username'] # Check if context is saved for Lucida user # If not, classify query, otherwise restore session if lucida_id not in Config.SESSION: services_needed = query_classifier.predict(speech_input, upload_file) speech_input = [speech_input] else: services_needed = Config.SESSION[lucida_id]['graph'] Config.SESSION[lucida_id]['data']['text'].append(speech_input) speech_input = Config.SESSION[lucida_id]['data']['text'] node = services_needed.get_node(0) options['result'] = thrift_client.infer(lucida_id, node.service_name, speech_input, image_input) log('Result ' + options['result']) # Check if Calendar service is needed. # If so, JavaScript needs to receive the parsed dates. if services_needed.has_service('CA'): options['dates'] = options['result'] options['result'] = None except Exception as e: log(e) options['errno'] = 500 options['error'] = str(e) if 'code' in e and re.match("^4\d\d$", str(e.code)): options['errno'] = e.code if str(e) == 'TSocket read 0 bytes': options['error'] = 'Back-end service encountered a problem' if str(e).startswith('Could not connect to'): options['error'] = 'Back-end service is not running' return options
def infer_route(): options = {} if os.environ.get('ASR_ADDR_PORT'): options['asr_addr_port'] = os.environ.get('ASR_ADDR_PORT') else: options['asr_addr_port'] = 'ws://*****:*****@@@@@@@@@@', form['speech_input'] # Classify the query. services_needed = \ query_classifier.predict(form['speech_input'], upload_file) options['result'] = thrift_client.infer( session['username'], services_needed, form['speech_input'], upload_file.read()) log('Result ' + options['result']) # Check if Calendar service is needed. # If so, JavaScript needs to receive the parsed dates. if services_needed.has_service('CA'): options['dates'] = options['result'] options['result'] = None return render_template('infer.html', **options) else: raise RuntimeError('Did you click the Ask button?') except Exception as e: log(e) if str(e) == 'TSocket read 0 bytes': e = 'Back-end service encountered a problem' options['error'] = e return render_template('infer.html', **options) # Display. return render_template('infer.html', **options)
def infer_route(): options = {} if os.environ.get("ASR_ADDR_PORT"): options["asr_addr_port"] = os.environ.get("ASR_ADDR_PORT") else: options["asr_addr_port"] = "ws://*****:*****@@@@@@@@@@", form["speech_input"] # Classify the query. services_needed = query_classifier.predict(form["speech_input"], upload_file) options["result"] = thrift_client.infer( session["username"], services_needed, form["speech_input"], upload_file.read() ) log("Result " + options["result"]) # Check if Calendar service is needed. # If so, JavaScript needs to receive the parsed dates. if services_needed.has_service("CA"): options["dates"] = options["result"] options["result"] = None return render_template("infer.html", **options) else: raise RuntimeError("Did you click the Ask button?") except Exception as e: log(e) if str(e) == "TSocket read 0 bytes": e = "Back-end service encountered a problem" options["error"] = e return render_template("infer.html", **options) # Display. return render_template("infer.html", **options)