def training(request): if request.is_ajax(): msg = trained.poll(50) msg = _ext_record_value(msg, trained_partition) logger.info(msg) return JsonResponse({'training_result': msg}) send = producer(KAFKA_BROKER_URL) send('trainer', {'cid': get_cid()}) return render(request, 'ml_training.html')
def trigger_word(request): if request.is_ajax(): msg = detected.poll(50) msg = _ext_record_value(msg, detected_partition) logger.info(msg) return JsonResponse({'detected': msg}) if request.method == 'POST' and request.FILES['myfile']: myfile = request.FILES['myfile'] fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) send = producer(KAFKA_BROKER_URL) send('detector', { 'cid': get_cid(), 'filePath': fs.base_location + '/' + filename }) return render(request, 'ml_detect_trigger_word.html', {'reloaded': True}) return render(request, 'ml_detect_trigger_word.html')
import os from common.mq.kafka import consumer, producer from common.log.logger import get_logger from common.log.cid import set_cid from slicer import process KAFKA_BROKER_URL = os.environ.get('KAFKA_BROKER_URL') CONSUMER_TOPIC = os.environ.get('UPLOAD_TOPIC') PRODUCER_TOPICS = [ topic.strip() for topic in str(os.environ.get('SLICER_TOPICS')).split(",") ] logger = get_logger(__name__) send = producer(KAFKA_BROKER_URL) if __name__ == '__main__': consumer = consumer(KAFKA_BROKER_URL, CONSUMER_TOPIC) for message in consumer: data: dict = message.value cid: str = data['cid'] set_cid(cid) logger.info(data) res = process(data) if res: for topic in PRODUCER_TOPICS: send(topic, res)
def negatives(request): return save_file(request, 'negatives') def save_file(request, path=None): if request.method == 'POST' and request.FILES['myfile']: myfile = request.FILES['myfile'] fs = FileSystemStorage() filename = fs.save( myfile.name if path is None else path + '/' + myfile.name, myfile) uploaded_file_url = fs.url(filename) logger.info(fs.path(filename)) make_json(fs.path(filename)) return render(request, path + '_uploads.html', {'uploaded_file_url': uploaded_file_url}) return render(request, path + '_uploads.html' if path is not None else 'home.html') msg_q = producer(KAFKA_BROKER_URL) def make_json(path): jsondict = OrderedDict() jsondict["cid"] = get_cid() jsondict["path"] = path msg_q(TOPIC, jsondict)