code: def smoothed_pdf(
      data,
      k=350,
      smoothing=0.5,
      legend=None,
      title=None,
      log=False,
      interactive=False,
      figure=None,
  ) -> Union[figure, Tuple[figure, Callable]]:
      """Create a density plot.
  
      Parameters
      ----------
      data : :class:`.Struct` or :class:`.Float64Expression`
          Sequence of data to plot.
      k : int
          Accuracy parameter.
      smoothing : float
          Degree of smoothing.
      legend : str
          Label of data on the x-axis.
      title : str
          Title of the histogram.
      log : bool
          Plot the log10 of the bin counts.
      interactive : bool
          If `True`, return a handle to pass to :func:`bokeh.io.show`.
      figure : :class:`bokeh.plotting.figure`
          If not None, add density plot to figure. Otherwise, create a new figure.
  
      Returns
      -------
      :class:`bokeh.plotting.figure`
      """
      if isinstance(data, Expression):
          if data._indices is None:
              raise ValueError("Invalid input")
          agg_f = data._aggregation_method()
          data = agg_f(aggregators.approx_cdf(data, k))
  
      if legend is None:
          legend = ""
  
      y_axis_label = "Frequency"
      if log:
          y_axis_type = "log"
      else:
          y_axis_type = "linear"
  
      if figure is None:
          p = bokeh.plotting.figure(
              title=title,
              x_axis_label=legend,
              y_axis_label=y_axis_label,
              y_axis_type=y_axis_type,
              width=600,
              height=400,
              tools="xpan,xwheel_zoom,reset,save",
              active_scroll="xwheel_zoom",
              background_fill_color="#EEEEEE",
          )
      else:
          p = figure
  
      n = data["ranks"][-1]
      weights = np.diff(data["ranks"][1:-1])
      min = data["values"][0]
      max = data["values"][-1]
      values = np.array(data["values"][1:-1])
      slope = 1 / (max - min)
  
      def f(x, prev, smoothing=smoothing):
          inv_scale = (np.sqrt(n * slope) / smoothing) * np.sqrt(
              prev / weights
          )
          diff = x[:, np.newaxis] - values
          grid = (
              (3 / (4 * n))
              * weights
              * np.maximum(
                  0,
                  inv_scale
                  - np.power(diff, 2) * np.power(inv_scale, 3),
              )
          )
          return np.sum(grid, axis=1)
  
      round1 = f(values, np.full(len(values), slope))
      x_d = np.linspace(min, max, 1000)
      final = f(x_d, round1)
  
      line = p.line(
          x_d,
          final,
          line_width=2,
          line_color="black",
          legend_label=legend,
      )
  
      if interactive:
  
          def mk_interact(handle):
              def update(smoothing=smoothing):
                  final = f(x_d, round1, smoothing)
                  line.data_source.data = {"x": x_d, "y": final}
                  bokeh.io.push_notebook(handle=handle)
  
              from ipywidgets import interact
  
              interact(update, smoothing=(0.02, 0.8, 0.005))
  
          return p, mk_interact
      else:
          return p
  
imports: import math
  import collections
  import numpy
  import pandas
  import bokeh
  import bokeh.io
  import bokeh.models
  import warnings
  from bokeh.models import HoverTool, ColorBar, LogTicker, LogColorMapper, LinearColorMapper, CategoricalColorMapper, ColumnDataSource, BasicTicker, Plot, CDSView, GroupFilter, IntersectionFilter, Legend, LegendItem, Renderer, CustomJS, Select, Column, Span, DataRange1d, Slope, Label, ColorMapper, GridPlot
  import bokeh.plotting
  import bokeh.palettes
  from bokeh.plotting import figure
  from bokeh.transform import transform
  from bokeh.layouts import gridplot
  from hail.expr import aggregators
  from hail.expr.expressions import Expression, NumericExpression, StringExpression, LocusExpression, Int32Expression, Int64Expression, Float32Expression, Float64Expression, expr_numeric, expr_float64, expr_any, expr_locus, expr_str, raise_unless_row_indexed
  from hail.expr.functions import _error_from_cdf_python
  from hail.typecheck import typecheck, oneof, nullable, sized_tupleof, numeric, sequenceof, dictof
  from hail import Table, MatrixTable
  from hail.utils.struct import Struct
  from hail.utils.java import warning
  from typing import List, Tuple, Dict, Union, Callable, Optional, Sequence, Any, Set
  import hail
label_desc: Use image node_id 6 for calling a global function with example usage: smoothed_pdf(data, k, smoothing, legend, title, log, interactive, figure) and returns: np, p,  mk_interact, p