def test_search_by_image(post_factory, config_injector, read_asset): config_injector({"allow_broken_uploads": False}) post = post_factory() posts.generate_post_signature(post, read_asset("jpeg.jpg")) db.session.flush() result1 = posts.search_by_image(read_asset("jpeg-similar.jpg")) assert len(result1) == 1 result1_distance, result1_post = result1[0] assert abs(result1_distance - 0.19713075553164386) < 1e-8 assert result1_post.post_id == post.post_id result2 = posts.search_by_image(read_asset("png.png")) assert not result2
def get_posts_by_image(ctx, _params=None): auth.verify_privilege(ctx.user, 'posts:reverse_search') content = ctx.get_file('content', required=True) return { 'exactPost': _serialize_post(ctx, posts.search_by_image_exact(content)), 'similarPosts': [ { 'distance': lookalike.distance, 'post': _serialize_post(ctx, lookalike.post), } for lookalike in posts.search_by_image(content) ], }
def get_posts_by_image(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: auth.verify_privilege(ctx.user, 'posts:reverse_search') content = ctx.get_file('content') try: lookalikes = posts.search_by_image(content) except (errors.ThirdPartyError, errors.ProcessingError): lookalikes = [] return { 'exactPost': _serialize_post(ctx, posts.search_by_image_exact(content)), 'similarPosts': [{ 'distance': lookalike.distance, 'post': _serialize_post(ctx, lookalike.post), } for lookalike in lookalikes], }
def get_posts_by_image(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: auth.verify_privilege(ctx.user, "posts:reverse_search") content = ctx.get_file("content") try: lookalikes = posts.search_by_image(content) except (errors.ThirdPartyError, errors.ProcessingError): lookalikes = [] return { "exactPost": _serialize_post(ctx, posts.search_by_image_exact(content)), "similarPosts": [{ "distance": distance, "post": _serialize_post(ctx, post), } for distance, post in lookalikes], }
def get_posts_by_image( ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: auth.verify_privilege(ctx.user, 'posts:reverse_search') content = ctx.get_file('content') try: lookalikes = posts.search_by_image(content) except (errors.ThirdPartyError, errors.ProcessingError): lookalikes = [] return { 'exactPost': _serialize_post(ctx, posts.search_by_image_exact(content)), 'similarPosts': [ { 'distance': lookalike.distance, 'post': _serialize_post(ctx, lookalike.post), } for lookalike in lookalikes ], }