Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,10 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
-
import time
|
| 4 |
-
import random
|
| 5 |
-
from PIL import Image
|
| 6 |
import glob
|
| 7 |
-
|
| 8 |
import base64
|
| 9 |
from streamlit.components.v1 import html
|
| 10 |
-
import
|
| 11 |
|
| 12 |
# ํ์ด์ง ์ค์
|
| 13 |
st.set_page_config(
|
|
@@ -17,223 +14,130 @@ st.set_page_config(
|
|
| 17 |
initial_sidebar_state="collapsed"
|
| 18 |
)
|
| 19 |
|
| 20 |
-
# CSS
|
| 21 |
st.markdown("""
|
| 22 |
<style>
|
| 23 |
-
|
| 24 |
-
padding: 0;
|
| 25 |
-
max-width: 100%;
|
| 26 |
-
}
|
| 27 |
-
.stApp {
|
| 28 |
-
margin: 0;
|
| 29 |
-
padding: 0;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
/* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์คํ์ผ๋ก ์์ */
|
| 33 |
.full-view {
|
| 34 |
-
width: 100vw;
|
| 35 |
-
height: 100vh;
|
| 36 |
position: fixed;
|
| 37 |
top: 0;
|
| 38 |
left: 0;
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
background-size: cover;
|
| 42 |
background-position: center;
|
| 43 |
background-repeat: no-repeat;
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
align-items: flex-end;
|
| 48 |
-
padding: 20px;
|
| 49 |
}
|
| 50 |
|
| 51 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
.view-toggle {
|
| 53 |
-
background: rgba(0,0,0,0.5);
|
| 54 |
color: white;
|
| 55 |
border: none;
|
| 56 |
-
padding:
|
| 57 |
margin: 5px;
|
| 58 |
border-radius: 4px;
|
| 59 |
cursor: pointer;
|
| 60 |
font-size: 14px;
|
| 61 |
}
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
.controls-panel {
|
| 65 |
-
display: flex;
|
| 66 |
-
gap: 10px;
|
| 67 |
-
margin-top: 10px;
|
| 68 |
}
|
| 69 |
|
| 70 |
-
/*
|
| 71 |
-
.
|
| 72 |
-
|
| 73 |
-
align-items: center;
|
| 74 |
-
margin-bottom: 5px;
|
| 75 |
}
|
| 76 |
-
.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
-
/* ์ ๋๋ฉ์ด์
์์ */
|
| 86 |
@keyframes fadeIn {
|
| 87 |
-
|
| 88 |
-
|
| 89 |
}
|
| 90 |
@keyframes zoomIn {
|
| 91 |
-
|
| 92 |
-
|
| 93 |
}
|
| 94 |
@keyframes slideIn {
|
| 95 |
-
|
| 96 |
-
|
| 97 |
}
|
| 98 |
@keyframes rotateIn {
|
| 99 |
-
|
| 100 |
-
|
| 101 |
}
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
-
.
|
| 107 |
-
|
|
|
|
| 108 |
}
|
| 109 |
-
.
|
| 110 |
-
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
-
.
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
| 114 |
}
|
| 115 |
</style>
|
| 116 |
""", unsafe_allow_html=True)
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
if 'contents' not in st.session_state:
|
| 120 |
-
# contents ํด๋ ๋ด์ ๋ชจ๋ ์ด๋ฏธ์ง ํ์ผ ๋ก๋
|
| 121 |
-
if not os.path.exists('contents'):
|
| 122 |
-
os.makedirs('contents')
|
| 123 |
-
|
| 124 |
-
image_files = glob.glob('contents/*.jpg') + glob.glob('contents/*.jpeg') + glob.glob('contents/*.png')
|
| 125 |
-
st.session_state.contents = image_files
|
| 126 |
-
|
| 127 |
-
if 'current_image_index' not in st.session_state:
|
| 128 |
-
st.session_state.current_image_index = 0
|
| 129 |
-
|
| 130 |
-
if 'animation_type' not in st.session_state:
|
| 131 |
-
st.session_state.animation_type = 'animate-fade'
|
| 132 |
-
|
| 133 |
-
if 'activate_fullscreen' not in st.session_state:
|
| 134 |
-
st.session_state.activate_fullscreen = False
|
| 135 |
-
|
| 136 |
-
if 'fit_mode' not in st.session_state:
|
| 137 |
-
st.session_state.fit_mode = 'cover' # ๊ธฐ๋ณธ๊ฐ์ ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ
|
| 138 |
-
|
| 139 |
-
# ์ฌ๊ธฐ์ ์ถ๊ฐํ์ธ์!
|
| 140 |
-
if 'app_loaded' not in st.session_state:
|
| 141 |
-
st.session_state.app_loaded = False
|
| 142 |
-
|
| 143 |
-
# ์ฌ๋ผ์ด๋์ผ ์๋ ์์ ๋ก์ง
|
| 144 |
-
if not st.session_state.app_loaded and not st.session_state.get('preview_mode', False):
|
| 145 |
-
if st.session_state.contents: # ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ์๋ ์์
|
| 146 |
-
st.session_state.preview_mode = True
|
| 147 |
-
st.session_state.preview_start_time = time.time()
|
| 148 |
-
st.session_state.activate_fullscreen = True
|
| 149 |
-
st.session_state.app_loaded = True # ์ฑ์ด ๋ก๋๋์์์ ํ์
|
| 150 |
-
|
| 151 |
-
# ์ด๋ฏธ์ง ์ธ๋ค์ผ ์์ฑ ํจ์
|
| 152 |
-
def create_thumbnail(image_path, size=(60, 60)):
|
| 153 |
-
try:
|
| 154 |
-
img = Image.open(image_path)
|
| 155 |
-
img.thumbnail(size)
|
| 156 |
-
buffered = io.BytesIO()
|
| 157 |
-
img.save(buffered, format=img.format or "JPEG")
|
| 158 |
-
return buffered.getvalue()
|
| 159 |
-
except Exception as e:
|
| 160 |
-
st.error(f"์ธ๋ค์ผ ์์ฑ ์ค๋ฅ: {e}")
|
| 161 |
-
return None
|
| 162 |
-
|
| 163 |
-
# ์ด๋ฏธ์ง ์์ ๋ณ๊ฒฝ ํจ์๋ค
|
| 164 |
-
def move_up(index):
|
| 165 |
-
if index > 0:
|
| 166 |
-
st.session_state.contents[index], st.session_state.contents[index-1] = st.session_state.contents[index-1], st.session_state.contents[index]
|
| 167 |
-
|
| 168 |
-
def move_down(index):
|
| 169 |
-
if index < len(st.session_state.contents) - 1:
|
| 170 |
-
st.session_state.contents[index], st.session_state.contents[index+1] = st.session_state.contents[index+1], st.session_state.contents[index]
|
| 171 |
-
|
| 172 |
-
def move_to_top(index):
|
| 173 |
-
if index > 0:
|
| 174 |
-
item = st.session_state.contents.pop(index)
|
| 175 |
-
st.session_state.contents.insert(0, item)
|
| 176 |
-
|
| 177 |
-
def move_to_bottom(index):
|
| 178 |
-
if index < len(st.session_state.contents) - 1:
|
| 179 |
-
item = st.session_state.contents.pop(index)
|
| 180 |
-
st.session_state.contents.append(item)
|
| 181 |
-
|
| 182 |
-
# ์๋ ์ ์ฒดํ๋ฉด ๋ชจ๋๋ฅผ ์ํ JavaScript ํจ์
|
| 183 |
def inject_fullscreen_js():
|
| 184 |
js_code = """
|
| 185 |
<script>
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
if (fullscreenButton) {
|
| 192 |
-
// ๋ฒํผ์ด ์์ผ๋ฉด ํด๋ฆญ
|
| 193 |
-
fullscreenButton.click();
|
| 194 |
-
} else {
|
| 195 |
-
// ๋ฒํผ์ ์ฐพ์ ์ ์์ผ๋ฉด ๋ธ๋ผ์ฐ์ API ์ฌ์ฉ
|
| 196 |
-
var elem = document.documentElement;
|
| 197 |
if (elem.requestFullscreen) {
|
| 198 |
elem.requestFullscreen();
|
| 199 |
-
} else if (elem.
|
| 200 |
-
elem.mozRequestFullScreen();
|
| 201 |
-
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
|
| 202 |
-
elem.webkitRequestFullscreen();
|
| 203 |
-
} else if (elem.msRequestFullscreen) { /* IE/Edge */
|
| 204 |
elem.msRequestFullscreen();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
}
|
| 206 |
}
|
| 207 |
}
|
| 208 |
-
|
| 209 |
-
// 1์ด ํ ์ ์ฒดํ๋ฉด ํ์ฑํ
|
| 210 |
setTimeout(function() {
|
| 211 |
-
|
| 212 |
}, 1000);
|
| 213 |
</script>
|
| 214 |
"""
|
| 215 |
html(js_code, height=0, width=0)
|
| 216 |
|
| 217 |
-
# ์ ๋๋ฉ์ด์
JS๋ฅผ ์ฃผ์
ํ๋ ํจ์
|
| 218 |
-
def inject_animation_js(animation_type):
|
| 219 |
-
js_code = f"""
|
| 220 |
-
<script>
|
| 221 |
-
// ์ ๋๋ฉ์ด์
์ ์ฉ
|
| 222 |
-
function applyAnimation() {{
|
| 223 |
-
const imageContainer = document.querySelector('.full-view img');
|
| 224 |
-
if (imageContainer) {{
|
| 225 |
-
imageContainer.classList.remove('animate-fade', 'animate-zoom', 'animate-slide', 'animate-rotate');
|
| 226 |
-
void imageContainer.offsetWidth; // ๊ฐ์ ๋ฆฌํ๋ก์ฐ
|
| 227 |
-
imageContainer.classList.add('{animation_type}');
|
| 228 |
-
}}
|
| 229 |
-
}}
|
| 230 |
-
|
| 231 |
-
// ํ์ด์ง ๋ก๋ ํ ์ ๋๋ฉ์ด์
์ ์ฉ
|
| 232 |
-
setTimeout(applyAnimation, 100);
|
| 233 |
-
</script>
|
| 234 |
-
"""
|
| 235 |
-
html(js_code, height=0, width=0)
|
| 236 |
-
|
| 237 |
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ํ์ ๋ฐฉ์ ์ ํ์ ์ํ JavaScript ํจ์
|
| 238 |
def inject_background_toggle_js():
|
| 239 |
js_code = """
|
|
@@ -269,149 +173,286 @@ def inject_background_toggle_js():
|
|
| 269 |
"""
|
| 270 |
html(js_code, height=0, width=0)
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
-
# ์ฌ์ด๋๋ฐ
|
| 274 |
with st.sidebar:
|
| 275 |
-
st.title("
|
| 276 |
|
| 277 |
# ์ด๋ฏธ์ง ์
๋ก๋
|
| 278 |
-
|
|
|
|
|
|
|
| 279 |
if uploaded_files:
|
| 280 |
-
for
|
| 281 |
-
#
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
with open(file_path, "wb") as f:
|
| 284 |
-
f.write(
|
| 285 |
|
| 286 |
-
# ๋ชฉ๋ก์ ์ถ๊ฐ (์ค๋ณต
|
| 287 |
if file_path not in st.session_state.contents:
|
| 288 |
st.session_state.contents.append(file_path)
|
| 289 |
|
| 290 |
st.success(f"{len(uploaded_files)}๊ฐ ์ด๋ฏธ์ง๊ฐ ์ถ๊ฐ๋์์ต๋๋ค.")
|
| 291 |
|
| 292 |
-
#
|
| 293 |
-
st.subheader("
|
| 294 |
|
| 295 |
if not st.session_state.contents:
|
| 296 |
-
st.info("
|
| 297 |
else:
|
| 298 |
-
# ํ์ ์์
|
| 299 |
for i, img_path in enumerate(st.session_state.contents):
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
# ์ธ๋ค์ผ๊ณผ ํ์ผ๋ช
์ ํฌํจํ HTML ์์ฑ
|
| 303 |
-
thumbnail_data = create_thumbnail(img_path)
|
| 304 |
-
if thumbnail_data:
|
| 305 |
-
thumbnail_b64 = base64.b64encode(thumbnail_data).decode()
|
| 306 |
-
st.markdown(f"""
|
| 307 |
-
<div class="thumbnail-container">
|
| 308 |
-
<img src="data:image/jpeg;base64,{thumbnail_b64}" alt="{img_name}" />
|
| 309 |
-
<div>{i+1}. {img_name}</div>
|
| 310 |
-
</div>
|
| 311 |
-
""", unsafe_allow_html=True)
|
| 312 |
-
else:
|
| 313 |
-
st.write(f"{i+1}. {img_name}")
|
| 314 |
|
| 315 |
-
# ์์ ๋ฒํผ๋ค
|
| 316 |
-
col1, col2 = st.columns(2)
|
| 317 |
with col1:
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
st.rerun()
|
| 321 |
|
| 322 |
with col2:
|
| 323 |
-
|
| 324 |
-
|
|
|
|
| 325 |
st.rerun()
|
| 326 |
-
|
| 327 |
-
col3, col4 = st.columns(2)
|
| 328 |
-
with col3:
|
| 329 |
-
if st.button("โค ๋งจ์๋ก", key=f"top_{i}", help="๋งจ ์๋ก ์ด๋"):
|
| 330 |
-
move_to_top(i)
|
| 331 |
-
st.rerun()
|
| 332 |
-
|
| 333 |
-
with col4:
|
| 334 |
-
if st.button("โค ๋งจ์๋๋ก", key=f"bottom_{i}", help="๋งจ ์๋๋ก ์ด๋"):
|
| 335 |
-
move_to_bottom(i)
|
| 336 |
-
st.rerun()
|
| 337 |
-
|
| 338 |
-
# ์ญ์ ๋ฒํผ
|
| 339 |
-
if st.button("๐๏ธ ์ญ์ ", key=f"del_{i}", help="์ด๋ฏธ์ง ์ญ์ "):
|
| 340 |
-
if os.path.exists(img_path):
|
| 341 |
-
# ํ์ผ ์ญ์ ์ฌ๋ถ ํ์ธ
|
| 342 |
-
if st.session_state.contents.count(img_path) == 1:
|
| 343 |
-
os.remove(img_path)
|
| 344 |
|
| 345 |
-
#
|
| 346 |
-
st.session_state.contents.
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
if st.session_state.current_image_index >= len(st.session_state.contents):
|
| 350 |
-
st.session_state.current_image_index = 0
|
| 351 |
|
| 352 |
-
|
|
|
|
|
|
|
|
|
|
| 353 |
|
| 354 |
st.markdown("<hr>", unsafe_allow_html=True)
|
| 355 |
|
| 356 |
-
#
|
| 357 |
-
st.subheader("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
animation_options = {
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
}
|
| 364 |
-
|
| 365 |
-
|
|
|
|
| 366 |
options=list(animation_options.keys()),
|
| 367 |
format_func=lambda x: animation_options[x],
|
| 368 |
-
index=list(animation_options.keys()).index(st.session_state.animation_type)
|
| 369 |
)
|
|
|
|
| 370 |
if selected_animation != st.session_state.animation_type:
|
| 371 |
st.session_state.animation_type = selected_animation
|
| 372 |
|
| 373 |
# ์ฌ์ ์ค์
|
| 374 |
st.subheader("์ฌ์ ์ค์ ")
|
| 375 |
-
preview_interval = st.slider("ํ์ ๊ฐ๊ฒฉ (์ด)", 2, 10, 5)
|
| 376 |
|
| 377 |
-
# ํ์
|
| 378 |
-
fit_options = {
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
"์ด๋ฏธ์ง ํ์ ๋ฐฉ์",
|
| 381 |
options=list(fit_options.keys()),
|
| 382 |
format_func=lambda x: fit_options[x],
|
| 383 |
-
index=list(fit_options.keys()).index(st.session_state.fit_mode)
|
| 384 |
)
|
|
|
|
| 385 |
if selected_fit != st.session_state.fit_mode:
|
| 386 |
st.session_state.fit_mode = selected_fit
|
| 387 |
|
| 388 |
-
#
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
# ๋ฉ์ธ ์ปจํ
์ธ ์์ญ
|
| 401 |
if st.session_state.get('preview_mode', False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
# ์๋ ์๋ก๊ณ ์นจ์ ์ํ ์นด์ดํฐ
|
| 403 |
count = st_autorefresh(interval=preview_interval * 1000, key="refreshInterval")
|
| 404 |
|
| 405 |
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ ํ JS ์ฝ์
(๋จผ์ ์คํ๋์ด์ผ ํจ)
|
| 406 |
inject_background_toggle_js()
|
| 407 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
# ํ์ฌ ์ธ๋ฑ์ค ์
๋ฐ์ดํธ
|
| 409 |
if count > 0 and st.session_state.contents:
|
| 410 |
-
|
|
|
|
|
|
|
| 411 |
|
| 412 |
# ํ๋ฉด์ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ก ํ์
|
| 413 |
if st.session_state.contents:
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
# ์น์์ ์ ๊ทผ ๊ฐ๋ฅํ ์ด๋ฏธ์ง URL๋ก ๋ณํ (Base64 ์ธ์ฝ๋ฉ ์ฌ์ฉ)
|
| 417 |
with open(full_img_path, "rb") as img_file:
|
|
@@ -420,7 +461,7 @@ if st.session_state.get('preview_mode', False):
|
|
| 420 |
# ์ด๋ฏธ์ง ํ์ฅ์ ๊ฐ์ ธ์ค๊ธฐ (๊ธฐ๋ณธ๊ฐ์ jpeg)
|
| 421 |
file_ext = os.path.splitext(full_img_path)[1][1:] or "jpeg"
|
| 422 |
|
| 423 |
-
|
| 424 |
background_html = f"""
|
| 425 |
<div class="full-view animate-{st.session_state.animation_type}"
|
| 426 |
style="background-image: url('data:image/{file_ext};base64,{img_data}');
|
|
@@ -455,8 +496,22 @@ if st.session_state.get('preview_mode', False):
|
|
| 455 |
window.applyBackgroundAnimation('animate-{st.session_state.animation_type}');
|
| 456 |
}}
|
| 457 |
}}, 1500);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
</script>
|
| 459 |
"""
|
|
|
|
| 460 |
|
| 461 |
# HTML ์ง์ ์ฝ์
|
| 462 |
st.markdown(background_html, unsafe_allow_html=True)
|
|
@@ -469,28 +524,36 @@ if st.session_state.get('preview_mode', False):
|
|
| 469 |
footer {visibility: hidden;}
|
| 470 |
</style>
|
| 471 |
""", unsafe_allow_html=True)
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
else:
|
| 475 |
-
st.info("ํ์ํ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.")
|
| 476 |
-
if st.button("๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ข
๋ฃ"):
|
| 477 |
-
st.session_state.preview_mode = False
|
| 478 |
-
st.rerun()
|
| 479 |
-
|
| 480 |
else:
|
| 481 |
-
# ์ผ๋ฐ ๋ชจ๋ -
|
| 482 |
-
st.title("๋์คํ๋ ์ด ์ปจํ
์ธ ๊ด๋ฆฌ")
|
| 483 |
|
| 484 |
if not st.session_state.contents:
|
| 485 |
-
st.
|
| 486 |
else:
|
| 487 |
-
st.
|
| 488 |
-
|
| 489 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
cols = st.columns(4)
|
| 491 |
for i, img_path in enumerate(st.session_state.contents):
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
else:
|
| 495 |
-
break
|
| 496 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
| 3 |
import glob
|
| 4 |
+
import time
|
| 5 |
import base64
|
| 6 |
from streamlit.components.v1 import html
|
| 7 |
+
from streamlit_autorefresh import st_autorefresh
|
| 8 |
|
| 9 |
# ํ์ด์ง ์ค์
|
| 10 |
st.set_page_config(
|
|
|
|
| 14 |
initial_sidebar_state="collapsed"
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# ์ ์ญ CSS ์ค์
|
| 18 |
st.markdown("""
|
| 19 |
<style>
|
| 20 |
+
/* ์ ์ฒด ํ๋ฉด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์คํ์ผ */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
.full-view {
|
|
|
|
|
|
|
| 22 |
position: fixed;
|
| 23 |
top: 0;
|
| 24 |
left: 0;
|
| 25 |
+
width: 100vw;
|
| 26 |
+
height: 100vh;
|
|
|
|
| 27 |
background-position: center;
|
| 28 |
background-repeat: no-repeat;
|
| 29 |
+
background-color: black;
|
| 30 |
+
transition: opacity 1s ease-in-out;
|
| 31 |
+
z-index: 9998;
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
+
/* ์ปจํธ๋กค ํจ๋ ์คํ์ผ */
|
| 35 |
+
.controls-panel {
|
| 36 |
+
position: fixed;
|
| 37 |
+
bottom: 20px;
|
| 38 |
+
right: 20px;
|
| 39 |
+
z-index: 9999;
|
| 40 |
+
opacity: 0.2;
|
| 41 |
+
transition: opacity 0.3s;
|
| 42 |
+
}
|
| 43 |
+
.controls-panel:hover {
|
| 44 |
+
opacity: 1;
|
| 45 |
+
}
|
| 46 |
.view-toggle {
|
| 47 |
+
background-color: rgba(0, 0, 0, 0.5);
|
| 48 |
color: white;
|
| 49 |
border: none;
|
| 50 |
+
padding: 8px 16px;
|
| 51 |
margin: 5px;
|
| 52 |
border-radius: 4px;
|
| 53 |
cursor: pointer;
|
| 54 |
font-size: 14px;
|
| 55 |
}
|
| 56 |
+
.view-toggle:hover {
|
| 57 |
+
background-color: rgba(0, 0, 0, 0.8);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
|
| 60 |
+
/* ์ ๋๋ฉ์ด์
ํจ๊ณผ */
|
| 61 |
+
.animate-fade {
|
| 62 |
+
animation: fadeIn 2s;
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
+
.animate-zoom {
|
| 65 |
+
animation: zoomIn 2s;
|
| 66 |
+
}
|
| 67 |
+
.animate-slide {
|
| 68 |
+
animation: slideIn 2s;
|
| 69 |
+
}
|
| 70 |
+
.animate-rotate {
|
| 71 |
+
animation: rotateIn 2s;
|
| 72 |
}
|
| 73 |
|
|
|
|
| 74 |
@keyframes fadeIn {
|
| 75 |
+
from { opacity: 0; }
|
| 76 |
+
to { opacity: 1; }
|
| 77 |
}
|
| 78 |
@keyframes zoomIn {
|
| 79 |
+
from { transform: scale(0.7); opacity: 0; }
|
| 80 |
+
to { transform: scale(1); opacity: 1; }
|
| 81 |
}
|
| 82 |
@keyframes slideIn {
|
| 83 |
+
from { transform: translateY(20%); opacity: 0; }
|
| 84 |
+
to { transform: translateY(0); opacity: 1; }
|
| 85 |
}
|
| 86 |
@keyframes rotateIn {
|
| 87 |
+
from { transform: rotate(-10deg) scale(0.9); opacity: 0; }
|
| 88 |
+
to { transform: rotate(0) scale(1); opacity: 1; }
|
| 89 |
}
|
| 90 |
|
| 91 |
+
/* ์ด๋ฏธ์ง ๊ด๋ฆฌ ๊ทธ๋ฆฌ๋ ์คํ์ผ */
|
| 92 |
+
.image-item {
|
| 93 |
+
position: relative;
|
| 94 |
+
margin-bottom: 10px;
|
| 95 |
}
|
| 96 |
+
.image-item img {
|
| 97 |
+
width: 100%;
|
| 98 |
+
border-radius: 4px;
|
| 99 |
}
|
| 100 |
+
.image-actions {
|
| 101 |
+
position: absolute;
|
| 102 |
+
top: 5px;
|
| 103 |
+
right: 5px;
|
| 104 |
}
|
| 105 |
+
.image-name {
|
| 106 |
+
font-size: 12px;
|
| 107 |
+
overflow: hidden;
|
| 108 |
+
text-overflow: ellipsis;
|
| 109 |
+
white-space: nowrap;
|
| 110 |
}
|
| 111 |
</style>
|
| 112 |
""", unsafe_allow_html=True)
|
| 113 |
|
| 114 |
+
# ์ ์ฒด ํ๋ฉด JS ํจ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
def inject_fullscreen_js():
|
| 116 |
js_code = """
|
| 117 |
<script>
|
| 118 |
+
function toggleFullScreen() {
|
| 119 |
+
var elem = document.documentElement;
|
| 120 |
+
if (!document.fullscreenElement && !document.mozFullScreenElement &&
|
| 121 |
+
!document.webkitFullscreenElement && !document.msFullscreenElement) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if (elem.requestFullscreen) {
|
| 123 |
elem.requestFullscreen();
|
| 124 |
+
} else if (elem.msRequestFullscreen) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
elem.msRequestFullscreen();
|
| 126 |
+
} else if (elem.mozRequestFullScreen) {
|
| 127 |
+
elem.mozRequestFullScreen();
|
| 128 |
+
} else if (elem.webkitRequestFullscreen) {
|
| 129 |
+
elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
| 130 |
}
|
| 131 |
}
|
| 132 |
}
|
| 133 |
+
// ์ ์ฒด ํ๋ฉด ํ์ฑํ ์๋
|
|
|
|
| 134 |
setTimeout(function() {
|
| 135 |
+
toggleFullScreen();
|
| 136 |
}, 1000);
|
| 137 |
</script>
|
| 138 |
"""
|
| 139 |
html(js_code, height=0, width=0)
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ํ์ ๋ฐฉ์ ์ ํ์ ์ํ JavaScript ํจ์
|
| 142 |
def inject_background_toggle_js():
|
| 143 |
js_code = """
|
|
|
|
| 173 |
"""
|
| 174 |
html(js_code, height=0, width=0)
|
| 175 |
|
| 176 |
+
# ์ด๊ธฐ ์ค์ ๋ฐ ์ํ ๊ด๋ฆฌ
|
| 177 |
+
if 'contents' not in st.session_state:
|
| 178 |
+
# contents ํด๋ ๋ด์ ๋ชจ๋ ์ด๋ฏธ์ง ํ์ผ ๋ก๋
|
| 179 |
+
if not os.path.exists('contents'):
|
| 180 |
+
os.makedirs('contents')
|
| 181 |
+
|
| 182 |
+
image_files = glob.glob('contents/*.jpg') + glob.glob('contents/*.jpeg') + glob.glob('contents/*.png')
|
| 183 |
+
st.session_state.contents = image_files
|
| 184 |
+
|
| 185 |
+
if 'current_image_index' not in st.session_state:
|
| 186 |
+
st.session_state.current_image_index = 0
|
| 187 |
+
|
| 188 |
+
if 'animation_type' not in st.session_state:
|
| 189 |
+
st.session_state.animation_type = 'animate-fade'
|
| 190 |
+
|
| 191 |
+
if 'activate_fullscreen' not in st.session_state:
|
| 192 |
+
st.session_state.activate_fullscreen = False
|
| 193 |
+
|
| 194 |
+
if 'fit_mode' not in st.session_state:
|
| 195 |
+
st.session_state.fit_mode = 'cover' # ๊ธฐ๋ณธ๊ฐ์ ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ
|
| 196 |
+
|
| 197 |
+
if 'app_loaded' not in st.session_state:
|
| 198 |
+
st.session_state.app_loaded = False
|
| 199 |
+
|
| 200 |
+
if 'fixed_image_enabled' not in st.session_state:
|
| 201 |
+
st.session_state.fixed_image_enabled = False
|
| 202 |
+
|
| 203 |
+
if 'fixed_image_path' not in st.session_state:
|
| 204 |
+
st.session_state.fixed_image_path = None
|
| 205 |
+
|
| 206 |
+
# ์ฌ๋ผ์ด๋์ผ ์๋ ์์ ๋ก์ง
|
| 207 |
+
if not st.session_state.app_loaded and not st.session_state.get('preview_mode', False):
|
| 208 |
+
if st.session_state.contents: # ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ์๋ ์์
|
| 209 |
+
st.session_state.preview_mode = True
|
| 210 |
+
st.session_state.preview_start_time = time.time()
|
| 211 |
+
st.session_state.activate_fullscreen = True
|
| 212 |
+
st.session_state.app_loaded = True # ์ฑ์ด ๋ก๋๋์์์ ํ์
|
| 213 |
|
| 214 |
+
# ์ฌ์ด๋๋ฐ - ์ด๋ฏธ์ง ๊ด๋ฆฌ
|
| 215 |
with st.sidebar:
|
| 216 |
+
st.title("๐ธ ๋์คํ๋ ์ด ์ค์ ")
|
| 217 |
|
| 218 |
# ์ด๋ฏธ์ง ์
๋ก๋
|
| 219 |
+
st.subheader("์ด๋ฏธ์ง ์ถ๊ฐ")
|
| 220 |
+
uploaded_files = st.file_uploader("์ด๋ฏธ์ง ํ์ผ์ ์
๋ก๋ํ์ธ์", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
|
| 221 |
+
|
| 222 |
if uploaded_files:
|
| 223 |
+
for uploaded_file in uploaded_files:
|
| 224 |
+
# contents ๋๋ ํ ๋ฆฌ๊ฐ ์์ผ๋ฉด ์์ฑ
|
| 225 |
+
if not os.path.exists('contents'):
|
| 226 |
+
os.makedirs('contents')
|
| 227 |
+
|
| 228 |
+
# ์ ์ฅ ๊ฒฝ๋ก ์์ฑ
|
| 229 |
+
file_path = os.path.join('contents', uploaded_file.name)
|
| 230 |
+
|
| 231 |
+
# ์ด๋ฏธ์ง ์ ์ฅ
|
| 232 |
with open(file_path, "wb") as f:
|
| 233 |
+
f.write(uploaded_file.getvalue())
|
| 234 |
|
| 235 |
+
# ์ ์ฅ๋ ์ด๋ฏธ์ง๋ฅผ ๋ชฉ๋ก์ ์ถ๊ฐ (์ค๋ณต ๋ฐฉ์ง)
|
| 236 |
if file_path not in st.session_state.contents:
|
| 237 |
st.session_state.contents.append(file_path)
|
| 238 |
|
| 239 |
st.success(f"{len(uploaded_files)}๊ฐ ์ด๋ฏธ์ง๊ฐ ์ถ๊ฐ๋์์ต๋๋ค.")
|
| 240 |
|
| 241 |
+
# ์ด๋ฏธ์ง ๋ชฉ๋ก ๋ฐ ๊ด๋ฆฌ
|
| 242 |
+
st.subheader("์ด๋ฏธ์ง ์์ ์กฐ์ ")
|
| 243 |
|
| 244 |
if not st.session_state.contents:
|
| 245 |
+
st.info("๋ฑ๋ก๋ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.")
|
| 246 |
else:
|
| 247 |
+
# ์ด๋ฏธ์ง ๋ชฉ๋ก ํ์ ๋ฐ ์์ ์กฐ์
|
| 248 |
for i, img_path in enumerate(st.session_state.contents):
|
| 249 |
+
col1, col2 = st.columns([3, 1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
|
|
|
|
|
|
| 251 |
with col1:
|
| 252 |
+
st.text(os.path.basename(img_path))
|
| 253 |
+
st.image(img_path, width=150)
|
|
|
|
| 254 |
|
| 255 |
with col2:
|
| 256 |
+
# ์๋ก ์ด๋ ๋ฒํผ
|
| 257 |
+
if i > 0 and st.button("๐", key=f"up_{i}"):
|
| 258 |
+
st.session_state.contents[i], st.session_state.contents[i-1] = st.session_state.contents[i-1], st.session_state.contents[i]
|
| 259 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
+
# ์๋๋ก ์ด๋ ๋ฒํผ
|
| 262 |
+
if i < len(st.session_state.contents) - 1 and st.button("๐", key=f"down_{i}"):
|
| 263 |
+
st.session_state.contents[i], st.session_state.contents[i+1] = st.session_state.contents[i+1], st.session_state.contents[i]
|
| 264 |
+
st.rerun()
|
|
|
|
|
|
|
| 265 |
|
| 266 |
+
# ์ญ์ ๋ฒํผ
|
| 267 |
+
if st.button("๐๏ธ", key=f"delete_{i}"):
|
| 268 |
+
del st.session_state.contents[i]
|
| 269 |
+
st.rerun()
|
| 270 |
|
| 271 |
st.markdown("<hr>", unsafe_allow_html=True)
|
| 272 |
|
| 273 |
+
# ์ด๋ฏธ์ง ๊ณ ์ ์ค์
|
| 274 |
+
st.subheader("์ด๋ฏธ์ง ๊ณ ์ ์ค์ ")
|
| 275 |
+
fixed_image_enabled = st.checkbox(
|
| 276 |
+
"ํ ์ด๋ฏธ์ง๋ง ๊ณ ์ ํ์ฌ ํ์",
|
| 277 |
+
value=st.session_state.fixed_image_enabled,
|
| 278 |
+
help="์ฒดํฌํ๋ฉด ์ ํํ ์ด๋ฏธ์ง๋ง ๊ณ์ ํ์๋ฉ๋๋ค. ์ฌ๋ผ์ด๋์ผ๊ฐ ์ค์ง๋ฉ๋๋ค."
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
# ์ฒดํฌ๋ฐ์ค ์ํ๊ฐ ๋ณ๊ฒฝ๋์์ ๋ ์ธ์
์ํ ์
๋ฐ์ดํธ
|
| 282 |
+
if fixed_image_enabled != st.session_state.fixed_image_enabled:
|
| 283 |
+
st.session_state.fixed_image_enabled = fixed_image_enabled
|
| 284 |
+
# ๊ณ ์ ๋ชจ๋๊ฐ ๋นํ์ฑํ๋๋ฉด ์ฌ๋ผ์ด๋์ผ ์ฌ๊ฐ
|
| 285 |
+
if not fixed_image_enabled and st.session_state.get('preview_mode', False):
|
| 286 |
+
st.session_state.preview_start_time = time.time()
|
| 287 |
+
|
| 288 |
+
# ์ด๋ฏธ์ง ๊ณ ์ ๋ชจ๋๊ฐ ํ์ฑํ๋ ๊ฒฝ์ฐ์๋ง ์ด๋ฏธ์ง ์ ํ ๋๋กญ๋ค์ด ํ์
|
| 289 |
+
if st.session_state.fixed_image_enabled:
|
| 290 |
+
# ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก์์ ํ์ผ๋ช
๋ง ์ถ์ถํ์ฌ ํ์ ์ต์
์์ฑ
|
| 291 |
+
image_options = {img_path: os.path.basename(img_path) for img_path in st.session_state.contents}
|
| 292 |
+
|
| 293 |
+
# ์ ํ๋ ์ด๋ฏธ์ง๊ฐ ์๊ฑฐ๋ ๋ชฉ๋ก์ ์๋ ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง ์ ํ
|
| 294 |
+
default_index = 0
|
| 295 |
+
if st.session_state.fixed_image_path in image_options:
|
| 296 |
+
default_index = list(image_options.keys()).index(st.session_state.fixed_image_path)
|
| 297 |
+
|
| 298 |
+
# ์ด๋ฏธ์ง ์ ํ ๋๋กญ๋ค์ด
|
| 299 |
+
if st.session_state.contents: # ์ด๋ฏธ์ง๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ๋๋กญ๋ค์ด ํ์
|
| 300 |
+
selected_image = st.selectbox(
|
| 301 |
+
"๊ณ ์ ํ ์ด๋ฏธ์ง ์ ํ",
|
| 302 |
+
options=list(image_options.keys()),
|
| 303 |
+
format_func=lambda x: image_options[x],
|
| 304 |
+
index=default_index
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
# ์ ํ๋ ์ด๋ฏธ์ง ์ ์ฅ
|
| 308 |
+
st.session_state.fixed_image_path = selected_image
|
| 309 |
+
|
| 310 |
+
# ์ ํ๋ ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํ์
|
| 311 |
+
st.image(selected_image, caption="์ ํ๋ ์ด๋ฏธ์ง", width=200)
|
| 312 |
+
else:
|
| 313 |
+
st.warning("ํ์ํ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.")
|
| 314 |
+
|
| 315 |
+
# ์ ๋๋ฉ์ด์
ํจ๊ณผ ์ ํ (๊ณ์)
|
| 316 |
animation_options = {
|
| 317 |
+
'animate-fade': 'ํ์ด๋ ์ธ/์์',
|
| 318 |
+
'animate-zoom': '์ค ์ธ/์์',
|
| 319 |
+
'animate-slide': '์ฌ๋ผ์ด๋',
|
| 320 |
+
'animate-rotate': 'ํ์ '
|
| 321 |
}
|
| 322 |
+
|
| 323 |
+
selected_animation = st.radio(
|
| 324 |
+
"์ ํ ํจ๊ณผ ์ ํ",
|
| 325 |
options=list(animation_options.keys()),
|
| 326 |
format_func=lambda x: animation_options[x],
|
| 327 |
+
index=list(animation_options.keys()).index(st.session_state.animation_type) if st.session_state.animation_type in animation_options else 0
|
| 328 |
)
|
| 329 |
+
|
| 330 |
if selected_animation != st.session_state.animation_type:
|
| 331 |
st.session_state.animation_type = selected_animation
|
| 332 |
|
| 333 |
# ์ฌ์ ์ค์
|
| 334 |
st.subheader("์ฌ์ ์ค์ ")
|
|
|
|
| 335 |
|
| 336 |
+
# ์ด๋ฏธ์ง ํ์ ๋ชจ๋ ์ ํ
|
| 337 |
+
fit_options = {
|
| 338 |
+
'cover': 'ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ',
|
| 339 |
+
'contain': '์๋ณธ ๋น์จ ์ ์ง'
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
selected_fit = st.radio(
|
| 343 |
"์ด๋ฏธ์ง ํ์ ๋ฐฉ์",
|
| 344 |
options=list(fit_options.keys()),
|
| 345 |
format_func=lambda x: fit_options[x],
|
| 346 |
+
index=list(fit_options.keys()).index(st.session_state.fit_mode) if st.session_state.fit_mode in fit_options else 0
|
| 347 |
)
|
| 348 |
+
|
| 349 |
if selected_fit != st.session_state.fit_mode:
|
| 350 |
st.session_state.fit_mode = selected_fit
|
| 351 |
|
| 352 |
+
# ์ฌ๋ผ์ด๋์ผ ๊ฐ๊ฒฉ ์ค์
|
| 353 |
+
preview_interval = st.slider("์ด๋ฏธ์ง ์ ํ ๊ฐ๊ฒฉ (์ด)", min_value=1, max_value=60, value=10)
|
| 354 |
+
|
| 355 |
+
# ์ฌ๋ผ์ด๋์ผ ์์/์ข
๋ฃ ๋ฒํผ
|
| 356 |
+
col1, col2 = st.columns(2)
|
| 357 |
+
|
| 358 |
+
with col1:
|
| 359 |
+
if st.button("๐ผ๏ธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์", use_container_width=True):
|
| 360 |
+
st.session_state.preview_mode = True
|
| 361 |
+
st.session_state.preview_start_time = time.time()
|
| 362 |
+
st.session_state.activate_fullscreen = False
|
| 363 |
+
st.rerun()
|
| 364 |
+
|
| 365 |
+
with col2:
|
| 366 |
+
if st.button("๐ ์ ์ฒดํ๋ฉด ๋ณด๊ธฐ", use_container_width=True):
|
| 367 |
+
st.session_state.preview_mode = True
|
| 368 |
+
st.session_state.preview_start_time = time.time()
|
| 369 |
+
st.session_state.activate_fullscreen = True
|
| 370 |
+
st.rerun()
|
| 371 |
+
|
| 372 |
+
# ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ชจ๋์ธ ๊ฒฝ์ฐ ์ข
๋ฃ ๋ฒํผ ํ์
|
| 373 |
+
if st.session_state.get('preview_mode', False):
|
| 374 |
+
if st.button("โน๏ธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ข
๋ฃ", use_container_width=True):
|
| 375 |
+
st.session_state.preview_mode = False
|
| 376 |
+
st.session_state.activate_fullscreen = False
|
| 377 |
+
st.rerun()
|
| 378 |
|
| 379 |
# ๋ฉ์ธ ์ปจํ
์ธ ์์ญ
|
| 380 |
if st.session_state.get('preview_mode', False):
|
| 381 |
+
# ํ๊น
ํ์ด์ค UI ์์ ์จ๊ธฐ๊ธฐ ์ํ CSS ์ถ๊ฐ
|
| 382 |
+
st.markdown("""
|
| 383 |
+
<style>
|
| 384 |
+
/* ํ๊น
ํ์ด์ค ํค๋ ๋ฐ ๊ด๋ จ UI ์์ ์จ๊ธฐ๊ธฐ */
|
| 385 |
+
div.css-1avcm0n {display: none !important;} /* ์๋จ ํค๋ */
|
| 386 |
+
div.css-14xtw13 {display: none !important;} /* ๊ณต๊ฐ */
|
| 387 |
+
section.css-1lcbmhc {display: none !important;} /* ์ฌ์ด๋๋ฐ */
|
| 388 |
+
div.css-1dp5vir {display: none !important;} /* ๊ธฐํ UI ์์ */
|
| 389 |
+
div.e1nzilvr5 {display: none !important;}
|
| 390 |
+
div.viewerBadge_link__1S137 {display: none !important;}
|
| 391 |
+
div.css-1bgch32 {display: none !important;}
|
| 392 |
+
|
| 393 |
+
/* Streamlit ์์ ์จ๊ธฐ๊ธฐ */
|
| 394 |
+
#MainMenu {visibility: hidden !important;}
|
| 395 |
+
header {visibility: hidden !important;}
|
| 396 |
+
footer {visibility: hidden !important;}
|
| 397 |
+
|
| 398 |
+
/* iframe ๊ด๋ จ ์ค์ */
|
| 399 |
+
iframe {border: none !important;}
|
| 400 |
+
|
| 401 |
+
/* ์ฑ ์ปจํ
์ด๋ ์ ์ฒด ํ๋ฉด ์ค์ */
|
| 402 |
+
.main .block-container {
|
| 403 |
+
padding: 0 !important;
|
| 404 |
+
max-width: 100% !important;
|
| 405 |
+
}
|
| 406 |
+
.stApp {
|
| 407 |
+
margin: 0 !important;
|
| 408 |
+
padding: 0 !important;
|
| 409 |
+
height: 100vh !important;
|
| 410 |
+
width: 100vw !important;
|
| 411 |
+
overflow: hidden !important;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
/* ์ ์ฒด ํ๋ฉด ์ค์ ๊ฐํ */
|
| 415 |
+
body {
|
| 416 |
+
margin: 0 !important;
|
| 417 |
+
padding: 0 !important;
|
| 418 |
+
overflow: hidden !important;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
/* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ปจํ
์ด๋ ์์ */
|
| 422 |
+
.full-view {
|
| 423 |
+
position: fixed !important;
|
| 424 |
+
top: 0 !important;
|
| 425 |
+
left: 0 !important;
|
| 426 |
+
width: 100vw !important;
|
| 427 |
+
height: 100vh !important;
|
| 428 |
+
z-index: 9999 !important;
|
| 429 |
+
}
|
| 430 |
+
</style>
|
| 431 |
+
""", unsafe_allow_html=True)
|
| 432 |
+
|
| 433 |
# ์๋ ์๋ก๊ณ ์นจ์ ์ํ ์นด์ดํฐ
|
| 434 |
count = st_autorefresh(interval=preview_interval * 1000, key="refreshInterval")
|
| 435 |
|
| 436 |
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ ํ JS ์ฝ์
(๋จผ์ ์คํ๋์ด์ผ ํจ)
|
| 437 |
inject_background_toggle_js()
|
| 438 |
|
| 439 |
+
# ์ ์ฒดํ๋ฉด ํ์ฑํ ํ์์ ์คํ
|
| 440 |
+
if st.session_state.activate_fullscreen:
|
| 441 |
+
inject_fullscreen_js()
|
| 442 |
+
|
| 443 |
# ํ์ฌ ์ธ๋ฑ์ค ์
๋ฐ์ดํธ
|
| 444 |
if count > 0 and st.session_state.contents:
|
| 445 |
+
# ์ด๋ฏธ์ง ๊ณ ์ ๋ชจ๋๊ฐ ํ์ฑํ๋์ง ์์ ๊ฒฝ์ฐ์๋ง ์ด๋ฏธ์ง ๋ณ๊ฒฝ
|
| 446 |
+
if not st.session_state.fixed_image_enabled:
|
| 447 |
+
st.session_state.current_image_index = (st.session_state.current_image_index + 1) % len(st.session_state.contents)
|
| 448 |
|
| 449 |
# ํ๋ฉด์ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง๋ก ํ์
|
| 450 |
if st.session_state.contents:
|
| 451 |
+
# ์ด๋ฏธ์ง ๊ณ ์ ๋ชจ๋๊ฐ ํ์ฑํ๋ ๊ฒฝ์ฐ ๊ณ ์ ์ด๋ฏธ์ง ์ฌ์ฉ, ์๋๋ฉด ํ์ฌ ์ธ๋ฑ์ค ์ด๋ฏธ์ง ์ฌ์ฉ
|
| 452 |
+
if st.session_state.fixed_image_enabled and st.session_state.fixed_image_path:
|
| 453 |
+
full_img_path = st.session_state.fixed_image_path
|
| 454 |
+
else:
|
| 455 |
+
full_img_path = st.session_state.contents[st.session_state.current_image_index]
|
| 456 |
|
| 457 |
# ์น์์ ์ ๊ทผ ๊ฐ๋ฅํ ์ด๋ฏธ์ง URL๋ก ๋ณํ (Base64 ์ธ์ฝ๋ฉ ์ฌ์ฉ)
|
| 458 |
with open(full_img_path, "rb") as img_file:
|
|
|
|
| 461 |
# ์ด๋ฏธ์ง ํ์ฅ์ ๊ฐ์ ธ์ค๊ธฐ (๊ธฐ๋ณธ๊ฐ์ jpeg)
|
| 462 |
file_ext = os.path.splitext(full_img_path)[1][1:] or "jpeg"
|
| 463 |
|
| 464 |
+
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ค์ ๊ณผ ์ปจํธ๋กค ๋ฒํผ์ด ํฌํจ๋ HTML ์์ฑ
|
| 465 |
background_html = f"""
|
| 466 |
<div class="full-view animate-{st.session_state.animation_type}"
|
| 467 |
style="background-image: url('data:image/{file_ext};base64,{img_data}');
|
|
|
|
| 496 |
window.applyBackgroundAnimation('animate-{st.session_state.animation_type}');
|
| 497 |
}}
|
| 498 |
}}, 1500);
|
| 499 |
+
|
| 500 |
+
// ํ๊น
ํ์ด์ค ์์ ์จ๊ธฐ๊ธฐ ๊ฐํ
|
| 501 |
+
function hideHuggingfaceElements() {{
|
| 502 |
+
const huggingfaceElements = document.querySelectorAll('.css-1avcm0n, .css-14xtw13, .css-1lcbmhc, .css-1dp5vir, .e1nzilvr5, .viewerBadge_link__1S137, .css-1bgch32');
|
| 503 |
+
huggingfaceElements.forEach(el => {{
|
| 504 |
+
if(el) el.style.display = 'none';
|
| 505 |
+
}});
|
| 506 |
+
}}
|
| 507 |
+
|
| 508 |
+
// ์ฌ๋ฌ ๋ฒ ์๋ํ์ฌ UI ์์ ์จ๊ธฐ๊ธฐ
|
| 509 |
+
setTimeout(hideHuggingfaceElements, 1000);
|
| 510 |
+
setTimeout(hideHuggingfaceElements, 2000);
|
| 511 |
+
setTimeout(hideHuggingfaceElements, 5000);
|
| 512 |
</script>
|
| 513 |
"""
|
| 514 |
+
|
| 515 |
|
| 516 |
# HTML ์ง์ ์ฝ์
|
| 517 |
st.markdown(background_html, unsafe_allow_html=True)
|
|
|
|
| 524 |
footer {visibility: hidden;}
|
| 525 |
</style>
|
| 526 |
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
else:
|
| 528 |
+
# ์ผ๋ฐ ๋ชจ๋ - ์ฑ ์๊ฐ ๋ฐ ์ฌ์ฉ๋ฒ
|
| 529 |
+
st.title("๐ผ๏ธ ๋์งํธ ๋์คํ๋ ์ด ์ปจํ
์ธ ๊ด๋ฆฌ")
|
| 530 |
|
| 531 |
if not st.session_state.contents:
|
| 532 |
+
st.warning("โ ๏ธ ๋ฑ๋ก๋ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ์ฌ์ด๋๋ฐ์์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์.")
|
| 533 |
else:
|
| 534 |
+
st.success(f"โ
{len(st.session_state.contents)}๊ฐ์ ์ด๋ฏธ์ง๊ฐ ๋ฑ๋ก๋์ด ์์ต๋๋ค.")
|
| 535 |
+
|
| 536 |
+
st.markdown("""
|
| 537 |
+
### ์ฌ์ฉ ๋ฐฉ๋ฒ
|
| 538 |
+
1. ์ผ์ชฝ ์ฌ์ด๋๋ฐ์์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํ์ธ์.
|
| 539 |
+
2. ์ด๋ฏธ์ง ์์๋ฅผ ์กฐ์ ํ๊ณ ์ ํ ํจ๊ณผ๋ฅผ ์ ํํ์ธ์.
|
| 540 |
+
3. ์ฌ์ ์ค์ ์์ ์ด๋ฏธ์ง ํ์ ๋ฐฉ์๊ณผ ์ ํ ๊ฐ๊ฒฉ์ ์ค์ ํ์ธ์.
|
| 541 |
+
4. ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์ ๋๋ ์ ์ฒดํ๋ฉด ๋ณด๊ธฐ ๋ฒํผ์ ํด๋ฆญํ์ฌ ์ฌ๋ผ์ด๋์ผ๋ฅผ ์์ํ์ธ์.
|
| 542 |
+
|
| 543 |
+
### ๊ธฐ๋ฅ ์๊ฐ
|
| 544 |
+
- **์ด๋ฏธ์ง ์์ ์กฐ์ **: ๐๐ ๋ฒํผ์ผ๋ก ์ด๋ฏธ์ง ์์๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
|
| 545 |
+
- **์ด๋ฏธ์ง ๊ณ ์ **: ํน์ ์ด๋ฏธ์ง ํ๋๋ง ๊ณ์ ํ์ํ๋๋ก ์ค์ ํ ์ ์์ต๋๋ค.
|
| 546 |
+
- **์ ํ ํจ๊ณผ**: ํ์ด๋, ์ค, ์ฌ๋ผ์ด๋, ํ์ ํจ๊ณผ๋ฅผ ์ ํํ ์ ์์ต๋๋ค.
|
| 547 |
+
- **ํ์ ๋ฐฉ์**: ํ๋ฉด์ ๊ฝ ์ฐจ๊ฒ ๋๋ ์๋ณธ ๋น์จ์ ์ ์งํ๋ฉฐ ํ์ํ ์ ์์ต๋๋ค.
|
| 548 |
+
- **์๋ ์ ํ**: ์ค์ ํ ๊ฐ๊ฒฉ์ผ๋ก ์ด๋ฏธ์ง๊ฐ ์๋ ์ ํ๋ฉ๋๋ค.
|
| 549 |
+
|
| 550 |
+
### ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
| 551 |
+
""")
|
| 552 |
+
|
| 553 |
+
# ์ด๋ฏธ์ง ๊ทธ๋ฆฌ๋๋ก ํ์
|
| 554 |
+
if st.session_state.contents:
|
| 555 |
cols = st.columns(4)
|
| 556 |
for i, img_path in enumerate(st.session_state.contents):
|
| 557 |
+
with cols[i % 4]:
|
| 558 |
+
st.image(img_path, caption=os.path.basename(img_path), use_column_width=True)
|
|
|
|
|
|
|
| 559 |
|