File size: 1,226 Bytes
62b4925
 
 
b4ebfe1
62b4925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bad7b8
62b4925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
import json
from json import JSONDecodeError

import streamlit as st
from datasets import Dataset

from spacy_to_hf import spacy_to_hf

demo_option = [
    {
        "text": "Planned to go to the Apple Storefront on Tuesday",
        "spans": [
            {"start": 0, "end": 7, "label": "Action"},
            {"start": 21, "end": 37, "label": "Loc"},
            {"start": 41, "end": 48, "label": "Date"},
        ],
    }
]

tokenizers = [
    "bert-base-uncased",
    "bert-base-cased",
    "distilbert-base-uncased",
    "distilbert-base-cased",
    "roberta-base",
]
tok = st.selectbox("Pick a tokenizer", tokenizers)
spacy_data = st.text_area("Input your NER Span data here")

if spacy_data or st.button("Or try an example"):
    run_data = None
    if spacy_data:
        try:
            run_data = json.loads(spacy_data)
        except JSONDecodeError as e:
            st.warning(f"Invalid JSON data, try again\n{str(e)}")
    else:
        run_data = demo_option
    if run_data:
        st.write("Spacy input data:")
        st.json(run_data)
        hf_data = spacy_to_hf(run_data, tok)
        df = Dataset.from_dict(hf_data).to_pandas()
        st.write("Output huggingface format:")
        st.dataframe(df)