예제 #1
0
async def do_get_question_api(question: str, table_name: str = None):
    try:
        questions, distances = do_search(table_name, question, MODEL,
                                         MILVUS_CLI, MYSQL_CLI)
        #res = dict(zip(questions, distances))
        # res = sorted(res.items(), key=lambda item: item[1])
        LOGGER.info("Successfully searched similar images!")
        return {'status': True, 'msg': questions}, 200
    except Exception as e:
        LOGGER.error(e)
        return {'status': False, 'msg': e}, 400
예제 #2
0
파일: main.py 프로젝트: filip-halt/bootcamp
async def search_images(image: UploadFile = File(...), table_name: str = None):
    # Search the upload image in Milvus/MySQL
    try:
        # Save the upload image to server.
        content = await image.read()
        print('read pic succ')
        img_path = os.path.join(UPLOAD_PATH, image.filename)
        with open(img_path, "wb+") as f:
            f.write(content)
        paths, distances = do_search(table_name, img_path, MODEL, MILVUS_CLI,
                                     MYSQL_CLI)
        res = dict(zip(paths, distances))
        res = sorted(res.items(), key=lambda item: item[1])
        LOGGER.info("Successfully searched similar images!")
        return res
    except Exception as e:
        LOGGER.error(e)
        return {'status': False, 'msg': e}, 400
예제 #3
0
async def search_images(request: Request,
                        image: UploadFile = File(...),
                        table_name: str = None):
    # Search the upload image in Milvus/MySQL
    try:
        # Save the upload image to server.
        content = await image.read()
        img_path = os.path.join(UPLOAD_PATH, image.filename)
        with open(img_path, "wb+") as f:
            f.write(content)
        host = request.headers['host']
        paths, distances = do_search(host, table_name, img_path, MODEL,
                                     MILVUS_CLI, MYSQL_CLI)
        res = {}
        for p, d in zip(paths, distances):
            if not p in res or res[p] > d:
                res[p] = d
        res = sorted(res.items(), key=lambda item: item[1])
        LOGGER.info("Successfully searched similar images!")
        return res
    except Exception as e:
        LOGGER.error(e)
        return {'status': False, 'msg': e}, 400