Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,9 +33,12 @@ from annotation_questions import (
|
|
| 33 |
########################################################################################
|
| 34 |
|
| 35 |
# Function to get user ID from URL
|
| 36 |
-
def get_param_from_url(param):
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# 'local' or 'hf'. hf is for Hugging Face file system but has limits on the number of access per hour
|
| 41 |
filesystem = 'hf'
|
|
@@ -342,7 +345,7 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 342 |
# )
|
| 343 |
|
| 344 |
if f.name == 'dialogue_name' and value:
|
| 345 |
-
render_markdown_simple(os.path.join(input_repo_path, 'dialogues', value), height_px=720)
|
| 346 |
|
| 347 |
elif f.name == 'role_name' and value:
|
| 348 |
render_markdown_simple(os.path.join(input_repo_path, 'role_descriptions', value), height_px=520)
|
|
@@ -359,7 +362,7 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 359 |
if f.other_params and f.other_params.get("use_dialogue_name"):
|
| 360 |
row = st.session_state.data.iloc[index]
|
| 361 |
dialogue_name = row["dialogue_name"]
|
| 362 |
-
md_path = os.path.join(input_repo_path, "dialogues", dialogue_name)
|
| 363 |
content = load_text(md_path)
|
| 364 |
st.markdown(content, unsafe_allow_html=True)
|
| 365 |
elif f.other_params and f.other_params.get("use_roledesc_name"):
|
|
@@ -558,6 +561,7 @@ def prep_and_save_data(index, skip_sample, completed: bool):
|
|
| 558 |
**existing,
|
| 559 |
**base,
|
| 560 |
'user_id': st.session_state.user_id,
|
|
|
|
| 561 |
'index': st.session_state.current_index,
|
| 562 |
'skip': skip_sample,
|
| 563 |
'completed': int(completed),
|
|
@@ -624,7 +628,12 @@ if 'data' not in st.session_state:
|
|
| 624 |
user_id_from_url = get_param_from_url("user_id")
|
| 625 |
if user_id_from_url and not st.session_state.get("user_id"):
|
| 626 |
st.session_state.user_id = user_id_from_url
|
| 627 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
# current index
|
| 629 |
if 'current_index' not in st.session_state:
|
| 630 |
start_index = get_start_index()
|
|
@@ -679,7 +688,7 @@ if st.session_state.current_index == -2:
|
|
| 679 |
add_checked_submit()
|
| 680 |
|
| 681 |
elif st.session_state.current_index == -1:
|
| 682 |
-
if st.session_state.get('user_id'):
|
| 683 |
navigate(1)
|
| 684 |
else:
|
| 685 |
with st.form("user_id_form"):
|
|
|
|
| 33 |
########################################################################################
|
| 34 |
|
| 35 |
# Function to get user ID from URL
|
| 36 |
+
def get_param_from_url(param: str, default: str = ""):
|
| 37 |
+
return st.query_params.get(param, default)
|
| 38 |
+
|
| 39 |
+
#def get_param_from_url(param):
|
| 40 |
+
# user_id = st.query_params.get(param, "")
|
| 41 |
+
# return user_id
|
| 42 |
|
| 43 |
# 'local' or 'hf'. hf is for Hugging Face file system but has limits on the number of access per hour
|
| 44 |
filesystem = 'hf'
|
|
|
|
| 345 |
# )
|
| 346 |
|
| 347 |
if f.name == 'dialogue_name' and value:
|
| 348 |
+
render_markdown_simple(os.path.join(input_repo_path, 'dialogues', st.session_state.batch, value), height_px=720)
|
| 349 |
|
| 350 |
elif f.name == 'role_name' and value:
|
| 351 |
render_markdown_simple(os.path.join(input_repo_path, 'role_descriptions', value), height_px=520)
|
|
|
|
| 362 |
if f.other_params and f.other_params.get("use_dialogue_name"):
|
| 363 |
row = st.session_state.data.iloc[index]
|
| 364 |
dialogue_name = row["dialogue_name"]
|
| 365 |
+
md_path = os.path.join(input_repo_path, "dialogues", st.session_state.batch, dialogue_name)
|
| 366 |
content = load_text(md_path)
|
| 367 |
st.markdown(content, unsafe_allow_html=True)
|
| 368 |
elif f.other_params and f.other_params.get("use_roledesc_name"):
|
|
|
|
| 561 |
**existing,
|
| 562 |
**base,
|
| 563 |
'user_id': st.session_state.user_id,
|
| 564 |
+
'batch': st.session_state.batch,
|
| 565 |
'index': st.session_state.current_index,
|
| 566 |
'skip': skip_sample,
|
| 567 |
'completed': int(completed),
|
|
|
|
| 628 |
user_id_from_url = get_param_from_url("user_id")
|
| 629 |
if user_id_from_url and not st.session_state.get("user_id"):
|
| 630 |
st.session_state.user_id = user_id_from_url
|
| 631 |
+
|
| 632 |
+
# batch
|
| 633 |
+
batch_from_url = get_param_from_url("batch")
|
| 634 |
+
if batch_from_url and not st.session_state.get("batch"):
|
| 635 |
+
st.session_state.batch = batch_from_url
|
| 636 |
+
|
| 637 |
# current index
|
| 638 |
if 'current_index' not in st.session_state:
|
| 639 |
start_index = get_start_index()
|
|
|
|
| 688 |
add_checked_submit()
|
| 689 |
|
| 690 |
elif st.session_state.current_index == -1:
|
| 691 |
+
if st.session_state.get('user_id') and st.session_state.get("batch"):
|
| 692 |
navigate(1)
|
| 693 |
else:
|
| 694 |
with st.form("user_id_form"):
|