-
Notifications
You must be signed in to change notification settings - Fork 0
/
labeler.py
61 lines (48 loc) · 1.45 KB
/
labeler.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
import streamlit as st
st.title("Data Preparation")
if "data" not in st.session_state:
st.session_state["data"] = []
def save(title, text, source):
if len(title.strip()) == 0:
st.warning("Title cannot be empty")
return
if len(text.strip()) == 0:
st.warning("Text cannot be empty")
return
if len(source.strip()) == 0:
st.warning("Source cannot be empty")
return
#st.session_state["title"] = ""
st.session_state["text"] = ""
#st.session_state["source"] = ""
st.session_state["data"] += [
{"text": text, "source_document": source, "title": title}
]
def load():
st.markdown(
"""
<style>
div[data-testid="column"]:nth-of-type(3)
{
text-align: end;
}
</style>
""",
unsafe_allow_html=True,
)
title = st.text_input(label="Title", key="title")
text = st.text_area(label="Text", key="text")
source = st.text_input(label="Source", key="source")
col1, col2, col3 = st.columns([1, 1, 1])
with col1:
st.button(label="Submit", on_click=save, args=(title, text, source))
with col3:
st.download_button(
label="Download",
data=json.dumps(st.session_state["data"], indent=4),
file_name="labeled.json",
mime="application/json",
)
if __name__ == "__main__":
load()