explosion / explosion/spacy-streamlit

No HTML object returned by displacy.render()

Open
#52 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
863
Forks
113
PR merge metrics
No merged PRs in 30d

Description

Running the set examples in Jupyter notebook causes:

```
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[47], line 2
1 doc = nlp('The tenants have mobility issues and cannot see well.')
----> 2 spacy_streamlit.visualize_spans(doc,
3 spans_key='sc',
4 displacy_options={'colors': {"MOBILITY":'#09a3d5'}},
5 show_table=False)

File ~\.conda\envs\prodigy\lib\site-packages\spacy_streamlit\visualizer.py:326, in visualize_spans(doc, spans_key, attrs, show_table, title, manual, displacy_options)
317 st.warning(
318 "When the parameter 'manual' is set to True, the parameter 'doc' must be of type 'Dict', not 'spacy.tokens.Doc'."
319 )
320 html = displacy.render(
321 doc,
322 style="span",
323 options=displacy_options,
324 manual=manual,
325 )
--> 326 st.write(f"{get_html(html)}", unsafe_allow_html=True)
328 if show_table:
329 data = [
330 [str(getattr(span, attr)) for attr in attrs]
331 for span in doc.spans[spans_key]
332 ]

File ~\.conda\envs\prodigy\lib\site-packages\spacy_streamlit\util.py:30, in get_html(html)
28 WRAPPER = """

{}
"""
29 # Newlines seem to mess with the rendering
---> 30 html = html.replace("\n", " ")
31 return WRAPPER.format(html)

AttributeError: 'NoneType' object has no attribute 'replace'
```

Setup:
Windows Server 2019 Standard
Jupyter 1.0.0
spaCy version 3.6.1
spacy-streamlit 1.0.6

Code:
```
import spacy_streamlit
import streamlit as st

import spacy
from spacy_streamlit import visualize_spans

nlp = spacy.load("en_core_web_sm")
doc = nlp("Sundar Pichai is the CEO of Google.")
span = doc[4:7] # CEO of Google
span.label_ = "CEO"
doc.spans["job_role"] = [span]
visualize_spans(
doc, spans_key="job_role", displacy_options={"colors": {"CEO": "#09a3d5"}}
)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.