Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,91 +4,89 @@ import copy
|
|
4 |
|
5 |
N = 10
|
6 |
state = st.session_state
|
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 |
st.header("Dataset annotation")
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
#
|
59 |
-
#
|
60 |
-
#
|
61 |
-
#
|
62 |
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
|
69 |
-
|
70 |
-
#
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
|
77 |
|
78 |
-
|
79 |
|
80 |
|
81 |
-
st.button('Submit')
|
82 |
|
83 |
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
# st.info("Everything annotated.")
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
# file_name="annotations_faithfull.csv",
|
94 |
-
# )
|
|
|
4 |
|
5 |
N = 10
|
6 |
state = st.session_state
|
7 |
+
generated_path = 'generated_predictions.txt'
|
8 |
+
|
9 |
+
ORI_RES = f'DUC/results/{generated_path}'
|
10 |
+
# CONTEXT_SENT_0_h_0_RES = f'/home/nlp/wolhanr/mds_faithfull/data/DUC/output_dir/sent_window_0_h_0_clusters/{generated_path}'
|
11 |
+
CONTEXT_SENT_0_h_1_RES = f'DUC/output_dir/sent_window_0_clusters/{generated_path}'
|
12 |
+
CONTEXT_SENT_1_h_1_RES = f'DUC/output_dir/sent_window_1_h_1_clusters/{generated_path}'
|
13 |
+
|
14 |
+
source_path = 'DUC/sent_window_1_h_1_clusters/test.source'
|
15 |
+
|
16 |
+
OPTIONS = ["faithfull", "Not faithfull"]
|
17 |
+
|
18 |
+
if "number_button_fill" not in state:
|
19 |
+
state.number_button_fill = 0
|
20 |
+
|
21 |
+
if "annotations" not in state:
|
22 |
+
state.annotations = {}
|
23 |
+
state.annotations['data_id', 'index', 'output', 'model', 'is_faithfull'] = ''
|
24 |
+
f_0 = open(source_path)
|
25 |
+
source = f_0.read().split('\n')[:N]
|
26 |
+
f_1 = open(ORI_RES)
|
27 |
+
ori_res = f_1.read().split('\n')[:N]
|
28 |
+
# f_2 = open(CONTEXT_SENT_0_h_0_RES)
|
29 |
+
f_3 = open(CONTEXT_SENT_0_h_1_RES)
|
30 |
+
sent_0_h_1 = f_3.read().split('\n')[:N]
|
31 |
+
f_4 = open(CONTEXT_SENT_1_h_1_RES)
|
32 |
+
sent_1_h_1 = f_4.read().split('\n')[:N]
|
33 |
+
state.files = list(zip(source, ori_res, sent_0_h_1, sent_1_h_1))
|
34 |
+
state.current_file = state.files[0]
|
35 |
+
state.counter = 0
|
36 |
+
state.submit = 0
|
37 |
+
|
38 |
+
|
39 |
+
def submit(index_0, index_1, index_2):
|
40 |
+
x = [(index_0, state.a),(index_1, state.b), (index_2, state.c)]
|
41 |
+
x = sorted(x, key=lambda x: x[0])
|
42 |
+
if state.submit == 0:
|
43 |
+
state.annotations[state.counter, x[0][0], state.current_file[1], 'ori_res', x[0][1]] = ''
|
44 |
+
state.annotations[state.counter, x[1][0], state.current_file[2], 'sent_0_h_1', x[1][1]] = ''
|
45 |
+
state.annotations[state.counter, x[2][0], state.current_file[3], 'sent_1_h_1', x[2][1]] = ''
|
46 |
+
state.submit = 1
|
47 |
+
if state.submit == 1:
|
48 |
+
state.files.remove(state.current_file)
|
49 |
+
random.shuffle(state.indexes)
|
50 |
+
state.current_file = state.files[0]
|
51 |
+
state.counter += 1
|
52 |
+
state.submit = 0
|
53 |
|
54 |
st.header("Dataset annotation")
|
55 |
|
56 |
+
if state.files:
|
57 |
+
selected_file = state.current_file
|
58 |
+
# source_file = selected_file[0]
|
59 |
+
# ori_file = selected_file[1]
|
60 |
+
# sent_0_h_1_file = selected_file[2]
|
61 |
+
# sent_1_h_1_file = selected_file[3]
|
62 |
|
63 |
+
st.write(f"Source file: {selected_file[0]}")
|
64 |
|
65 |
+
if 'indexes' not in state:
|
66 |
+
state.indexes = [1, 2, 3]
|
67 |
+
random.shuffle(state.indexes)
|
68 |
|
69 |
+
st.write(f"Output: {selected_file[state.indexes[0]]}")
|
70 |
+
# c = st.columns(len(OPTIONS))
|
71 |
+
state.a = st.radio('a', OPTIONS, key=f'{0}')
|
72 |
+
st.write(f"Output: {selected_file[state.indexes[1]]}")
|
73 |
+
state.b = st.radio('b', OPTIONS, key=f'{1}')
|
74 |
+
st.write(f"Output: {selected_file[state.indexes[2]]}")
|
75 |
+
state.c = st.radio('c', OPTIONS, key=f'{2}')
|
76 |
|
77 |
|
78 |
+
st.button('Submit', on_click=submit, args=(copy.deepcopy(state.indexes)))
|
79 |
|
80 |
|
|
|
81 |
|
82 |
|
83 |
+
else:
|
84 |
+
st.info("Everything annotated.")
|
85 |
|
86 |
+
st.info(f"Annotated: {len(state.annotations)}, Remaining: {len(state.files)}")
|
|
|
87 |
|
88 |
+
st.download_button(
|
89 |
+
"Download annotations as CSV",
|
90 |
+
"\n".join([f"{k}\t{v}" for k, v in state.annotations.items()]),
|
91 |
+
file_name="annotations_faithfull.csv",
|
92 |
+
)
|
|
|
|