Spaces:
Runtime error
Runtime error
Commit
·
62b4925
1
Parent(s):
93c9b8d
Upload 2 files
Browse files- app.py +43 -2
- requirements.txt +4 -0
app.py
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from json import JSONDecodeError
|
| 3 |
+
|
| 4 |
import streamlit as st
|
| 5 |
+
from datasets import Dataset
|
| 6 |
+
|
| 7 |
+
from spacy_to_hf import spacy_to_hf
|
| 8 |
+
|
| 9 |
+
demo_option = [
|
| 10 |
+
{
|
| 11 |
+
"text": "Planned to go to the Apple Storefront on Tuesday",
|
| 12 |
+
"spans": [
|
| 13 |
+
{"start": 0, "end": 7, "label": "Action"},
|
| 14 |
+
{"start": 21, "end": 37, "label": "Loc"},
|
| 15 |
+
{"start": 41, "end": 48, "label": "Date"},
|
| 16 |
+
],
|
| 17 |
+
}
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
tokenizers = [
|
| 21 |
+
"bert-base-uncased",
|
| 22 |
+
"bert-base-cased",
|
| 23 |
+
"distilbert-base-uncased",
|
| 24 |
+
"distilbert-base-cased",
|
| 25 |
+
"roberta-base",
|
| 26 |
+
]
|
| 27 |
+
tok = st.selectbox("Pick a tokenizer", tokenizers)
|
| 28 |
+
spacy_data = st.text_area("Input your NER Span data here")
|
| 29 |
|
| 30 |
+
if spacy_data or st.button("Or try an example"):
|
| 31 |
+
run_data = None
|
| 32 |
+
if spacy_data:
|
| 33 |
+
try:
|
| 34 |
+
run_data = json.loads(spacy_data)
|
| 35 |
+
except JSONDecodeError as e:
|
| 36 |
+
st.warning(f"Invalid JSON data, try again\n{str(e)}")
|
| 37 |
+
else:
|
| 38 |
+
run_data = demo_option
|
| 39 |
+
if run_data:
|
| 40 |
+
st.write("Spacy input data:")
|
| 41 |
+
st.json(run_data)
|
| 42 |
+
hf_data = spacy_to_hf(run_data, tok)
|
| 43 |
+
df = Dataset.from_dict(hf_data).to_pandas()
|
| 44 |
+
st.write("Output huggingface format:")
|
| 45 |
+
st.dataframe(df)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
spacy-to-hf
|
| 3 |
+
datasets
|
| 4 |
+
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm
|