<a href="https://explosion.ai"><img src="https://explosion.ai/assets/img/logo.svg" width="125" height="125" align="right" /></a>
# spacy-streamlit: spaCy building blocks for Streamlit apps
This package contains utilities for visualizing [spaCy](https://spacy.io) models
and building interactive spaCy-powered apps with
[Streamlit](https://streamlit.io). It includes various building blocks you can
use in your own Streamlit app, like visualizers for **syntactic dependencies**,
**named entities**, **text classification**, **semantic similarity** via word
vectors, token attributes, and more.
[![Current Release Version](https://img.shields.io/github/release/explosion/spacy-streamlit.svg?style=flat-square&logo=github&include_prereleases)](https://github.com/explosion/spacy-streamlit/releases)
[![pypi Version](https://img.shields.io/pypi/v/spacy-streamlit.svg?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/spacy-streamlit/)
<img width="50%" align="right" src="https://user-images.githubusercontent.com/13643239/85388081-f2da8700-b545-11ea-9bd4-e303d3c5763c.png">
## 🚀 Quickstart
You can install `spacy-streamlit` from pip:
```bash
pip install spacy-streamlit
```
The package includes **building blocks** that call into Streamlit and set up all
the required elements for you. You can either use the individual components
directly and combine them with other elements in your app, or call the
`visualize` function to embed the whole visualizer.
Download the English model from spaCy to get started.
```bash
python -m spacy download en_core_web_sm
```
Then put the following example code in a file.
```python
# streamlit_app.py
import spacy_streamlit
models = ["en_core_web_sm", "en_core_web_md"]
default_text = "Sundar Pichai is the CEO of Google."
spacy_streamlit.visualize(models, default_text)
```
You can then run your app with `streamlit run streamlit_app.py`. The app should
pop up in your web browser. 😀
#### 📦 Example: [`01_out-of-the-box.py`](examples/01_out-of-the-box.py)
Use the embedded visualizer with custom settings out-of-the-box.
```bash
streamlit run https://raw.githubusercontent.com/explosion/spacy-streamlit/master/examples/01_out-of-the-box.py
```
#### 👑 Example: [`02_custom.py`](examples/02_custom.py)
Use individual components in your existing app.
```bash
streamlit run https://raw.githubusercontent.com/explosion/spacy-streamlit/master/examples/02_custom.py
```
## 🎛 API
### Visualizer components
These functions can be used in your Streamlit app. They call into `streamlit`
under the hood and set up the required elements.
#### <kbd>function</kbd> `visualize`
Embed the full visualizer with selected components.
```python
import spacy_streamlit
models = ["en_core_web_sm", "/path/to/model"]
default_text = "Sundar Pichai is the CEO of Google."
visualizers = ["ner", "textcat"]
spacy_streamlit.visualize(models, default_text, visualizers)
```
| Argument | Type | Description |
| ------------------------ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `models` | List[str] / Dict[str, str] | Names of loadable spaCy models (paths or package names). The models become selectable via a dropdown. Can either be a list of names or the names mapped to descriptions to display in the dropdown. |
| `default_text` | str | Default text to analyze on load. Defaults to `""`. |
| `default_model` | Optional[str] | Optional name of default model. If not set, the first model in the list of `models` is used. |
| `visualizers` | List[str] | Names of visualizers to show. Defaults to `["parser", "ner", "textcat", "similarity", "tokens"]`. |
| `ner_labels` | Optional[List[str]] | NER labels to include. If not set, all labels present in the `"ner"` pipeline component will be used. |
| `ner_attrs` | List[str] | Span attributes shown in table of named entities. See [`visualizer.py`](spacy_streamlit/visualizer.py) for defaults. |
| `token_attrs` | List[str] | Token attributes to show in token visualizer. See [`visualizer.py`](spacy_streamlit/visualizer.py) for defaults. |
| `similarity_texts` | Tuple[str, str] | The default texts to compare in the similarity visualizer. Defaults to `("apple", "orange")`. |
| `show_json_doc` | bool | Show button to toggle JSON representation of the `Doc`. Defaults to `True`. |
| `show_meta` | bool | Show button to toggle `meta.json` of the current pipeline. Defaults to `True`. |
| `show_config` | bool | Show button to toggle `config.cfg` of the current pipeline. Defaults to `True`. |
| `show_visualizer_select` | bool | Show sidebar dropdown to select visualizers to display (based on enabled visualizers). Defaults to `False`. |
| `sidebar_title` | Optional[str] | Title shown in the sidebar. Defaults to `None`. |
| `sidebar_description` | Optional[str] | Description shown in the sidebar. Accepts Markdown-formatted text. |
| `show_logo` | bool | Show the spaCy logo in the sidebar. Defaults to `True`. |
| `color` | Optional[str] | Experimental: Primary color to use for some of the main UI elements (`None` to disable hack). Defaults to `"#09A3D5"`. |
| `get_default_text` | Callable[[Language], str] | Optional callable that takes the currently loaded `nlp` object and returns the default text. Can be used to provide language-specific default texts. If the function returns `None`, the value of `default_text` is used, if available. Defaults to `None`. |
#### <kbd>function</kbd> `visualize_parser`
Visualize the dependency parse and part-of-speech tags using spaCy's
[`displacy` visualizer](https://spacy.io/usage/visualizers).
```python
import spacy
from spacy_streamlit import visualize_parser
nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a text")
visualize_parser(doc)
```
| Argument | Type | Description |
| ------------------ | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `doc` | `Doc` | The spaCy `Doc` object to visualize. |
| _keyword-only_ | | |
| `title` | Optional[str] | Title of the visualizer block. |
| `key` | Optional[str] | Key used for the streamlit component for selecting labels. |
| `manual` | bool | Flag signifying whether the doc argument is a Doc object or a List of Dicts containing parse information. |
| `displacy_optoins` | Optional[Dict] | Dictionary of options to be passed to the displacy render method for generating the HTML to be rendered. See: https://spacy.io/api/top-level#options-dep |
#### <kbd>function</kbd> `visualize_ner`
Visualize the named entities in a `Doc` using spaCy's
[`displacy` visualizer](https://spacy.io/usage/visualizers).
```python
import spacy
from spacy_streamlit import visualize_ner
nlp = spacy.load("en_core_web_sm")
doc = nlp("Sundar Pichai is the CEO of Google.")
visualize_ner(doc, labels=nlp.get_pipe("ner").labels)
```
| Argument | Type | Description |
| ------------------ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `doc` | `Doc` | The spaCy `Doc` object to visualize. |
| _keyword-only_ | | |
| `labels` | Sequence[str] | The labels to show in the labels dropdown. |
| `attrs` | List[str] | The span attributes to show in entity table. |
| `show_table` | bool | Whether to show a table of entities and their attributes. Defaults to `True`. |
| `title` | Optional[str] | Title of the visualizer block. |
| `colors` | Dict[str,str] | Dictionary of colors for the entity spans to visualize, with keys as labels and corresponding colors as the values. This argument will be deprecated soon. In future the colors arg need to be passed in the `displacy_options` arg with the key "colors".) |
| `key` | Optional[str] | Key used for the streamlit component for selecting labels. |
| `manual` | bool | Flag signifying whether the doc argument is a Doc object or a List of Dicts containing entity span |
| information. |
| `displacy_options` | Optional[Dict] | Dictionary of options to be passed to the displacy render method for generating the HTML to be rendered. See https://spacy.io/api/top-level#displacy_options-ent. |
#### <kbd>function</kbd> `visualize_spans`
Visualize spans in a `Doc` using spaCy's
[`displacy` visualizer](https://spacy.io/usage/visualizers).
```python
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"}})
```
| Argument | Type | Description |
| ------------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `doc` | `Doc` | The spaCy `Doc` object to visualize. |
| _keyword-only_ | | |
| `spans_key` | Sequence[str] | Which spans key to render spans from. Default is "sc". |
| `attrs` | List[str] | The attributes on the entity Span to be labeled. Attributes are displayed only when the `show_table` argument is True. |
| `show_table` | bool | Whether to show a table of spans and their attributes. Defaults to `True`. |
| `title` | Optional[str] | Title of the visualizer block. |
| `manual` | bool | Flag signifying whether the doc argument is a Doc object or a List of Dicts containing entity span information. |
| `displacy_options` | Optional[Dict] | Dictionary of options to be passed to the displacy render method for generating the HTML to be rendered. See https://spacy.io/api/top-level#displacy_options-span. |
#### <kbd>function</kbd> `visualize_textcat`
Visualize text categories predicted by a trained text classifier.
```python
import spacy
from spacy_streamlit import visualize_textcat
nlp = spacy.load("./my_textcat_model")
doc = nlp("This is a text about a topic")
visualize_textcat(doc)
```
| Argument | Type | Description |
| -------------- | ------------- | ------------------------------------ |
| `doc` | `Doc` | The spaCy `Doc` object to visualize. |
| _keyword-only_ | | |
| `title` | Optional[str] | Title of the visualizer block. |
#### `visualize_similarity`
Visualize semantic similarity using the model's word vectors. Will show a
warning if no vectors are present in the model.
```python
import spacy
from spacy_streamlit import visualize_similarity
nlp = spacy.load("en_core_web_lg")
visualize_similarity(nlp, ("pizza", "fries"))
```
| Argument | Type | Description |
| --------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `nlp` | `Language` | The loaded `nlp` object with vectors. |
| `default_texts` | Tuple[str, str] | The default texts to compare on load. Defaults to `("apple", "orange")`. |
| _keyword-only_ | | |
| `threshold` | float | Threshold for what's considered "similar". If the similarity score is greater than the threshold, the result is shown as similar. Defaults to `0.5`. |
| `title` | Optional[str] | Title of the visualizer block. |
#### <kbd>function</kbd> `visualize_tokens`
Visualize the tokens in a `Doc` and their attributes.
```python
import spacy
from spacy_streamlit import visualize_tokens
nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a text")
visualize_tokens(doc, attrs=["text", "pos_", "dep_", "ent_type_"])
```
| Argument | Type | Description |
| -------------- | ------------- | -------------------------------------------------------------------------------------------------------- |
| `doc` | `Doc` | The spaCy `Doc` object to visualize. |
| _keyword-only_ | | |
| `attrs` | List[str] | The names of token attributes to use. See [`visualizer.py`](spacy_streamlit/visualizer.py) for defaults. |
| `title` | Optional[str] | Title of the visualizer block. |
### Cached helpers
These helpers attempt to cache loaded models and created `Doc` objects.
#### <kbd>function</kbd> `process_text`
Process a text with a model of a given name and create a `Doc` object. Calls
into the `load_model` helper to load the model.
```python
import streamlit as st
from spacy_streamlit import process_text
spacy_model = st.sidebar.selectbox("Model name", ["en_core_web_sm", "en_core_web_md"])
text = st.text_area("Text to analyze", "This is a text")
doc = process_text(spacy_model, text)
```
| Argument | Type | Description |
| ------------ | ----- | ------------------------------------------------------- |
| `model_name` | str | Loadable spaCy model name. Can be path or package name. |
| `text` | str | The text to process. |
| **RETURNS** | `Doc` | The processed document. |
#### <kbd>function</kbd> `load_model`
Load a spaCy model from a path or installed package and return a loaded `nlp`
object.
```python
import streamlit as st
from spacy_streamlit import load_model
spacy_model = st.sidebar.selectbox("Model name", ["en_core_web_sm", "en_core_web_md"])
nlp = load_model(spacy_model)
```
| Argument | Type | Description |
| ----------- | ---------- | ------------------------------------------------------- |
| `name` | str | Loadable spaCy model name. Can be path or package name. |
| **RETURNS** | `Language` | The loaded `nlp` object. |
Raw data
{
"_id": null,
"home_page": "https://github.com/explosion/spacy-streamlit",
"name": "spacy-streamlit",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Explosion",
"author_email": "contact@explosion.ai",
"download_url": "https://files.pythonhosted.org/packages/78/91/72a4817b31db40b5346d3246464743b6e7bbe2ea75f4693a6affd3c11166/spacy_streamlit-1.0.6.tar.gz",
"platform": null,
"description": "<a href=\"https://explosion.ai\"><img src=\"https://explosion.ai/assets/img/logo.svg\" width=\"125\" height=\"125\" align=\"right\" /></a>\n\n# spacy-streamlit: spaCy building blocks for Streamlit apps\n\nThis package contains utilities for visualizing [spaCy](https://spacy.io) models\nand building interactive spaCy-powered apps with\n[Streamlit](https://streamlit.io). It includes various building blocks you can\nuse in your own Streamlit app, like visualizers for **syntactic dependencies**,\n**named entities**, **text classification**, **semantic similarity** via word\nvectors, token attributes, and more.\n\n[![Current Release Version](https://img.shields.io/github/release/explosion/spacy-streamlit.svg?style=flat-square&logo=github&include_prereleases)](https://github.com/explosion/spacy-streamlit/releases)\n[![pypi Version](https://img.shields.io/pypi/v/spacy-streamlit.svg?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/spacy-streamlit/)\n\n<img width=\"50%\" align=\"right\" src=\"https://user-images.githubusercontent.com/13643239/85388081-f2da8700-b545-11ea-9bd4-e303d3c5763c.png\">\n\n## \ud83d\ude80 Quickstart\n\nYou can install `spacy-streamlit` from pip:\n\n```bash\npip install spacy-streamlit\n```\n\nThe package includes **building blocks** that call into Streamlit and set up all\nthe required elements for you. You can either use the individual components\ndirectly and combine them with other elements in your app, or call the\n`visualize` function to embed the whole visualizer.\n\nDownload the English model from spaCy to get started.\n\n```bash\npython -m spacy download en_core_web_sm\n```\n\nThen put the following example code in a file.\n\n```python\n# streamlit_app.py\nimport spacy_streamlit\n\nmodels = [\"en_core_web_sm\", \"en_core_web_md\"]\ndefault_text = \"Sundar Pichai is the CEO of Google.\"\nspacy_streamlit.visualize(models, default_text)\n```\n\nYou can then run your app with `streamlit run streamlit_app.py`. The app should\npop up in your web browser. \ud83d\ude00\n\n#### \ud83d\udce6 Example: [`01_out-of-the-box.py`](examples/01_out-of-the-box.py)\n\nUse the embedded visualizer with custom settings out-of-the-box.\n\n```bash\nstreamlit run https://raw.githubusercontent.com/explosion/spacy-streamlit/master/examples/01_out-of-the-box.py\n```\n\n#### \ud83d\udc51 Example: [`02_custom.py`](examples/02_custom.py)\n\nUse individual components in your existing app.\n\n```bash\nstreamlit run https://raw.githubusercontent.com/explosion/spacy-streamlit/master/examples/02_custom.py\n```\n\n## \ud83c\udf9b API\n\n### Visualizer components\n\nThese functions can be used in your Streamlit app. They call into `streamlit`\nunder the hood and set up the required elements.\n\n#### <kbd>function</kbd> `visualize`\n\nEmbed the full visualizer with selected components.\n\n```python\nimport spacy_streamlit\n\nmodels = [\"en_core_web_sm\", \"/path/to/model\"]\ndefault_text = \"Sundar Pichai is the CEO of Google.\"\nvisualizers = [\"ner\", \"textcat\"]\nspacy_streamlit.visualize(models, default_text, visualizers)\n```\n\n| Argument | Type | Description |\n| ------------------------ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `models` | List[str] / Dict[str, str] | Names of loadable spaCy models (paths or package names). The models become selectable via a dropdown. Can either be a list of names or the names mapped to descriptions to display in the dropdown. |\n| `default_text` | str | Default text to analyze on load. Defaults to `\"\"`. |\n| `default_model` | Optional[str] | Optional name of default model. If not set, the first model in the list of `models` is used. |\n| `visualizers` | List[str] | Names of visualizers to show. Defaults to `[\"parser\", \"ner\", \"textcat\", \"similarity\", \"tokens\"]`. |\n| `ner_labels` | Optional[List[str]] | NER labels to include. If not set, all labels present in the `\"ner\"` pipeline component will be used. |\n| `ner_attrs` | List[str] | Span attributes shown in table of named entities. See [`visualizer.py`](spacy_streamlit/visualizer.py) for defaults. |\n| `token_attrs` | List[str] | Token attributes to show in token visualizer. See [`visualizer.py`](spacy_streamlit/visualizer.py) for defaults. |\n| `similarity_texts` | Tuple[str, str] | The default texts to compare in the similarity visualizer. Defaults to `(\"apple\", \"orange\")`. |\n| `show_json_doc` | bool | Show button to toggle JSON representation of the `Doc`. Defaults to `True`. |\n| `show_meta` | bool | Show button to toggle `meta.json` of the current pipeline. Defaults to `True`. |\n| `show_config` | bool | Show button to toggle `config.cfg` of the current pipeline. Defaults to `True`. |\n| `show_visualizer_select` | bool | Show sidebar dropdown to select visualizers to display (based on enabled visualizers). Defaults to `False`. |\n| `sidebar_title` | Optional[str] | Title shown in the sidebar. Defaults to `None`. |\n| `sidebar_description` | Optional[str] | Description shown in the sidebar. Accepts Markdown-formatted text. |\n| `show_logo` | bool | Show the spaCy logo in the sidebar. Defaults to `True`. |\n| `color` | Optional[str] | Experimental: Primary color to use for some of the main UI elements (`None` to disable hack). Defaults to `\"#09A3D5\"`. |\n| `get_default_text` | Callable[[Language], str] | Optional callable that takes the currently loaded `nlp` object and returns the default text. Can be used to provide language-specific default texts. If the function returns `None`, the value of `default_text` is used, if available. Defaults to `None`. |\n\n#### <kbd>function</kbd> `visualize_parser`\n\nVisualize the dependency parse and part-of-speech tags using spaCy's\n[`displacy` visualizer](https://spacy.io/usage/visualizers).\n\n```python\nimport spacy\nfrom spacy_streamlit import visualize_parser\n\nnlp = spacy.load(\"en_core_web_sm\")\ndoc = nlp(\"This is a text\")\nvisualize_parser(doc)\n```\n\n| Argument | Type | Description |\n| ------------------ | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `doc` | `Doc` | The spaCy `Doc` object to visualize. |\n| _keyword-only_ | | |\n| `title` | Optional[str] | Title of the visualizer block. |\n| `key` | Optional[str] | Key used for the streamlit component for selecting labels. |\n| `manual` | bool | Flag signifying whether the doc argument is a Doc object or a List of Dicts containing parse information. |\n| `displacy_optoins` | Optional[Dict] | Dictionary of options to be passed to the displacy render method for generating the HTML to be rendered. See: https://spacy.io/api/top-level#options-dep |\n\n#### <kbd>function</kbd> `visualize_ner`\n\nVisualize the named entities in a `Doc` using spaCy's\n[`displacy` visualizer](https://spacy.io/usage/visualizers).\n\n```python\nimport spacy\nfrom spacy_streamlit import visualize_ner\n\nnlp = spacy.load(\"en_core_web_sm\")\ndoc = nlp(\"Sundar Pichai is the CEO of Google.\")\nvisualize_ner(doc, labels=nlp.get_pipe(\"ner\").labels)\n```\n\n| Argument | Type | Description |\n| ------------------ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `doc` | `Doc` | The spaCy `Doc` object to visualize. |\n| _keyword-only_ | | |\n| `labels` | Sequence[str] | The labels to show in the labels dropdown. |\n| `attrs` | List[str] | The span attributes to show in entity table. |\n| `show_table` | bool | Whether to show a table of entities and their attributes. Defaults to `True`. |\n| `title` | Optional[str] | Title of the visualizer block. |\n| `colors` | Dict[str,str] | Dictionary of colors for the entity spans to visualize, with keys as labels and corresponding colors as the values. This argument will be deprecated soon. In future the colors arg need to be passed in the `displacy_options` arg with the key \"colors\".) |\n| `key` | Optional[str] | Key used for the streamlit component for selecting labels. |\n| `manual` | bool | Flag signifying whether the doc argument is a Doc object or a List of Dicts containing entity span |\n| information. |\n| `displacy_options` | Optional[Dict] | Dictionary of options to be passed to the displacy render method for generating the HTML to be rendered. See https://spacy.io/api/top-level#displacy_options-ent. |\n\n\n#### <kbd>function</kbd> `visualize_spans`\n\nVisualize spans in a `Doc` using spaCy's\n[`displacy` visualizer](https://spacy.io/usage/visualizers).\n\n```python\nimport spacy\nfrom spacy_streamlit import visualize_spans\n\nnlp = spacy.load(\"en_core_web_sm\")\ndoc = nlp(\"Sundar Pichai is the CEO of Google.\")\nspan = doc[4:7] # CEO of Google\nspan.label_ = \"CEO\"\ndoc.spans[\"job_role\"] = [span]\nvisualize_spans(doc, spans_key=\"job_role\", displacy_options={\"colors\": {\"CEO\": \"#09a3d5\"}})\n```\n\n| Argument | Type | Description |\n| ------------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `doc` | `Doc` | The spaCy `Doc` object to visualize. |\n| _keyword-only_ | | |\n| `spans_key` | Sequence[str] | Which spans key to render spans from. Default is \"sc\". |\n| `attrs` | List[str] | The attributes on the entity Span to be labeled. Attributes are displayed only when the `show_table` argument is True. |\n| `show_table` | bool | Whether to show a table of spans and their attributes. Defaults to `True`. |\n| `title` | Optional[str] | Title of the visualizer block. |\n| `manual` | bool | Flag signifying whether the doc argument is a Doc object or a List of Dicts containing entity span information. |\n| `displacy_options` | Optional[Dict] | Dictionary of options to be passed to the displacy render method for generating the HTML to be rendered. See https://spacy.io/api/top-level#displacy_options-span. |\n\n\n#### <kbd>function</kbd> `visualize_textcat`\n\nVisualize text categories predicted by a trained text classifier.\n\n```python\nimport spacy\nfrom spacy_streamlit import visualize_textcat\n\nnlp = spacy.load(\"./my_textcat_model\")\ndoc = nlp(\"This is a text about a topic\")\nvisualize_textcat(doc)\n```\n\n| Argument | Type | Description |\n| -------------- | ------------- | ------------------------------------ |\n| `doc` | `Doc` | The spaCy `Doc` object to visualize. |\n| _keyword-only_ | | |\n| `title` | Optional[str] | Title of the visualizer block. |\n\n#### `visualize_similarity`\n\nVisualize semantic similarity using the model's word vectors. Will show a\nwarning if no vectors are present in the model.\n\n```python\nimport spacy\nfrom spacy_streamlit import visualize_similarity\n\nnlp = spacy.load(\"en_core_web_lg\")\nvisualize_similarity(nlp, (\"pizza\", \"fries\"))\n```\n\n| Argument | Type | Description |\n| --------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `nlp` | `Language` | The loaded `nlp` object with vectors. |\n| `default_texts` | Tuple[str, str] | The default texts to compare on load. Defaults to `(\"apple\", \"orange\")`. |\n| _keyword-only_ | | |\n| `threshold` | float | Threshold for what's considered \"similar\". If the similarity score is greater than the threshold, the result is shown as similar. Defaults to `0.5`. |\n| `title` | Optional[str] | Title of the visualizer block. |\n\n#### <kbd>function</kbd> `visualize_tokens`\n\nVisualize the tokens in a `Doc` and their attributes.\n\n```python\nimport spacy\nfrom spacy_streamlit import visualize_tokens\n\nnlp = spacy.load(\"en_core_web_sm\")\ndoc = nlp(\"This is a text\")\nvisualize_tokens(doc, attrs=[\"text\", \"pos_\", \"dep_\", \"ent_type_\"])\n```\n\n| Argument | Type | Description |\n| -------------- | ------------- | -------------------------------------------------------------------------------------------------------- |\n| `doc` | `Doc` | The spaCy `Doc` object to visualize. |\n| _keyword-only_ | | |\n| `attrs` | List[str] | The names of token attributes to use. See [`visualizer.py`](spacy_streamlit/visualizer.py) for defaults. |\n| `title` | Optional[str] | Title of the visualizer block. |\n\n### Cached helpers\n\nThese helpers attempt to cache loaded models and created `Doc` objects.\n\n#### <kbd>function</kbd> `process_text`\n\nProcess a text with a model of a given name and create a `Doc` object. Calls\ninto the `load_model` helper to load the model.\n\n```python\nimport streamlit as st\nfrom spacy_streamlit import process_text\n\nspacy_model = st.sidebar.selectbox(\"Model name\", [\"en_core_web_sm\", \"en_core_web_md\"])\ntext = st.text_area(\"Text to analyze\", \"This is a text\")\ndoc = process_text(spacy_model, text)\n```\n\n| Argument | Type | Description |\n| ------------ | ----- | ------------------------------------------------------- |\n| `model_name` | str | Loadable spaCy model name. Can be path or package name. |\n| `text` | str | The text to process. |\n| **RETURNS** | `Doc` | The processed document. |\n\n#### <kbd>function</kbd> `load_model`\n\nLoad a spaCy model from a path or installed package and return a loaded `nlp`\nobject.\n\n```python\nimport streamlit as st\nfrom spacy_streamlit import load_model\n\nspacy_model = st.sidebar.selectbox(\"Model name\", [\"en_core_web_sm\", \"en_core_web_md\"])\nnlp = load_model(spacy_model)\n```\n\n| Argument | Type | Description |\n| ----------- | ---------- | ------------------------------------------------------- |\n| `name` | str | Loadable spaCy model name. Can be path or package name. |\n| **RETURNS** | `Language` | The loaded `nlp` object. |\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Visualize spaCy with streamlit",
"version": "1.0.6",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "288bf762777bcfffd47a757c0684424ef390849df5f72c9325ad3458ea47cf59",
"md5": "16a487c03ebebed3321fdf97bed46674",
"sha256": "00b829b25b349eec5cd012274b233ee8909301af7fdc9c128c9affd877bcb7b6"
},
"downloads": -1,
"filename": "spacy_streamlit-1.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "16a487c03ebebed3321fdf97bed46674",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 12374,
"upload_time": "2023-04-25T09:42:45",
"upload_time_iso_8601": "2023-04-25T09:42:45.748130Z",
"url": "https://files.pythonhosted.org/packages/28/8b/f762777bcfffd47a757c0684424ef390849df5f72c9325ad3458ea47cf59/spacy_streamlit-1.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "789172a4817b31db40b5346d3246464743b6e7bbe2ea75f4693a6affd3c11166",
"md5": "ccfebd9ada8c12e875e48733d56f709f",
"sha256": "4a54df591f5d4c031e3af3540f58a84c79be741e2583beb21b9d1bd654790750"
},
"downloads": -1,
"filename": "spacy_streamlit-1.0.6.tar.gz",
"has_sig": false,
"md5_digest": "ccfebd9ada8c12e875e48733d56f709f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 14603,
"upload_time": "2023-04-25T09:42:48",
"upload_time_iso_8601": "2023-04-25T09:42:48.191529Z",
"url": "https://files.pythonhosted.org/packages/78/91/72a4817b31db40b5346d3246464743b6e7bbe2ea75f4693a6affd3c11166/spacy_streamlit-1.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-25 09:42:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "explosion",
"github_project": "spacy-streamlit",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "streamlit",
"specs": [
[
">=",
"1.18.0"
]
]
},
{
"name": "spacy",
"specs": [
[
">=",
"3.0.0"
],
[
"<",
"4.0.0"
]
]
},
{
"name": "pandas",
"specs": []
}
],
"lcname": "spacy-streamlit"
}