File size: 1,122 Bytes
e23402e
 
 
 
 
 
 
 
855e5bd
e23402e
73df8ac
 
 
 
 
 
 
 
 
 
 
e23402e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import spacy_streamlit
from pathlib import Path
import srsly
import importlib
import random

DEFAULT_MODEL = "en_core_web_sm"
DEFAULT_TEXT = "David Bowie moved to the US in 1974, initially staying in New York City before settling in Los Angeles."
DESCRIPTION = """**Explore trained [spaCy v3.2](https://nightly.spacy.io) pipelines**"""

def get_all_models():
   with open("requirements.txt") as f:
    content = f.readlines()
    models = []
    for line in content:
        if "huggingface.co" in line:
            models.append(line.split("/")[4])
    return models

MODELS = get_all_models()

def get_default_text(nlp):
    # Check if spaCy has built-in example texts for the language
    try:
        examples = importlib.import_module(f".lang.{nlp.lang}.examples", "spacy")
        return examples.sentences[0]
    except (ModuleNotFoundError, ImportError):
        return ""

spacy_streamlit.visualize(
    MODELS,
    default_model=DEFAULT_MODEL,
    visualizers=["parser", "ner", "similarity", "tokens"],
    show_visualizer_select=True,
    sidebar_description=DESCRIPTION,
    get_default_text=get_default_text
)