Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +50 -0
- data_streamlit_align.csv +0 -0
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
state = st.session_state
|
5 |
+
path = 'data_streamlit_align.csv'
|
6 |
+
OPTIONS = ["faithfull", "Not faithfull"]
|
7 |
+
|
8 |
+
if "number_button_fill" not in state:
|
9 |
+
state.number_button_fill = 0
|
10 |
+
|
11 |
+
if "annotations" not in state:
|
12 |
+
state.annotations = {}
|
13 |
+
state.files = pd.read_csv(path)
|
14 |
+
state.current_file = 0
|
15 |
+
state.counter = 0
|
16 |
+
state.submit = 0
|
17 |
+
|
18 |
+
|
19 |
+
def submit():
|
20 |
+
if state.submit == 0:
|
21 |
+
state.annotations[state.files.iloc[state.current_file]['topic_id']] = state.a
|
22 |
+
state.submit = 1
|
23 |
+
if state.submit == 1:
|
24 |
+
state.current_file += 1
|
25 |
+
state.counter += 1
|
26 |
+
state.submit = 0
|
27 |
+
|
28 |
+
st.title("Dataset annotation")
|
29 |
+
|
30 |
+
if state.current_file < len(state.files):
|
31 |
+
selected_file = state.files.iloc[state.current_file]
|
32 |
+
st.header(f'Topic id : {selected_file["topic_id"]}')
|
33 |
+
for i, document in enumerate(selected_file['document'].split('|||||')):
|
34 |
+
st.markdown(f"**Document {i+1}:**")
|
35 |
+
st.write(f"{document}", unsafe_allow_html=True)
|
36 |
+
st.header('Summary:')
|
37 |
+
st.write(f"{selected_file['summary']}", unsafe_allow_html=True)
|
38 |
+
state.a = st.radio('a', OPTIONS)
|
39 |
+
st.button('Next', on_click=submit)
|
40 |
+
|
41 |
+
else:
|
42 |
+
st.info("Everything annotated.")
|
43 |
+
|
44 |
+
st.info(f"Annotated: {len(state.annotations)}, Remaining: {len(state.files)-len(state.annotations)}")
|
45 |
+
|
46 |
+
st.download_button(
|
47 |
+
"Download annotations as CSV",
|
48 |
+
"\n".join([f"{k}\t{v}" for k, v in state.annotations.items()]),
|
49 |
+
file_name="annotations_faithfull.csv",
|
50 |
+
)
|
data_streamlit_align.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|