osanseviero's picture
osanseviero
HF staff
Update app.py 855e5bd
1
import spacy_streamlit
2
from pathlib import Path
3
import srsly
4
import importlib
5
import random
6
7
DEFAULT_MODEL = "en_core_web_sm"
8
DEFAULT_TEXT = "David Bowie moved to the US in 1974, initially staying in New York City before settling in Los Angeles."
9
DESCRIPTION = """**Explore trained [spaCy v3.2](https://nightly.spacy.io) pipelines**"""
10
11
def get_all_models():
12
   with open("requirements.txt") as f:
13
    content = f.readlines()
14
    models = []
15
    for line in content:
16
        if "huggingface.co" in line:
17
            models.append(line.split("/")[4])
18
    return models
19
20
MODELS = get_all_models()
21
22
def get_default_text(nlp):
23
    # Check if spaCy has built-in example texts for the language
24
    try:
25
        examples = importlib.import_module(f".lang.{nlp.lang}.examples", "spacy")
26
        return examples.sentences[0]
27
    except (ModuleNotFoundError, ImportError):
28
        return ""
29
30
spacy_streamlit.visualize(
31
    MODELS,
32
    default_model=DEFAULT_MODEL,
33
    visualizers=["parser", "ner", "similarity", "tokens"],
34
    show_visualizer_select=True,
35
    sidebar_description=DESCRIPTION,
36
    get_default_text=get_default_text
37
)