Spaces:
Running
Running
Commit
·
e23402e
1
Parent(s):
11dbd43
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spacy_streamlit
|
2 |
+
from pathlib import Path
|
3 |
+
import srsly
|
4 |
+
import importlib
|
5 |
+
import random
|
6 |
+
|
7 |
+
MODELS = srsly.read_json(Path(__file__).parent / "models.json")
|
8 |
+
DEFAULT_MODEL = "en_core_web_sm"
|
9 |
+
DEFAULT_TEXT = "David Bowie moved to the US in 1974, initially staying in New York City before settling in Los Angeles."
|
10 |
+
DESCRIPTION = """**Explore trained [spaCy v3.0](https://nightly.spacy.io) pipelines**"""
|
11 |
+
|
12 |
+
def get_default_text(nlp):
|
13 |
+
# Check if spaCy has built-in example texts for the language
|
14 |
+
try:
|
15 |
+
examples = importlib.import_module(f".lang.{nlp.lang}.examples", "spacy")
|
16 |
+
return examples.sentences[0]
|
17 |
+
except (ModuleNotFoundError, ImportError):
|
18 |
+
return ""
|
19 |
+
|
20 |
+
spacy_streamlit.visualize(
|
21 |
+
MODELS,
|
22 |
+
default_model=DEFAULT_MODEL,
|
23 |
+
visualizers=["parser", "ner", "similarity", "tokens"],
|
24 |
+
show_visualizer_select=True,
|
25 |
+
sidebar_description=DESCRIPTION,
|
26 |
+
get_default_text=get_default_text
|
27 |
+
)
|