Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,22 +34,20 @@ def save_annotations_as_json(annotated_text, filename):
|
|
34 |
with open(filename, 'w', encoding='utf-8') as json_file:
|
35 |
json.dump(annotated_text, json_file, ensure_ascii=False, indent=4)
|
36 |
|
37 |
-
# Define the layout
|
38 |
st.title("Annotation Tool")
|
|
|
|
|
39 |
st.markdown('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">', unsafe_allow_html=True)
|
40 |
|
41 |
-
# Input text area
|
42 |
text = st.text_area("Text")
|
43 |
if st.button("Annotate"):
|
44 |
if text:
|
45 |
segmented_text = tokenize_with_spacy(text)
|
46 |
annotated_text = annotate_text(segmented_text)
|
47 |
-
|
48 |
st.subheader("Segmented Text:")
|
49 |
-
|
50 |
-
st.write(token)
|
51 |
-
|
52 |
st.subheader("Annotated Text:")
|
|
|
53 |
for token in annotated_text:
|
54 |
st.write(f"Token: {token['token']}")
|
55 |
st.write(f"POS: {token['pos']}")
|
@@ -64,14 +62,17 @@ if st.button("Annotate"):
|
|
64 |
st.write(f"Case: {', '.join(token['case'])}")
|
65 |
st.write(f"Gender: {', '.join(token['gender'])}")
|
66 |
st.write("-----")
|
|
|
67 |
else:
|
68 |
st.warning("Please enter some text.")
|
69 |
|
70 |
if st.button("Save Modifications as JSON"):
|
71 |
if annotated_text:
|
|
|
72 |
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
73 |
filename = f'annotations_{timestamp}.json'
|
74 |
save_annotations_as_json(annotated_text, filename)
|
75 |
st.success(f"Annotations saved as {filename}")
|
76 |
|
|
|
77 |
st.markdown('<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>', unsafe_allow_html=True)
|
|
|
34 |
with open(filename, 'w', encoding='utf-8') as json_file:
|
35 |
json.dump(annotated_text, json_file, ensure_ascii=False, indent=4)
|
36 |
|
|
|
37 |
st.title("Annotation Tool")
|
38 |
+
|
39 |
+
# Add Materialize CSS
|
40 |
st.markdown('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">', unsafe_allow_html=True)
|
41 |
|
|
|
42 |
text = st.text_area("Text")
|
43 |
if st.button("Annotate"):
|
44 |
if text:
|
45 |
segmented_text = tokenize_with_spacy(text)
|
46 |
annotated_text = annotate_text(segmented_text)
|
|
|
47 |
st.subheader("Segmented Text:")
|
48 |
+
st.write(segmented_text)
|
|
|
|
|
49 |
st.subheader("Annotated Text:")
|
50 |
+
|
51 |
for token in annotated_text:
|
52 |
st.write(f"Token: {token['token']}")
|
53 |
st.write(f"POS: {token['pos']}")
|
|
|
62 |
st.write(f"Case: {', '.join(token['case'])}")
|
63 |
st.write(f"Gender: {', '.join(token['gender'])}")
|
64 |
st.write("-----")
|
65 |
+
|
66 |
else:
|
67 |
st.warning("Please enter some text.")
|
68 |
|
69 |
if st.button("Save Modifications as JSON"):
|
70 |
if annotated_text:
|
71 |
+
# Generate a unique file name using a timestamp
|
72 |
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
73 |
filename = f'annotations_{timestamp}.json'
|
74 |
save_annotations_as_json(annotated_text, filename)
|
75 |
st.success(f"Annotations saved as {filename}")
|
76 |
|
77 |
+
# Add Materialize JavaScript
|
78 |
st.markdown('<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>', unsafe_allow_html=True)
|