<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def init(loop=None, hardware: 'HardwareAPILike' = None):
 """ Builds an application and sets up RPC and HTTP servers with it. :param loop: A specific aiohttp event loop to use. If not specified, the server will use the default event loop. :param hardware: The hardware manager or hardware adapter to connect to. If not specified, the server will use :py:attr:`opentrons.hardware` """


    app = web.Application(loop=loop, middlewares=[error_middleware])
    if hardware:
        checked_hardware = hardware
    else:
        checked_hardware = opentrons.hardware
    app['com.opentrons.hardware'] = checked_hardware
    app['com.opentrons.rpc'] = RPCServer(app, MainRouter(checked_hardware))
    app['com.opentrons.http'] = HTTPServer(app, CONFIG['log_dir'])

    return app