mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 01:48:04 +03:00 
			
		
		
		
	Update streamlit app (#5017)
* Update streamlit app [ci skip] * Add all labels by default * Tidy up and auto-format Co-authored-by: Ines Montani <ines@ines.io>
This commit is contained in:
		
							parent
							
								
									979a3fd1f5
								
							
						
					
					
						commit
						ff8e71f46d
					
				| 
						 | 
					@ -26,12 +26,12 @@ DEFAULT_TEXT = "Mark Zuckerberg is the CEO of Facebook."
 | 
				
			||||||
HTML_WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem; margin-bottom: 2.5rem">{}</div>"""
 | 
					HTML_WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem; margin-bottom: 2.5rem">{}</div>"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@st.cache(ignore_hash=True)
 | 
					@st.cache(allow_output_mutation=True)
 | 
				
			||||||
def load_model(name):
 | 
					def load_model(name):
 | 
				
			||||||
    return spacy.load(name)
 | 
					    return spacy.load(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@st.cache(ignore_hash=True)
 | 
					@st.cache(allow_output_mutation=True)
 | 
				
			||||||
def process_text(model_name, text):
 | 
					def process_text(model_name, text):
 | 
				
			||||||
    nlp = load_model(model_name)
 | 
					    nlp = load_model(model_name)
 | 
				
			||||||
    return nlp(text)
 | 
					    return nlp(text)
 | 
				
			||||||
| 
						 | 
					@ -79,7 +79,9 @@ if "ner" in nlp.pipe_names:
 | 
				
			||||||
    st.header("Named Entities")
 | 
					    st.header("Named Entities")
 | 
				
			||||||
    st.sidebar.header("Named Entities")
 | 
					    st.sidebar.header("Named Entities")
 | 
				
			||||||
    label_set = nlp.get_pipe("ner").labels
 | 
					    label_set = nlp.get_pipe("ner").labels
 | 
				
			||||||
    labels = st.sidebar.multiselect("Entity labels", label_set, label_set)
 | 
					    labels = st.sidebar.multiselect(
 | 
				
			||||||
 | 
					        "Entity labels", options=label_set, default=list(label_set)
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    html = displacy.render(doc, style="ent", options={"ents": labels})
 | 
					    html = displacy.render(doc, style="ent", options={"ents": labels})
 | 
				
			||||||
    # Newlines seem to mess with the rendering
 | 
					    # Newlines seem to mess with the rendering
 | 
				
			||||||
    html = html.replace("\n", " ")
 | 
					    html = html.replace("\n", " ")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user