Example #1
0
def receivePic():
    try:
        log.endpointReached('image',request.remote_addr)
        image = objectDetect()
        print('endpoint reachde')
        if request.method == 'POST':
            print("hello world")
            data = request.json
            pic_as_base64 = data['pictureString']
            with open("imageToDetect.jpg",'wb') as fh:
                fh.write(base64.b64decode(pic_as_base64))


            imagePath = "./imageToDetect.jpg"
            imageDetected, objectList = image.processImage(imagePath)
            objects = ""
            for i in range(len(objectList)):
                objects += objectList[i] +"\n"

            os.remove("./imageToDetect.jpg")
            os.remove("./imageToDetect_yolo3.jpg")
            log.success()
            return {
                "pictureResponse": imageDetected,
                "objects": objects
            }
        if request.method == 'GET':
            return "<h1>Hello world iSeek</h1>"
    except:
        log.fail(str(sys.exec_info()))
        return "failed check system log"
Example #2
0
def receivePic():
    try:
        log.endpointReached('image', request.remote_addr)
        image = objectDetect()
        print('endpoint reached')
        if request.method == 'POST':
            print("hello world")
            data = request.json
            pic_as_base64 = data['pictureString']

            with open("imageToDetect.jpg", 'wb') as fh:
                fh.write(base64.b64decode(pic_as_base64))

            imagePath = "./imageToDetect.jpg"
            objectList = image.detect(source=imagePath)

            with open('result.jpg', 'rb') as image_file:
                imageDetected = base64.b64encode(
                    image_file.read()).decode('utf-8')

            objects = ""
            for i in range(len(objectList)):
                objects += str(objectList[i])

            os.remove("./imageToDetect.jpg")
            os.remove("./result.jpg")
            log.success()
            return {"pictureResponse": imageDetected, "objects": objectList}
        if request.method == 'GET':
            return "<h1>Hello world iSeek</h1>"
    except Exception as e:
        log.fail(str(e))
        return "failed check system log"
Example #3
0
def chatbot():
    log.endpointReached('chatbot', request.remote_addr)
    try:
        if request.method == 'POST':
            data = request.json
            message = data['textString']

            jsonText = json.dumps({'textString': message})

            respond = requests.post(url, json=jsonText)
            log.success()
            return {"textResponse": respond.text}

        if request.method == 'GET':
            return "<h1>Hello world iSeek</h1>"
    except Exception as e:
        log.fail(str(e))
        return "failed check system log"
Example #4
0
def receiveWav():
    log.endpointReached('recording', request.remote_addr)
    print('endpoint reached')
    if request.method == 'POST':
        #try:
        if 'file' not in request.files:
            log.write("ERROR:\nNo File Given")
            return "no file added"

        wavFile = request.files['file']

        if wavFile.filename != '':
            wavFile.save(wavFile.filename)
        else:
            return "no file name given"

        filePath = "./{}".format(wavFile.filename)

        # Android sends audio files in .m4a format
        if wavFile.filename[-4:] == ".m4a":
            voice.m4aToWav(filePath)
            #filePath = "./{}".format(wavFile.filename[:-4] + '.wav')
            filePath = os.getcwd() + "/{}".format(wavFile.filename[:-4] +
                                                  '.wav')

        text = voice.wavToText(filePath)

        os.remove(filePath)

        jsonText = json.dumps({'textString': text})

        respond = requests.post(url, json=jsonText)

        log.success()

        return {"textResponse": respond.text}

        # except Exception as e:
        #     log.fail(str(e))
        #     return "failed check system log"

    if request.method == 'GET':
        # return "<h1>Hello world iSeek</h1>"
        return chatbot.chatbot_response('hello')
Example #5
0
def recieveText():
    log.endpointReached('text', request.remote_addr)
    image = objectDetect()
    if request.method == 'POST':
        print("hello world")
        data = request.json

        pic_as_base64 = data['pictureString']
        with open("textToDetect.jpg", 'wb') as fh:
            fh.write(base64.b64decode(pic_as_base64))

        imagePath = "./textToDetect.jpg"
        text = image.readText(imagePath)

        os.remove("./textToDetect.jpg")

        log.success()
        return {
            "imageText": text,
        }
    else:
        log.fail(sys.exc_info()[0])
        return "failed check system log"
Example #6
0
def send_time():
    log.endpointReached('time', request.remote_addr)
    print('hello world')
    return {'time': time.time()}
Example #7
0
def hello_world():
    log.endpointReached('hello_world', request.remote_addr)
    return "<h1>hello world iseek.</h1>"