섹션 조회 추가
This commit is contained in:
@@ -44,6 +44,13 @@ def save_completed_file(seed, basename):
|
||||
json.dump(list(completed_set), f, indent=2)
|
||||
|
||||
|
||||
def get_existing_sessions():
|
||||
""" "shared_sessions" 디렉토리에서 기존 세션 목록을 가져옵니다. """
|
||||
if not SESSION_BASE_PATH.exists():
|
||||
return []
|
||||
return sorted([d.name for d in SESSION_BASE_PATH.iterdir() if d.is_dir()])
|
||||
|
||||
|
||||
# --- 헬퍼 함수 ---
|
||||
|
||||
|
||||
@@ -196,26 +203,65 @@ def main():
|
||||
st.session_state.current_index = 0
|
||||
SESSION_BASE_PATH.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
matched_files = None
|
||||
st.sidebar.info("화면을 넓게 보려면 오른쪽 위 화살표를 누르세요 <<")
|
||||
st.sidebar.markdown("---")
|
||||
|
||||
st.sidebar.header("세션 선택")
|
||||
existing_sessions = get_existing_sessions()
|
||||
session_options = ["새 세션 생성"] + existing_sessions
|
||||
|
||||
current_seed_from_url = st.query_params.get("seed")
|
||||
|
||||
# URL에 시드가 없으면 "새 세션 생성"을 기본값으로
|
||||
if not current_seed_from_url:
|
||||
current_selection = "새 세션 생성"
|
||||
# URL의 시드가 존재하지 않는 세션이면 경고 후 "새 세션 생성"으로
|
||||
elif current_seed_from_url not in existing_sessions:
|
||||
st.sidebar.warning(f"URL의 시드 '{current_seed_from_url}'에 해당하는 세션을 찾을 수 없습니다.")
|
||||
current_selection = "새 세션 생성"
|
||||
# 잘못된 시드는 URL에서 제거
|
||||
if "seed" in st.query_params:
|
||||
del st.query_params["seed"]
|
||||
else:
|
||||
current_selection = current_seed_from_url
|
||||
|
||||
selected_session = st.sidebar.selectbox(
|
||||
"작업할 세션을 선택하세요.",
|
||||
session_options,
|
||||
index=session_options.index(current_selection),
|
||||
key="session_selector",
|
||||
)
|
||||
|
||||
# 사용자가 선택을 변경하면 URL을 업데이트하고 앱을 다시 실행
|
||||
if selected_session != current_selection:
|
||||
if selected_session == "새 세션 생성":
|
||||
if "seed" in st.query_params:
|
||||
del st.query_params["seed"]
|
||||
else:
|
||||
st.query_params["seed"] = selected_session
|
||||
st.rerun()
|
||||
|
||||
# --- 이후 로직은 URL의 'seed' 쿼리 파라미터를 기반으로 동작 ---
|
||||
url_seed = st.query_params.get("seed")
|
||||
matched_files = None
|
||||
completed_files = set()
|
||||
|
||||
if url_seed:
|
||||
completed_files = load_completed_files(url_seed)
|
||||
files = load_files_from_session(url_seed)
|
||||
if files[0] is not None:
|
||||
st.success(f"'{url_seed}' 시드에서 파일을 불러왔습니다.")
|
||||
st.success(f"'{url_seed}' 세션에서 파일을 불러왔습니다.")
|
||||
matched_files = match_files_3_way(*files)
|
||||
else:
|
||||
# 이 경우는 위에서 처리되었지만, 안전장치로 남겨둠
|
||||
st.error(f"'{url_seed}'에 해당하는 세션을 찾을 수 없습니다.")
|
||||
else:
|
||||
completed_files = set()
|
||||
if "seed" in st.query_params:
|
||||
del st.query_params["seed"]
|
||||
st.rerun()
|
||||
|
||||
# --- 사이드바 ---
|
||||
st.sidebar.info("화면을 넓게 보려면 오른쪽 위 화살표를 누르세요 <<")
|
||||
st.sidebar.markdown("---")
|
||||
|
||||
st.sidebar.header("파일 업로드")
|
||||
if not matched_files:
|
||||
# 파일 업로드 UI는 새 세션 생성 시에만 표시
|
||||
if not url_seed:
|
||||
st.sidebar.header("새 세션 생성 (파일 업로드)")
|
||||
docs = st.sidebar.file_uploader(
|
||||
"1. 원본 문서", accept_multiple_files=True, type=["png", "jpg", "pdf"]
|
||||
)
|
||||
@@ -238,12 +284,14 @@ def main():
|
||||
st.sidebar.info("URL을 복사하여 다른 사람과 세션을 공유하세요.")
|
||||
st.sidebar.text_input("공유 시드", url_seed, disabled=True)
|
||||
|
||||
if not url_seed:
|
||||
st.info("새로운 세션을 생성하려면 사이드바에서 모든 종류의 파일을 업로드하세요.")
|
||||
return
|
||||
|
||||
if not matched_files:
|
||||
st.info("모든 종류의 파일을 업로드하고 세션을 생성하세요.")
|
||||
if matched_files is not None and not matched_files:
|
||||
st.warning(
|
||||
"파일 이름(확장자 제외)이 동일한 '문서-paddle_ocr-upstage' 세트를 찾을 수 없습니다."
|
||||
)
|
||||
st.warning(
|
||||
"파일 이름(확장자 제외)이 동일한 '문서-paddle_ocr-upstage' 세트를 찾을 수 없습니다."
|
||||
)
|
||||
return
|
||||
|
||||
st.sidebar.header("파일 탐색")
|
||||
|
||||
Reference in New Issue
Block a user