mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 10:16:27 +03:00
Add is_in_jupyter() helper for displaCy (see #1058)
This commit is contained in:
parent
abf0188b0a
commit
489d2fb4ba
|
@ -3,13 +3,14 @@ from __future__ import unicode_literals
|
|||
|
||||
from .render import DependencyRenderer, EntityRenderer
|
||||
from ..tokens import Doc
|
||||
from ..util import prints
|
||||
from ..util import prints, is_in_jupyter
|
||||
|
||||
|
||||
_html = {}
|
||||
IS_JUPYTER = is_in_jupyter()
|
||||
|
||||
|
||||
def render(docs, style='dep', page=False, minify=False, jupyter=False, options={}):
|
||||
def render(docs, style='dep', page=False, minify=False, jupyter=IS_JUPYTER, options={}):
|
||||
"""Render displaCy visualisation.
|
||||
|
||||
docs (list or Doc): Document(s) to visualise.
|
||||
|
|
|
@ -142,6 +142,20 @@ def parse_package_meta(package_path, require=True):
|
|||
return None
|
||||
|
||||
|
||||
def is_in_jupyter():
|
||||
"""Check if user is in a Jupyter notebook. Mainly used for displaCy.
|
||||
|
||||
RETURNS (bool): True if in Jupyter, False if not.
|
||||
"""
|
||||
try:
|
||||
cfg = get_ipython().config
|
||||
if cfg['IPKernelApp']['parent_appname'] == 'ipython-notebook':
|
||||
return True
|
||||
except NameError:
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def get_cuda_stream(require=False):
|
||||
# TODO: Error and tell to install chainer if not found
|
||||
# Requires GPU
|
||||
|
|
Loading…
Reference in New Issue
Block a user