code: def assemble_pysb():
      
      if request.method == 'OPTIONS':
          return {}
      response = request.body.read().decode('utf-8')
      body = json.loads(response)
      stmts_json = body.get('statements')
      export_format = body.get('export_format')
      stmts = stmts_from_json(stmts_json)
      pa = PysbAssembler()
      pa.add_statements(stmts)
      pa.make_model()
      try:
          for m in pa.model.monomers:
              pysb_assembler.set_extended_initial_condition(pa.model, m, 0)
      except Exception as e:
          logger.exception(e)
  
      if not export_format:
          model_str = pa.print_model()
      elif export_format in ('kappa_im', 'kappa_cm'):
          fname = 'model_%s.png' % export_format
          root = os.path.dirname(os.path.abspath(fname))
          graph = pa.export_model(format=export_format, file_name=fname)
          with open(fname, 'rb') as fh:
              data = 'data:image/png;base64,%s' % \
                  base64.b64encode(fh.read()).decode() 
              return {'image': data}
      else:
          try:
              model_str = pa.export_model(format=export_format)
          except Exception as e:
              logger.exception(e)
              model_str = ''
      res = {'model': model_str}
      return res
docs: Assemble INDRA Statements and return PySB model string.