Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| import glob | |
| import time | |
| import base64 | |
| from streamlit.components.v1 import html | |
| from streamlit_autorefresh import st_autorefresh | |
| # ํ์ด์ง ์ค์ | |
| st.set_page_config( | |
| page_title="๋์คํ๋ ์ด ์ปจํ ์ธ ๊ด๋ฆฌ", | |
| page_icon="๐ผ๏ธ", | |
| layout="wide", | |
| initial_sidebar_state="collapsed" | |
| ) | |
| # ์ ์ญ CSS ์ค์ | |
| st.markdown(""" | |
| <style> | |
| /* ์ ์ฒด ํ๋ฉด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์คํ์ผ */ | |
| .full-view { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100vw; | |
| height: 100vh; | |
| background-position: center; | |
| background-repeat: no-repeat; | |
| background-color: black; | |
| transition: opacity 1s ease-in-out; | |
| z-index: 9998; | |
| } | |
| /* ์ปจํธ๋กค ํจ๋ ์คํ์ผ */ | |
| .controls-panel { | |
| position: fixed; | |
| bottom: 20px; | |
| right: 20px; | |
| z-index: 9999; | |
| opacity: 0.2; | |
| transition: opacity 0.3s; | |
| } | |
| .controls-panel:hover { | |
| opacity: 1; | |
| } | |
| .view-toggle { | |
| background-color: rgba(0, 0, 0, 0.5); | |
| color: white; | |
| border: none; | |
| padding: 8px 16px; | |
| margin: 5px; | |
| border-radius: 4px; | |
| cursor: pointer; | |
| font-size: 14px; | |
| } | |
| .view-toggle:hover { | |
| background-color: rgba(0, 0, 0, 0.8); | |
| } | |
| /* ์ ๋๋ฉ์ด์ ํจ๊ณผ */ | |
| .animate-fade { | |
| animation: fadeIn 2s; | |
| } | |
| .animate-zoom { | |
| animation: zoomIn 2s; | |
| } | |
| .animate-slide { | |
| animation: slideIn 2s; | |
| } | |
| .animate-rotate { | |
| animation: rotateIn 2s; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; } | |
| to { opacity: 1; } | |
| } | |
| @keyframes zoomIn { | |
| from { transform: scale(0.7); opacity: 0; } | |
| to { transform: scale(1); opacity: 1; } | |
| } | |
| @keyframes slideIn { | |
| from { transform: translateY(20%); opacity: 0; } | |
| to { transform: translateY(0); opacity: 1; } | |
| } | |
| @keyframes rotateIn { | |
| from { transform: rotate(-10deg) scale(0.9); opacity: 0; } | |
| to { transform: rotate(0) scale(1); opacity: 1; } | |
| } | |
| /* ์ด๋ฏธ์ง ๊ด๋ฆฌ ๊ทธ๋ฆฌ๋ ์คํ์ผ */ | |
| .image-item { | |
| position: relative; | |
| margin-bottom: 10px; | |
| } | |
| .image-item img { | |
| width: 100%; | |
| border-radius: 4px; | |
| } | |
| .image-actions { | |
| position: absolute; | |
| top: 5px; | |
| right: 5px; | |
| } | |
| .image-name { | |
| font-size: 12px; | |
| overflow: hidden; | |
| text-overflow: ellipsis; | |
| white-space: nowrap; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # ์ ์ฒด ํ๋ฉด JS ํจ์ | |
| def inject_fullscreen_js(): | |
| js_code = """ | |
| <script> | |
| function toggleFullScreen() { | |
| var elem = document.documentElement; | |
| if (!document.fullscreenElement && !document.mozFullScreenElement && | |
| !document.webkitFullscreenElement && !document.msFullscreenElement) { | |
| if (elem.requestFullscreen) { | |
| elem.requestFullscreen(); | |
| } else if (elem.msRequestFullscreen) { | |
| elem.msRequestFullscreen(); | |
| } else if (elem.mozRequestFullScreen) { | |
| elem.mozRequestFullScreen(); | |
| } else if (elem.webkitRequestFullscreen) { | |
| elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); | |
| } | |
| } | |
| } | |
| // ์ ์ฒด ํ๋ฉด ํ์ฑํ ์๋ | |
| setTimeout(function() { | |
| toggleFullScreen(); | |
| }, 1000); | |
| </script> | |
| """ | |
| html(js_code, height=0, width=0) | |
| # ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ํ์ ๋ฐฉ์ ์ ํ์ ์ํ JavaScript ํจ์ | |
| def inject_background_toggle_js(): | |
| js_code = """ | |
| <script> | |
| // ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ํ์ ๋ฐฉ์ ์ ํ ํจ์ | |
| function toggleBackgroundFit() { | |
| const fullView = document.querySelector('.full-view'); | |
| if (fullView) { | |
| const currentFit = fullView.style.backgroundSize; | |
| if (currentFit === 'cover') { | |
| fullView.style.backgroundSize = 'contain'; | |
| document.getElementById('fit-toggle-btn').innerText = 'ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ'; | |
| } else { | |
| fullView.style.backgroundSize = 'cover'; | |
| document.getElementById('fit-toggle-btn').innerText = '์๋ณธ ๋น์จ ์ ์ง'; | |
| } | |
| } | |
| } | |
| // ์ ์ญ ๋ฒ์์ ํจ์ ๋ ธ์ถ (window ๊ฐ์ฒด์ ์ถ๊ฐ) | |
| window.applyBackgroundAnimation = function(animationType) { | |
| const fullView = document.querySelector('.full-view'); | |
| if (fullView) { | |
| // ๋ชจ๋ ์ ๋๋ฉ์ด์ ํด๋์ค ์ ๊ฑฐ | |
| fullView.classList.remove('animate-fade', 'animate-zoom', 'animate-slide', 'animate-rotate'); | |
| // ์ ์ ๋๋ฉ์ด์ ํด๋์ค ์ถ๊ฐ | |
| void fullView.offsetWidth; // ๊ฐ์ ๋ฆฌํ๋ก์ฐ | |
| fullView.classList.add(animationType); | |
| } | |
| } | |
| </script> | |
| """ | |
| html(js_code, height=0, width=0) | |
| # URL ํ๋ผ๋ฏธํฐ ์ฒ๋ฆฌ | |
| try: | |
| query_params = st.query_params | |
| # ์ ์ฒดํ๋ฉด ๋ชจ๋ ํ์ธ | |
| if "fullscreen" in query_params and query_params["fullscreen"][0].lower() == "true": | |
| st.session_state.preview_mode = True | |
| st.session_state.activate_fullscreen = True | |
| # ์ด๋ฏธ์ง ์ ํ ๋ชจ๋ ํ์ธ | |
| if "change" in query_params: | |
| st.session_state.fixed_image_enabled = False | |
| # ๋จ์ผ ์ด๋ฏธ์ง ๋ชจ๋ ํ์ธ | |
| elif "1image" in query_params: # change์ 1image ๋ ๋ค ์์ผ๋ฉด change๊ฐ ์ฐ์ ํ๋๋ก elif ์ฌ์ฉ | |
| st.session_state.fixed_image_enabled = True | |
| # ํน์ ์ด๋ฏธ์ง ์ธ๋ฑ์ค๊ฐ ์ง์ ๋์๋์ง ํ์ธ | |
| if "image" in query_params: | |
| try: | |
| img_index = int(query_params["image"]) | |
| # contents ํด๋ ๋ด์ ๋ชจ๋ ์ด๋ฏธ์ง ํ์ผ ๋ฏธ๋ฆฌ ๋ก๋ | |
| if not os.path.exists('contents'): | |
| os.makedirs('contents') | |
| image_files = glob.glob('contents/*.jpg') + glob.glob('contents/*.jpeg') + glob.glob('contents/*.png') | |
| # ์ธ๋ฑ์ค๊ฐ ์ ํจํ์ง ํ์ธ | |
| if 0 <= img_index < len(image_files): | |
| st.session_state.fixed_image_path = image_files[img_index] | |
| elif image_files: # ์ ํจํ์ง ์์ง๋ง ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง ์ฌ์ฉ | |
| st.session_state.fixed_image_path = image_files[0] | |
| except ValueError: | |
| # ์ซ์๋ก ๋ณํํ ์ ์๋ ๊ฒฝ์ฐ | |
| pass | |
| except Exception as e: | |
| st.error(f"URL ํ๋ผ๋ฏธํฐ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {e}") | |
| # ์ด๊ธฐ ์ค์ ๋ฐ ์ํ ๊ด๋ฆฌ (๊ธฐ์กด ์ฝ๋ ์์ ) | |
| if 'contents' not in st.session_state: | |
| # contents ํด๋ ๋ด์ ๋ชจ๋ ์ด๋ฏธ์ง ํ์ผ ๋ก๋ | |
| if not os.path.exists('contents'): | |
| os.makedirs('contents') | |
| image_files = glob.glob('contents/*.jpg') + glob.glob('contents/*.jpeg') + glob.glob('contents/*.png') | |
| st.session_state.contents = image_files | |
| if 'current_image_index' not in st.session_state: | |
| st.session_state.current_image_index = 0 | |
| if 'animation_type' not in st.session_state: | |
| st.session_state.animation_type = 'animate-fade' | |
| if 'activate_fullscreen' not in st.session_state: | |
| st.session_state.activate_fullscreen = False | |
| if 'fit_mode' not in st.session_state: | |
| st.session_state.fit_mode = 'cover' # ๊ธฐ๋ณธ๊ฐ์ ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ | |
| if 'app_loaded' not in st.session_state: | |
| st.session_state.app_loaded = False | |
| # ๊ธฐ์กด ์ฝ๋๋ฅผ ์กฐ๊ฑด๋ถ๋ก ์์ | |
| if 'fixed_image_enabled' not in st.session_state: | |
| st.session_state.fixed_image_enabled = False | |
| if 'fixed_image_path' not in st.session_state and st.session_state.contents: | |
| st.session_state.fixed_image_path = st.session_state.contents[0] if st.session_state.contents else None | |
| # ์ฌ๋ผ์ด๋์ผ ์๋ ์์ ๋ก์ง | |
| if not st.session_state.app_loaded and not st.session_state.get('preview_mode', False): | |
| if st.session_state.contents and not st.session_state.fixed_image_enabled: # ์ด๋ฏธ์ง๊ฐ ์๊ณ ๊ณ ์ ๋ชจ๋๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ์๋ ์์ | |
| st.session_state.preview_mode = True | |
| st.session_state.preview_start_time = time.time() | |
| st.session_state.activate_fullscreen = True | |
| st.session_state.app_loaded = True # ์ฑ์ด ๋ก๋๋์์์ ํ์ | |
| # ์ฌ์ด๋๋ฐ - ์ด๋ฏธ์ง ๊ด๋ฆฌ | |
| with st.sidebar: | |
| st.title("๐ธ ๋์คํ๋ ์ด ์ค์ ") | |
| # ์ด๋ฏธ์ง ์ ๋ก๋ | |
| st.subheader("์ด๋ฏธ์ง ์ถ๊ฐ") | |
| uploaded_files = st.file_uploader("์ด๋ฏธ์ง ํ์ผ์ ์ ๋ก๋ํ์ธ์", type=["jpg", "jpeg", "png"], accept_multiple_files=True) | |
| if uploaded_files: | |
| for uploaded_file in uploaded_files: | |
| # contents ๋๋ ํ ๋ฆฌ๊ฐ ์์ผ๋ฉด ์์ฑ | |
| if not os.path.exists('contents'): | |
| os.makedirs('contents') | |
| # ์ ์ฅ ๊ฒฝ๋ก ์์ฑ | |
| file_path = os.path.join('contents', uploaded_file.name) | |
| # ์ด๋ฏธ์ง ์ ์ฅ | |
| with open(file_path, "wb") as f: | |
| f.write(uploaded_file.getvalue()) | |
| # ์ ์ฅ๋ ์ด๋ฏธ์ง๋ฅผ ๋ชฉ๋ก์ ์ถ๊ฐ (์ค๋ณต ๋ฐฉ์ง) | |
| if file_path not in st.session_state.contents: | |
| st.session_state.contents.append(file_path) | |
| st.success(f"{len(uploaded_files)}๊ฐ ์ด๋ฏธ์ง๊ฐ ์ถ๊ฐ๋์์ต๋๋ค.") | |
| # ์ด๋ฏธ์ง ๋ชฉ๋ก ๋ฐ ๊ด๋ฆฌ | |
| st.subheader("์ด๋ฏธ์ง ์์ ์กฐ์ ") | |
| if not st.session_state.contents: | |
| st.info("๋ฑ๋ก๋ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.") | |
| else: | |
| # ์ด๋ฏธ์ง ๋ชฉ๋ก ํ์ ๋ฐ ์์ ์กฐ์ | |
| for i, img_path in enumerate(st.session_state.contents): | |
| col1, col2 = st.columns([3, 1]) | |
| with col1: | |
| st.text(os.path.basename(img_path)) | |
| st.image(img_path, width=150) | |
| with col2: | |
| # ์๋ก ์ด๋ ๋ฒํผ | |
| if i > 0 and st.button("๐", key=f"up_{i}"): | |
| st.session_state.contents[i], st.session_state.contents[i-1] = st.session_state.contents[i-1], st.session_state.contents[i] | |
| st.rerun() | |
| # ์๋๋ก ์ด๋ ๋ฒํผ | |
| if i < len(st.session_state.contents) - 1 and st.button("๐", key=f"down_{i}"): | |
| st.session_state.contents[i], st.session_state.contents[i+1] = st.session_state.contents[i+1], st.session_state.contents[i] | |
| st.rerun() | |
| # ์ญ์ ๋ฒํผ | |
| if st.button("๐๏ธ", key=f"delete_{i}"): | |
| del st.session_state.contents[i] | |
| st.rerun() | |
| st.markdown("<hr>", unsafe_allow_html=True) | |
| # ์ด๋ฏธ์ง ๊ณ ์ ์ค์ | |
| st.subheader("์ด๋ฏธ์ง ๊ณ ์ ์ค์ ") | |
| fixed_image_enabled = st.checkbox( | |
| "ํ ์ด๋ฏธ์ง๋ง ๊ณ ์ ํ์ฌ ํ์", | |
| value=st.session_state.fixed_image_enabled, | |
| help="์ฒดํฌํ๋ฉด ์ ํํ ์ด๋ฏธ์ง๋ง ๊ณ์ ํ์๋ฉ๋๋ค. ์ฌ๋ผ์ด๋์ผ๊ฐ ์ค์ง๋ฉ๋๋ค." | |
| ) | |
| # ์ฒดํฌ๋ฐ์ค ์ํ๊ฐ ๋ณ๊ฒฝ๋์์ ๋ ์ธ์ ์ํ ์ ๋ฐ์ดํธ | |
| if fixed_image_enabled != st.session_state.fixed_image_enabled: | |
| st.session_state.fixed_image_enabled = fixed_image_enabled | |
| # ๊ณ ์ ๋ชจ๋๊ฐ ๋นํ์ฑํ๋๋ฉด ์ฌ๋ผ์ด๋์ผ ์ฌ๊ฐ | |
| if not fixed_image_enabled and st.session_state.get('preview_mode', False): | |
| st.session_state.preview_start_time = time.time() | |
| # ์ด๋ฏธ์ง ๊ณ ์ ๋ชจ๋๊ฐ ํ์ฑํ๋ ๊ฒฝ์ฐ์๋ง ์ด๋ฏธ์ง ์ ํ ๋๋กญ๋ค์ด ํ์ | |
| if st.session_state.fixed_image_enabled: | |
| # ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก์์ ํ์ผ๋ช ๋ง ์ถ์ถํ์ฌ ํ์ ์ต์ ์์ฑ | |
| image_options = {img_path: os.path.basename(img_path) for img_path in st.session_state.contents} | |
| # ์ ํ๋ ์ด๋ฏธ์ง๊ฐ ์๊ฑฐ๋ ๋ชฉ๋ก์ ์๋ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง ์ ํ | |
| default_index = 0 | |
| if st.session_state.fixed_image_path in image_options: | |
| default_index = list(image_options.keys()).index(st.session_state.fixed_image_path) | |
| # ์ด๋ฏธ์ง ์ ํ ๋๋กญ๋ค์ด | |
| if st.session_state.contents: # ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ๋๋กญ๋ค์ด ํ์ | |
| selected_image = st.selectbox( | |
| "๊ณ ์ ํ ์ด๋ฏธ์ง ์ ํ", | |
| options=list(image_options.keys()), | |
| format_func=lambda x: image_options[x], | |
| index=default_index | |
| ) | |
| # ์ ํ๋ ์ด๋ฏธ์ง ์ ์ฅ | |
| st.session_state.fixed_image_path = selected_image | |
| # ์ ํ๋ ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํ์ | |
| st.image(selected_image, caption="์ ํ๋ ์ด๋ฏธ์ง", width=200) | |
| else: | |
| st.warning("ํ์ํ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.") | |
| # ์ ๋๋ฉ์ด์ ํจ๊ณผ ์ ํ (๊ณ์) | |
| animation_options = { | |
| 'animate-fade': 'ํ์ด๋ ์ธ/์์', | |
| 'animate-zoom': '์ค ์ธ/์์', | |
| 'animate-slide': '์ฌ๋ผ์ด๋', | |
| 'animate-rotate': 'ํ์ ' | |
| } | |
| selected_animation = st.radio( | |
| "์ ํ ํจ๊ณผ ์ ํ", | |
| options=list(animation_options.keys()), | |
| format_func=lambda x: animation_options[x], | |
| index=list(animation_options.keys()).index(st.session_state.animation_type) if st.session_state.animation_type in animation_options else 0 | |
| ) | |
| if selected_animation != st.session_state.animation_type: | |
| st.session_state.animation_type = selected_animation | |
| # ์ฌ์ ์ค์ | |
| st.subheader("์ฌ์ ์ค์ ") | |
| # ์ด๋ฏธ์ง ํ์ ๋ชจ๋ ์ ํ | |
| fit_options = { | |
| 'cover': 'ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ', | |
| 'contain': '์๋ณธ ๋น์จ ์ ์ง' | |
| } | |
| selected_fit = st.radio( | |
| "์ด๋ฏธ์ง ํ์ ๋ฐฉ์", | |
| options=list(fit_options.keys()), | |
| format_func=lambda x: fit_options[x], | |
| index=list(fit_options.keys()).index(st.session_state.fit_mode) if st.session_state.fit_mode in fit_options else 0 | |
| ) | |
| if selected_fit != st.session_state.fit_mode: | |
| st.session_state.fit_mode = selected_fit | |
| # ์ฌ๋ผ์ด๋์ผ ๊ฐ๊ฒฉ ์ค์ | |
| preview_interval = st.slider("์ด๋ฏธ์ง ์ ํ ๊ฐ๊ฒฉ (์ด)", min_value=1, max_value=60, value=10) | |
| # ์ฌ๋ผ์ด๋์ผ ์์/์ข ๋ฃ ๋ฒํผ | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| if st.button("๐ผ๏ธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์", use_container_width=True): | |
| st.session_state.preview_mode = True | |
| st.session_state.preview_start_time = time.time() | |
| st.session_state.activate_fullscreen = False | |
| st.rerun() | |
| with col2: | |
| if st.button("๐ ์ ์ฒดํ๋ฉด ๋ณด๊ธฐ", use_container_width=True): | |
| st.session_state.preview_mode = True | |
| st.session_state.preview_start_time = time.time() | |
| st.session_state.activate_fullscreen = True | |
| st.rerun() | |
| # ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ชจ๋์ธ ๊ฒฝ์ฐ ์ข ๋ฃ ๋ฒํผ ํ์ | |
| if st.session_state.get('preview_mode', False): | |
| if st.button("โน๏ธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ข ๋ฃ", use_container_width=True): | |
| st.session_state.preview_mode = False | |
| st.session_state.activate_fullscreen = False | |
| st.rerun() | |
| # ์ฌ์ด๋๋ฐ ํ๋จ์ URL ์ ๋ณด ์ถ๊ฐ | |
| st.sidebar.markdown("---") | |
| st.sidebar.subheader("์ ์ URL") | |
| base_url = "https://jamespark3-display.hf.space/" | |
| # ์ด๋ฏธ์ง ์ ํ ๋ชจ๋ URL | |
| transition_url = f"{base_url}?fullscreen=true&change" | |
| st.sidebar.text_area("์ด๋ฏธ์ง ์ ํ ๋ชจ๋", transition_url, help="์ด URL๋ก ์ ์ํ๋ฉด ์๋์ผ๋ก ์ด๋ฏธ์ง ์ ํ ๋ชจ๋๋ก ์์๋ฉ๋๋ค.") | |
| # ๋จ์ผ ์ด๋ฏธ์ง ๋ชจ๋ URL | |
| if st.session_state.fixed_image_enabled and st.session_state.fixed_image_path and st.session_state.contents: | |
| current_img_index = st.session_state.contents.index(st.session_state.fixed_image_path) if st.session_state.fixed_image_path in st.session_state.contents else 0 | |
| single_url = f"{base_url}?fullscreen=true&1image&image={current_img_index}" | |
| st.sidebar.text_area("ํ์ฌ ์ ํ๋ ์ด๋ฏธ์ง ๋ชจ๋", single_url, help="์ด URL๋ก ์ ์ํ๋ฉด ์ ํ๋ ์ด๋ฏธ์ง๋ง ํ์๋ฉ๋๋ค.") | |
| else: | |
| single_url = f"{base_url}?fullscreen=true&1image" | |
| st.sidebar.text_area("๋จ์ผ ์ด๋ฏธ์ง ๋ชจ๋", single_url, help="์ด URL๋ก ์ ์ํ๋ฉด ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง๊ฐ ๊ณ ์ ๋์ด ํ์๋ฉ๋๋ค.") | |
| # ๋ฉ์ธ ์ปจํ ์ธ ์์ญ | |
| if st.session_state.get('preview_mode', False): | |
| # ํ๊น ํ์ด์ค UI ์์ ์จ๊ธฐ๊ธฐ ์ํ CSS ์ถ๊ฐ | |
| st.markdown(""" | |
| <style> | |
| /* ํ๊น ํ์ด์ค ํค๋ ๋ฐ ๊ด๋ จ UI ์์ ์จ๊ธฐ๊ธฐ */ | |
| div.css-1avcm0n {display: none !important;} /* ์๋จ ํค๋ */ | |
| div.css-14xtw13 {display: none !important;} /* ๊ณต๊ฐ */ | |
| section.css-1lcbmhc {display: none !important;} /* ์ฌ์ด๋๋ฐ */ | |
| div.css-1dp5vir {display: none !important;} /* ๊ธฐํ UI ์์ */ | |
| div.e1nzilvr5 {display: none !important;} | |
| div.viewerBadge_link__1S137 {display: none !important;} | |
| div.css-1bgch32 {display: none !important;} | |
| /* Streamlit ์์ ์จ๊ธฐ๊ธฐ */ | |
| #MainMenu {visibility: hidden !important;} | |
| header {visibility: hidden !important;} | |
| footer {visibility: hidden !important;} | |
| /* iframe ๊ด๋ จ ์ค์ */ | |
| iframe {border: none !important;} | |
| /* ์ฑ ์ปจํ ์ด๋ ์ ์ฒด ํ๋ฉด ์ค์ */ | |
| .main .block-container { | |
| padding: 0 !important; | |
| max-width: 100% !important; | |
| } | |
| .stApp { | |
| margin: 0 !important; | |
| padding: 0 !important; | |
| height: 100vh !important; | |
| width: 100vw !important; | |
| overflow: hidden !important; | |
| } | |
| /* ์ ์ฒด ํ๋ฉด ์ค์ ๊ฐํ */ | |
| body { | |
| margin: 0 !important; | |
| padding: 0 !important; | |
| overflow: hidden !important; | |
| } | |
| /* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ปจํ ์ด๋ ์์ */ | |
| .full-view { | |
| position: fixed !important; | |
| top: 0 !important; | |
| left: 0 !important; | |
| width: 100vw !important; | |
| height: 100vh !important; | |
| z-index: 9999 !important; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # ์๋ ์๋ก๊ณ ์นจ์ ์ํ ์นด์ดํฐ | |
| count = st_autorefresh(interval=preview_interval * 1000, key="refreshInterval") | |
| # ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ ํ JS ์ฝ์ (๋จผ์ ์คํ๋์ด์ผ ํจ) | |
| inject_background_toggle_js() | |
| # ์ ์ฒดํ๋ฉด ํ์ฑํ ํ์์ ์คํ | |
| if st.session_state.activate_fullscreen: | |
| inject_fullscreen_js() | |
| # ํ์ฌ ์ธ๋ฑ์ค ์ ๋ฐ์ดํธ | |
| if count > 0 and st.session_state.contents: | |
| # ์ด๋ฏธ์ง ๊ณ ์ ๋ชจ๋๊ฐ ํ์ฑํ๋์ง ์์ ๊ฒฝ์ฐ์๋ง ์ด๋ฏธ์ง ๋ณ๊ฒฝ | |
| if not st.session_state.fixed_image_enabled: | |
| st.session_state.current_image_index = (st.session_state.current_image_index + 1) % len(st.session_state.contents) | |
| # ํ๋ฉด์ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ก ํ์ | |
| if st.session_state.contents: | |
| # ์ด๋ฏธ์ง ๊ณ ์ ๋ชจ๋๊ฐ ํ์ฑํ๋ ๊ฒฝ์ฐ ๊ณ ์ ์ด๋ฏธ์ง ์ฌ์ฉ, ์๋๋ฉด ํ์ฌ ์ธ๋ฑ์ค ์ด๋ฏธ์ง ์ฌ์ฉ | |
| if st.session_state.fixed_image_enabled and st.session_state.fixed_image_path: | |
| full_img_path = st.session_state.fixed_image_path | |
| else: | |
| full_img_path = st.session_state.contents[st.session_state.current_image_index] | |
| # ์น์์ ์ ๊ทผ ๊ฐ๋ฅํ ์ด๋ฏธ์ง URL๋ก ๋ณํ (Base64 ์ธ์ฝ๋ฉ ์ฌ์ฉ) | |
| with open(full_img_path, "rb") as img_file: | |
| img_data = base64.b64encode(img_file.read()).decode() | |
| # ์ด๋ฏธ์ง ํ์ฅ์ ๊ฐ์ ธ์ค๊ธฐ (๊ธฐ๋ณธ๊ฐ์ jpeg) | |
| file_ext = os.path.splitext(full_img_path)[1][1:] or "jpeg" | |
| # ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ค์ ๊ณผ ์ปจํธ๋กค ๋ฒํผ์ด ํฌํจ๋ HTML ์์ฑ | |
| background_html = f""" | |
| <div class="full-view animate-{st.session_state.animation_type}" | |
| style="background-image: url('data:image/{file_ext};base64,{img_data}'); | |
| background-size: {st.session_state.fit_mode};"> | |
| <div class="controls-panel"> | |
| <button id="fit-toggle-btn" class="view-toggle" onclick="toggleBackgroundFit()"> | |
| {'์๋ณธ ๋น์จ ์ ์ง' if st.session_state.fit_mode == 'cover' else 'ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ'} | |
| </button> | |
| <button id="exit-btn" class="view-toggle" onclick="window.location.href=window.location.pathname"> | |
| ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ข ๋ฃ | |
| </button> | |
| </div> | |
| </div> | |
| <script> | |
| // ์ ์ฒดํ๋ฉด ํ์ฑํ | |
| setTimeout(function() {{ | |
| var elem = document.documentElement; | |
| if (elem.requestFullscreen) {{ | |
| elem.requestFullscreen(); | |
| }} else if (elem.mozRequestFullScreen) {{ | |
| elem.mozRequestFullScreen(); | |
| }} else if (elem.webkitRequestFullscreen) {{ | |
| elem.webkitRequestFullscreen(); | |
| }} else if (elem.msRequestFullscreen) {{ | |
| elem.msRequestFullscreen(); | |
| }} | |
| }}, 1000); | |
| // ์ ๋๋ฉ์ด์ ์ ์ฉ (window ๊ฐ์ฒด์์ ํจ์ ํธ์ถ) | |
| setTimeout(function() {{ | |
| if (typeof window.applyBackgroundAnimation === 'function') {{ | |
| window.applyBackgroundAnimation('animate-{st.session_state.animation_type}'); | |
| }} | |
| }}, 1500); | |
| // ํ๊น ํ์ด์ค ์์ ์จ๊ธฐ๊ธฐ ๊ฐํ | |
| function hideHuggingfaceElements() {{ | |
| const huggingfaceElements = document.querySelectorAll('.css-1avcm0n, .css-14xtw13, .css-1lcbmhc, .css-1dp5vir, .e1nzilvr5, .viewerBadge_link__1S137, .css-1bgch32'); | |
| huggingfaceElements.forEach(el => {{ | |
| if(el) el.style.display = 'none'; | |
| }}); | |
| }} | |
| // ์ฌ๋ฌ ๋ฒ ์๋ํ์ฌ UI ์์ ์จ๊ธฐ๊ธฐ | |
| setTimeout(hideHuggingfaceElements, 1000); | |
| setTimeout(hideHuggingfaceElements, 2000); | |
| setTimeout(hideHuggingfaceElements, 5000); | |
| </script> | |
| """ | |
| # HTML ์ง์ ์ฝ์ | |
| st.markdown(background_html, unsafe_allow_html=True) | |
| # Streamlit ์์ ์จ๊ธฐ๊ธฐ | |
| st.markdown(""" | |
| <style> | |
| #MainMenu {visibility: hidden;} | |
| header {visibility: hidden;} | |
| footer {visibility: hidden;} | |
| </style> | |
| """, unsafe_allow_html=True) | |
| else: | |
| # ์ผ๋ฐ ๋ชจ๋ - ์ฑ ์๊ฐ ๋ฐ ์ฌ์ฉ๋ฒ | |
| st.title("๐ผ๏ธ ๋์งํธ ๋์คํ๋ ์ด ์ปจํ ์ธ ๊ด๋ฆฌ") | |
| if not st.session_state.contents: | |
| st.warning("โ ๏ธ ๋ฑ๋ก๋ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ์ฌ์ด๋๋ฐ์์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.") | |
| else: | |
| st.success(f"โ {len(st.session_state.contents)}๊ฐ์ ์ด๋ฏธ์ง๊ฐ ๋ฑ๋ก๋์ด ์์ต๋๋ค.") | |
| st.markdown(""" | |
| ### ์ฌ์ฉ ๋ฐฉ๋ฒ | |
| 1. ์ผ์ชฝ ์ฌ์ด๋๋ฐ์์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํ์ธ์. | |
| 2. ์ด๋ฏธ์ง ์์๋ฅผ ์กฐ์ ํ๊ณ ์ ํ ํจ๊ณผ๋ฅผ ์ ํํ์ธ์. | |
| 3. ์ฌ์ ์ค์ ์์ ์ด๋ฏธ์ง ํ์ ๋ฐฉ์๊ณผ ์ ํ ๊ฐ๊ฒฉ์ ์ค์ ํ์ธ์. | |
| 4. ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์ ๋๋ ์ ์ฒดํ๋ฉด ๋ณด๊ธฐ ๋ฒํผ์ ํด๋ฆญํ์ฌ ์ฌ๋ผ์ด๋์ผ๋ฅผ ์์ํ์ธ์. | |
| ### ๊ธฐ๋ฅ ์๊ฐ | |
| - **์ด๋ฏธ์ง ์์ ์กฐ์ **: ๐๐ ๋ฒํผ์ผ๋ก ์ด๋ฏธ์ง ์์๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. | |
| - **์ด๋ฏธ์ง ๊ณ ์ **: ํน์ ์ด๋ฏธ์ง ํ๋๋ง ๊ณ์ ํ์ํ๋๋ก ์ค์ ํ ์ ์์ต๋๋ค. | |
| - **์ ํ ํจ๊ณผ**: ํ์ด๋, ์ค, ์ฌ๋ผ์ด๋, ํ์ ํจ๊ณผ๋ฅผ ์ ํํ ์ ์์ต๋๋ค. | |
| - **ํ์ ๋ฐฉ์**: ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ ๋๋ ์๋ณธ ๋น์จ์ ์ ์งํ๋ฉฐ ํ์ํ ์ ์์ต๋๋ค. | |
| - **์๋ ์ ํ**: ์ค์ ํ ๊ฐ๊ฒฉ์ผ๋ก ์ด๋ฏธ์ง๊ฐ ์๋ ์ ํ๋ฉ๋๋ค. | |
| ### ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ | |
| """) | |
| # ์ด๋ฏธ์ง ๊ทธ๋ฆฌ๋๋ก ํ์ | |
| if st.session_state.contents: | |
| cols = st.columns(4) | |
| for i, img_path in enumerate(st.session_state.contents): | |
| with cols[i % 4]: | |
| # use_column_width=True๋ฅผ use_container_width=True๋ก ๋ณ๊ฒฝ | |
| st.image(img_path, caption=os.path.basename(img_path), use_container_width=True) | |