from aiohttp import web
import base64
import io
import face_recognition

async def encode(request):
    request_data = await request.json()

    # Read base64 encoded image
    url = request_data['image'].split(',')[1]
    image = io.BytesIO(base64.b64decode(url))

    # Load image data
    np_array = face_recognition.load_image_file(image)

    # Find face locations
    locations = face_recognition.face_locations(np_array)

    # Create face encodings
    encodings = face_recognition.face_encodings(np_array, locations)

    results = []

    for i in range(len(locations)):
        top, right, bottom, left = locations[i]

        result = {
            'x': left,
            'y': top,
            'width': right - left,
            'height': bottom - top,
            'encodings': encodings[i].tolist()
        }

        results.append(result)

    return web.json_response(results)

def main():
    app = web.Application()
    app.router.add_post('/encode', encode)

    web.run_app(app, host='0.0.0.0', port='3000')

main()

[((303, 342), 'face_recognition.load_image_file', 'face_recognition.load_image_file', (['image'], {}), '(image)\n', (335, 342), False, 'import face_recognition\n'), ((386, 427), 'face_recognition.face_locations', 'face_recognition.face_locations', (['np_array'], {}), '(np_array)\n', (417, 427), False, 'import face_recognition\n'), ((473, 525), 'face_recognition.face_encodings', 'face_recognition.face_encodings', (['np_array', 'locations'], {}), '(np_array, locations)\n', (504, 525), False, 'import face_recognition\n'), ((866, 892), 'aiohttp.web.json_response', 'web.json_response', (['results'], {}), '(results)\n', (883, 892), False, 'from aiohttp import web\n'), ((916, 933), 'aiohttp.web.Application', 'web.Application', ([], {}), '()\n', (931, 933), False, 'from aiohttp import web\n'), ((982, 1027), 'aiohttp.web.run_app', 'web.run_app', (['app'], {'host': '"""0.0.0.0"""', 'port': '"""3000"""'}), "(app, host='0.0.0.0', port='3000')\n", (993, 1027), False, 'from aiohttp import web\n'), ((242, 263), 'base64.b64decode', 'base64.b64decode', (['url'], {}), '(url)\n', (258, 263), False, 'import base64\n')]