def get_web_ui_url(sc):
    """Gets the URL of the Spark web UI for a given SparkContext.

    Parameters
    ----------
    sc : SparkContext

    Returns
    -------
    url : str
        URL to the Spark web UI
    """
    conf = sc._jsc.getConf()
    if conf.getBoolean('spark.ui.reverseProxy', False):
        proxy_url = conf.get('spark.ui.reverseProxyUrl', '')
        if proxy_url:
            web_ui_url = '{proxy_url}/proxy/{application_id}'.format(proxy_url
                =proxy_url, application_id=sc.applicationId)
        else:
            web_ui_url = 'Spark Master Public URL'
    else:
        joption = sc._jsc.sc().uiWebUrl()
        if joption.isDefined():
            web_ui_url = joption.get()
        else:
            web_ui_url = ''
    yarn_proxy_spark_property = (
        'spark.org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.param.PROXY_URI_BASES'
        )
    if sc.master.startswith('yarn'):
        web_ui_url = conf.get(yarn_proxy_spark_property)
    return web_ui_url
