Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -74,6 +74,14 @@ assistance_choices = ['Expand the breadth of moderator role',
|
|
74 |
|
75 |
default_choices = function_choices
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
fields: List[Field] = [
|
79 |
Field(name="topic", type="input_col", title="**Topic:**"),
|
@@ -244,8 +252,8 @@ div[data-testid="stMarkdownContainer"] > p {
|
|
244 |
</style>
|
245 |
""", unsafe_allow_html=True)
|
246 |
|
247 |
-
with st.expander(label="Annotation Guidelines", expanded=False):
|
248 |
-
st.write('some guidelines here')
|
249 |
|
250 |
# Load the data to annotate
|
251 |
if 'data' not in st.session_state:
|
@@ -253,45 +261,89 @@ if 'data' not in st.session_state:
|
|
253 |
|
254 |
# Initialize the current index
|
255 |
if 'current_index' not in st.session_state:
|
256 |
-
st.session_state.current_index = -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
user_id_from_url = get_user_id_from_url()
|
260 |
if user_id_from_url:
|
261 |
st.session_state.user_id = user_id_from_url
|
262 |
navigate(1)
|
263 |
else:
|
264 |
-
|
265 |
-
|
266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
|
268 |
elif st.session_state.current_index < len(st.session_state.data):
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
else:
|
297 |
st.write("Finished all data points!")
|
@@ -304,6 +356,7 @@ if st.session_state.current_index > 0:
|
|
304 |
if 0 <= st.session_state.current_index < len(st.session_state.data):
|
305 |
st.write(f"Page {st.session_state.current_index + 1} out of {len(st.session_state.data)}")
|
306 |
|
|
|
307 |
# disable text input enter to submit
|
308 |
# https://discuss.streamlit.io/t/text-input-how-to-disable-press-enter-to-apply/14457/6
|
309 |
import streamlit.components.v1 as components
|
|
|
74 |
|
75 |
default_choices = function_choices
|
76 |
|
77 |
+
consent_text = 'By taking part in this study you agree that you read all the details in [the consent form](https://someurl.com) and that you give your consent to participate in the study.'
|
78 |
+
guidelines_text = 'Please read <a href="https://someurl.com">the guidelines</a>'
|
79 |
+
study_code = 'some code here'
|
80 |
+
|
81 |
+
intro_fields: List[Field] = [
|
82 |
+
Field(name="intro_comments_1", type="text", title="Further comments1: free text"),
|
83 |
+
Field(name="intro_comments_2", type="text", title="Further comments2: free text"),
|
84 |
+
]
|
85 |
|
86 |
fields: List[Field] = [
|
87 |
Field(name="topic", type="input_col", title="**Topic:**"),
|
|
|
252 |
</style>
|
253 |
""", unsafe_allow_html=True)
|
254 |
|
255 |
+
#with st.expander(label="Annotation Guidelines", expanded=False):
|
256 |
+
# st.write('some guidelines here')
|
257 |
|
258 |
# Load the data to annotate
|
259 |
if 'data' not in st.session_state:
|
|
|
261 |
|
262 |
# Initialize the current index
|
263 |
if 'current_index' not in st.session_state:
|
264 |
+
st.session_state.current_index = -3
|
265 |
+
|
266 |
+
def add_checked_submit():
|
267 |
+
check = st.checkbox('I agree', key='consent')
|
268 |
+
if st.form_submit_button("Submit"):
|
269 |
+
if not check:
|
270 |
+
st.error("Please agree to give your consent to proceed")
|
271 |
+
else:
|
272 |
+
navigate(1)
|
273 |
|
274 |
+
def add_annotation_guidelines():
|
275 |
+
st.markdown(
|
276 |
+
"<details open><summary>Annotation Guidelines</summary>"+guidelines_text+"</details>"
|
277 |
+
, unsafe_allow_html=True)
|
278 |
+
st.write(f"username is {st.session_state.user_id}")
|
279 |
+
|
280 |
+
if st.session_state.current_index == -3:
|
281 |
+
with st.form("data_form"):
|
282 |
+
st.markdown(consent_text)
|
283 |
+
add_checked_submit()
|
284 |
+
|
285 |
+
elif st.session_state.current_index == -2:
|
286 |
user_id_from_url = get_user_id_from_url()
|
287 |
if user_id_from_url:
|
288 |
st.session_state.user_id = user_id_from_url
|
289 |
navigate(1)
|
290 |
else:
|
291 |
+
with st.form("data_form"):
|
292 |
+
st.session_state.user_id = st.text_input('Please enter your user ID', value=user_id_from_url)
|
293 |
+
if st.form_submit_button("Submit"):
|
294 |
+
navigate(1)
|
295 |
+
|
296 |
+
elif st.session_state.current_index == -1:
|
297 |
+
add_annotation_guidelines()
|
298 |
+
with st.form("data_form"):
|
299 |
+
show_fields(intro_fields)
|
300 |
|
301 |
elif st.session_state.current_index < len(st.session_state.data):
|
302 |
+
add_annotation_guidelines()
|
303 |
+
with st.form("data_form"):
|
304 |
+
show_fields(fields)
|
305 |
+
|
306 |
+
else:
|
307 |
+
st.write(f"Thank you for taking part in this study! Code to finish the study: {study_code}")
|
308 |
+
|
309 |
+
|
310 |
+
#if st.session_state.current_index == -1:
|
311 |
+
# user_id_from_url = get_user_id_from_url()
|
312 |
+
# if user_id_from_url:
|
313 |
+
# st.session_state.user_id = user_id_from_url
|
314 |
+
# navigate(1)
|
315 |
+
# else:
|
316 |
+
# st.session_state.user_id = st.text_input('Please enter your user ID to proceed', value=user_id_from_url)
|
317 |
+
# if st.button("Next"):
|
318 |
+
# navigate(1)
|
319 |
+
#
|
320 |
+
#elif st.session_state.current_index < len(st.session_state.data):
|
321 |
+
# st.write(f"username is {st.session_state.user_id}")
|
322 |
+
#
|
323 |
+
# # Creating the form
|
324 |
+
# with st.form("feedback_form"):
|
325 |
+
# index = st.session_state.current_index
|
326 |
+
# data_collected = read_saved_data()
|
327 |
+
# st.session_state.default_values = {}
|
328 |
+
# st.session_state.data_inputs = {}
|
329 |
+
#
|
330 |
+
# for field in fields:
|
331 |
+
# if field.name not in st.session_state.data.columns:
|
332 |
+
# # Field doesn't exist in input dataframe, add it with a default value
|
333 |
+
# st.session_state.data_inputs[field.name] = None
|
334 |
+
# show_field(field, index)
|
335 |
+
#
|
336 |
+
# submitted = st.form_submit_button("Submit")
|
337 |
+
# if submitted:
|
338 |
+
# with st.spinner(text="saving"):
|
339 |
+
# save_data({
|
340 |
+
# 'user_id': st.session_state.user_id,
|
341 |
+
# 'index': st.session_state.current_index,
|
342 |
+
# **st.session_state.data.iloc[index][COLS_TO_SAVE].to_dict(),
|
343 |
+
# **st.session_state.data_inputs
|
344 |
+
# })
|
345 |
+
# st.success("Feedback submitted successfully!")
|
346 |
+
# navigate(1)
|
347 |
|
348 |
else:
|
349 |
st.write("Finished all data points!")
|
|
|
356 |
if 0 <= st.session_state.current_index < len(st.session_state.data):
|
357 |
st.write(f"Page {st.session_state.current_index + 1} out of {len(st.session_state.data)}")
|
358 |
|
359 |
+
|
360 |
# disable text input enter to submit
|
361 |
# https://discuss.streamlit.io/t/text-input-how-to-disable-press-enter-to-apply/14457/6
|
362 |
import streamlit.components.v1 as components
|