code: def leg_from_proto_v2(
      leg_proto: ir_swap.SwapLeg,
  ) -> Union[
      coupon_specs.FixedCouponSpecs, coupon_specs.FloatCouponSpecs
  ]:
      """Initialized coupon specifications from a proto instance."""
      if leg_proto.HasField("fixed_leg"):
          leg = leg_proto.fixed_leg
          coupon_freq = leg.coupon_frequency.type
          (
              coupon_freq,
              coupon_freq_multiplier,
          ) = _frequency_and_multiplier(coupon_freq)
          return coupon_specs.FixedCouponSpecs(
              currency=[currencies.from_proto_value(leg.currency)],
              coupon_frequency=(
                  coupon_freq,
                  [
                      coupon_freq_multiplier
                      * leg.coupon_frequency.amount
                  ],
              ),
              notional_amount=[
                  instrument_utils.decimal_to_double(
                      leg.notional_amount
                  )
              ],
              fixed_rate=[
                  instrument_utils.decimal_to_double(leg.fixed_rate)
              ],
              settlement_days=[leg.settlement_days],
              businessday_rule=business_days.convention_from_proto_value(
                  leg.business_day_convention
              ),
              daycount_convention=daycount_conventions.from_proto_value(
                  leg.daycount_convention
              ),
              calendar=business_days.holiday_from_proto_value(
                  leg.bank_holidays
              ),
          )
      else:
          leg = leg_proto.floating_leg
          # Get the index rate object
          rate_index = leg.floating_rate_type
          rate_index = rate_indices.RateIndex.from_proto(rate_index)
          rate_index.name = [rate_index.name]
          rate_index.source = [rate_index.source]
          coupon_freq = leg.coupon_frequency.type
          (
              coupon_freq,
              coupon_freq_multiplier,
          ) = _frequency_and_multiplier(coupon_freq)
          reset_freq = leg.reset_frequency.type
          reset_freq, reset_freq_multiplier = _frequency_and_multiplier(
              reset_freq
          )
          return coupon_specs.FloatCouponSpecs(
              currency=[currencies.from_proto_value(leg.currency)],
              coupon_frequency=(
                  coupon_freq,
                  [
                      coupon_freq_multiplier
                      * leg.coupon_frequency.amount
                  ],
              ),
              reset_frequency=(
                  reset_freq,
                  [reset_freq_multiplier * leg.reset_frequency.amount],
              ),
              notional_amount=[
                  instrument_utils.decimal_to_double(
                      leg.notional_amount
                  )
              ],
              floating_rate_type=[rate_index],
              settlement_days=[leg.settlement_days],
              businessday_rule=business_days.convention_from_proto_value(
                  leg.business_day_convention
              ),
              daycount_convention=daycount_conventions.from_proto_value(
                  leg.daycount_convention
              ),
              spread=[instrument_utils.decimal_to_double(leg.spread)],
              calendar=business_days.holiday_from_proto_value(
                  leg.bank_holidays
              ),
          )
  
imports: from typing import Any, Dict, List, Tuple, Union
  import tensorflow.compat.v2
  from tf_quant_finance import datetime
  from tf_quant_finance.experimental.pricing_platform.framework import utils
  from tf_quant_finance.experimental.pricing_platform.framework.core import business_days
  from tf_quant_finance.experimental.pricing_platform.framework.core import currencies
  from tf_quant_finance.experimental.pricing_platform.framework.core import curve_types
  from tf_quant_finance.experimental.pricing_platform.framework.core import daycount_conventions
  from tf_quant_finance.experimental.pricing_platform.framework.core import rate_indices
  from tf_quant_finance.experimental.pricing_platform.framework.market_data import utils
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import cashflow_streams
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import coupon_specs
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import utils
  from tf_quant_finance.experimental.pricing_platform.instrument_protos import interest_rate_swap_pb2
label_desc: Use image node_id 5 for calling a global function with example usage: leg_from_proto_v2(leg_proto) and returns: coupon_specs, coupon_specs