pythonjupyter-notebooknlpspacydisplacy

spaCy displacy output using anvil.works server


I am attempting to display entities using spaCy's displacy feature. The output of my render is being shown in my Jupyter Notebook code cell with my anvil.server.wait_forever() code.

Here is an example of the code cell output I'm getting.

I would rather have the output appear here.

I have already tried using displacy.server instead of displacy.render and tried auto_port.

Here is my code:

def visualize_entities_in_sentences(self, doc_id):
    """Visualize entities in the sentences of a document.

    :param doc_id: the id of the document to visualize
    :type doc_id: str
    """
    doc = self.get_document(doc_id)
    sentences = list(doc.sents)
    labels = displacy.render(sentences, style="ent", page=False, minify=True)
    return labels

And my callable for the Anvil implementation:

@anvil.server.callable
def get_visualize_entities_in_sentences(doc_id):
    """"Get the document markdown for a document in my_corpus with entity labels visualized.

    :param doc_id: a document id
    :type doc_id: str
    :returns: markdown
    :rtype: str
    """    
    return my_corpus.visualize_entities_in_sentences(doc_id)

Solution

  • Try adding jupyter=False to displacy.render to skip the jupyter auto-detection.