emvecchi commited on
Commit
4b568ea
·
verified ·
1 Parent(s): 88329f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -228,9 +228,9 @@ def get_base_path():
228
  def get_path():
229
  return f"{get_base_path()}/{st.session_state.current_index}.json"
230
 
231
- def display_dialogue(dialogue_path):
232
- dialogue_text = load_text(dialogue_path)
233
- st.code(dialogue_text, language="markdown", line_numbers=True)
234
  #st.markdown(
235
  # f"<details><summary><b>Annotation Guidelines</b></summary><div>{dialogue_text}</div></details><br>",
236
  #unsafe_allow_html=True)
@@ -289,8 +289,8 @@ def show_field(f: Field, index: int, data_collected):
289
  if f.name == 'image_name':
290
  display_image(os.path.join(input_repo_path, 'images', value))
291
  elif f.name == 'dialogue_name':
292
- #display_dialogue(os.path.join(input_repo_path, 'dialogues', value))
293
- display_dialogue(os.path.join(input_repo_path, value))
294
  else:
295
  st.write(value)
296
  case 'markdown':
@@ -508,10 +508,13 @@ def add_checked_submit():
508
  check = st.checkbox('I agree', key='consent')
509
  add_validated_submit([check], "Please agree to give your consent to proceed")
510
 
511
- def load_text(file):
512
- with open(file, "r") as file:
513
- consent_text = file.read()
514
- return consent_text
 
 
 
515
 
516
  if st.session_state.current_index == -2:
517
  with st.form("data_form"):
 
228
  def get_path():
229
  return f"{get_base_path()}/{st.session_state.current_index}.json"
230
 
231
+ def display_dialogue(hf_path: str):
232
+ txt = load_text(hf_path)
233
+ st.code(txt, language="markdown", line_numbers=True)
234
  #st.markdown(
235
  # f"<details><summary><b>Annotation Guidelines</b></summary><div>{dialogue_text}</div></details><br>",
236
  #unsafe_allow_html=True)
 
289
  if f.name == 'image_name':
290
  display_image(os.path.join(input_repo_path, 'images', value))
291
  elif f.name == 'dialogue_name':
292
+ display_dialogue(os.path.join(input_repo_path, 'dialogues', value))
293
+ #display_dialogue(os.path.join(input_repo_path, value))
294
  else:
295
  st.write(value)
296
  case 'markdown':
 
508
  check = st.checkbox('I agree', key='consent')
509
  add_validated_submit([check], "Please agree to give your consent to proceed")
510
 
511
+ def load_text(path: str) -> str:
512
+ if filesystem == 'hf':
513
+ with hf_fs.open(path, "rb") as f:
514
+ return f.read().decode("utf-8")
515
+ else:
516
+ with open(path, "r", encoding="utf-8") as f:
517
+ return f.read()
518
 
519
  if st.session_state.current_index == -2:
520
  with st.form("data_form"):