JAMESPARK3 commited on
Commit
4ae2b1b
ยท
verified ยท
1 Parent(s): b7a9689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -4
app.py CHANGED
@@ -173,7 +173,42 @@ def inject_background_toggle_js():
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'):
@@ -197,11 +232,13 @@ if 'fit_mode' not in st.session_state:
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):
@@ -376,6 +413,26 @@ with st.sidebar:
376
  st.session_state.activate_fullscreen = False
377
  st.rerun()
378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  # ๋ฉ”์ธ ์ปจํ…์ธ  ์˜์—ญ
380
  if st.session_state.get('preview_mode', False):
381
  # ํ—ˆ๊น…ํŽ˜์ด์Šค UI ์š”์†Œ ์ˆจ๊ธฐ๊ธฐ ์œ„ํ•œ CSS ์ถ”๊ฐ€
@@ -558,4 +615,3 @@ else:
558
  # use_column_width=True๋ฅผ use_container_width=True๋กœ ๋ณ€๊ฒฝ
559
  st.image(img_path, caption=os.path.basename(img_path), use_container_width=True)
560
 
561
-
 
173
  """
174
  html(js_code, height=0, width=0)
175
 
176
+ # URL ํŒŒ๋ผ๋ฏธํ„ฐ ์ฒ˜๋ฆฌ
177
+ try:
178
+ query_params = st.query_params
179
+
180
+ # ์ „์ฒดํ™”๋ฉด ๋ชจ๋“œ ํ™•์ธ
181
+ if "fullscreen" in query_params and query_params["fullscreen"][0].lower() == "true":
182
+ st.session_state.preview_mode = True
183
+ st.session_state.activate_fullscreen = True
184
+
185
+ # ์ด๋ฏธ์ง€ ์ „ํ™˜ ๋ชจ๋“œ ํ™•์ธ
186
+ if "change" in query_params:
187
+ st.session_state.fixed_image_enabled = False
188
+
189
+ # ๋‹จ์ผ ์ด๋ฏธ์ง€ ๋ชจ๋“œ ํ™•์ธ
190
+ if "1image" in query_params:
191
+ st.session_state.fixed_image_enabled = True
192
+
193
+ # ํŠน์ • ์ด๋ฏธ์ง€ ์ธ๋ฑ์Šค๊ฐ€ ์ง€์ •๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
194
+ if "image" in query_params and query_params["image"][0].isdigit():
195
+ img_index = int(query_params["image"][0])
196
+
197
+ # contents ํด๋” ๋‚ด์˜ ๋ชจ๋“  ์ด๋ฏธ์ง€ ํŒŒ์ผ ๋ฏธ๋ฆฌ ๋กœ๋“œ
198
+ if not os.path.exists('contents'):
199
+ os.makedirs('contents')
200
+
201
+ image_files = glob.glob('contents/*.jpg') + glob.glob('contents/*.jpeg') + glob.glob('contents/*.png')
202
+
203
+ # ์ธ๋ฑ์Šค๊ฐ€ ์œ ํšจํ•œ์ง€ ํ™•์ธ
204
+ if 0 <= img_index < len(image_files):
205
+ st.session_state.fixed_image_path = image_files[img_index]
206
+ elif image_files: # ์œ ํšจํ•˜์ง€ ์•Š์ง€๋งŒ ์ด๋ฏธ์ง€๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€ ์‚ฌ์šฉ
207
+ st.session_state.fixed_image_path = image_files[0]
208
+ except Exception as e:
209
+ st.error(f"URL ํŒŒ๋ผ๋ฏธํ„ฐ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
210
+
211
+ # ์ดˆ๊ธฐ ์„ค์ • ๋ฐ ์ƒํƒœ ๊ด€๋ฆฌ (๊ธฐ์กด ์ฝ”๋“œ ์ˆ˜์ •)
212
  if 'contents' not in st.session_state:
213
  # contents ํด๋” ๋‚ด์˜ ๋ชจ๋“  ์ด๋ฏธ์ง€ ํŒŒ์ผ ๋กœ๋“œ
214
  if not os.path.exists('contents'):
 
232
  if 'app_loaded' not in st.session_state:
233
  st.session_state.app_loaded = False
234
 
235
+ # ๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ์กฐ๊ฑด๋ถ€๋กœ ์ˆ˜์ •
236
  if 'fixed_image_enabled' not in st.session_state:
237
  st.session_state.fixed_image_enabled = False
238
 
239
+ if 'fixed_image_path' not in st.session_state and st.session_state.contents:
240
+ st.session_state.fixed_image_path = st.session_state.contents[0] if st.session_state.contents else None
241
+
242
 
243
  # ์Šฌ๋ผ์ด๋“œ์‡ผ ์ž๋™ ์‹œ์ž‘ ๋กœ์ง
244
  if not st.session_state.app_loaded and not st.session_state.get('preview_mode', False):
 
413
  st.session_state.activate_fullscreen = False
414
  st.rerun()
415
 
416
+ # ์‚ฌ์ด๋“œ๋ฐ” ํ•˜๋‹จ์— URL ์ •๋ณด ์ถ”๊ฐ€
417
+ st.sidebar.markdown("---")
418
+ st.sidebar.subheader("์ ‘์† URL")
419
+
420
+ base_url = "https://jamespark3-display.hf.space/"
421
+
422
+ # ์ด๋ฏธ์ง€ ์ „ํ™˜ ๋ชจ๋“œ URL
423
+ transition_url = f"{base_url}?fullscreen=true&change"
424
+ st.sidebar.text_area("์ด๋ฏธ์ง€ ์ „ํ™˜ ๋ชจ๋“œ", transition_url, help="์ด URL๋กœ ์ ‘์†ํ•˜๋ฉด ์ž๋™์œผ๋กœ ์ด๋ฏธ์ง€ ์ „ํ™˜ ๋ชจ๋“œ๋กœ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค.")
425
+
426
+ # ๋‹จ์ผ ์ด๋ฏธ์ง€ ๋ชจ๋“œ URL
427
+ if st.session_state.fixed_image_enabled and st.session_state.fixed_image_path and st.session_state.contents:
428
+ 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
429
+ single_url = f"{base_url}?fullscreen=true&1image&image={current_img_index}"
430
+ st.sidebar.text_area("ํ˜„์žฌ ์„ ํƒ๋œ ์ด๋ฏธ์ง€ ๋ชจ๋“œ", single_url, help="์ด URL๋กœ ์ ‘์†ํ•˜๋ฉด ์„ ํƒ๋œ ์ด๋ฏธ์ง€๋งŒ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.")
431
+ else:
432
+ single_url = f"{base_url}?fullscreen=true&1image"
433
+ st.sidebar.text_area("๋‹จ์ผ ์ด๋ฏธ์ง€ ๋ชจ๋“œ", single_url, help="์ด URL๋กœ ์ ‘์†ํ•˜๋ฉด ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€๊ฐ€ ๊ณ ์ •๋˜์–ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.")
434
+
435
+
436
  # ๋ฉ”์ธ ์ปจํ…์ธ  ์˜์—ญ
437
  if st.session_state.get('preview_mode', False):
438
  # ํ—ˆ๊น…ํŽ˜์ด์Šค UI ์š”์†Œ ์ˆจ๊ธฐ๊ธฐ ์œ„ํ•œ CSS ์ถ”๊ฐ€
 
615
  # use_column_width=True๋ฅผ use_container_width=True๋กœ ๋ณ€๊ฒฝ
616
  st.image(img_path, caption=os.path.basename(img_path), use_container_width=True)
617