code-slicer commited on
Commit
d266088
ยท
verified ยท
1 Parent(s): 22eb5d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -32
app.py CHANGED
@@ -194,42 +194,74 @@ BG_URL = "https://plus.unsplash.com/premium_photo-1679830513869-cd3648acb1db?q=8
194
  st.sidebar.subheader("๐ŸŽจ ๋ฐฐ๊ฒฝ ์„ค์ •")
195
  st.sidebar.toggle("๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์‚ฌ์šฉ", key="bg_on", value=True)
196
 
197
- def apply_background(): # ๋ณดํ˜ธ: ๊ธฐ์กด ::before ๋ฐฐ๊ฒฝ์ด ์žˆ์œผ๋ฉด ๋„๊ธฐ (๊ฒน์นจ/๋Š๊น€ ๋ฐฉ์ง€)
198
- base_reset_css = """
199
- <style>
200
- .stApp::before, .block-container::before{ content:none !important; }
201
- /* ์ปจํ…์ธ /์‚ฌ์ด๋“œ๋ฐ”๋Š” ๋ฐฐ๊ฒฝ ๋ ˆ์ด์–ด ์œ„์— ์˜ค๋„๋ก */
202
- .block-container, [data-testid="stSidebar"]{ position:relative; z-index:1; }
203
- /* ์ž…๋ ฅ๋ฐ•์Šค ์•„๋ž˜ ์—ฌ๋ฐฑ (์š”์ฒญ 2๋ฒˆ) */
204
- div[data-testid="stTextInput"]{ margin-bottom:18px !important; }
205
- </style>
206
- """
207
-
208
- st.markdown(base_reset_css, unsafe_allow_html=True)
209
- if st.session_state.get("bg_on") and st.session_state.get("bg_url"):
210
- url = st.session_state["bg_url"] # 0~1 ๋กœ ๋ณ€ํ™˜ (ํฐ ์˜ค๋ฒ„๋ ˆ์ด๋กœ ๋ฐ๊ธฐ/๊ฐ€๋…์„ฑ ์กฐ์ ˆ)
211
- overlay_alpha = float(st.session_state.get("bg_overlay_pct", 15)) / 100.0 # โœ… ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ (๋Š๊น€ ๋ฐฉ์ง€: ํŽ˜์ด์ง€ ์ „์ฒด .stApp์— ๊ณ ์ • ๋ฐฐ๊ฒฝ)
212
- st.markdown(f"""
213
- <style>
214
- .stApp{{ background: url('{url}') center / cover no-repeat fixed; }}
215
- /* ์˜ค๋ฒ„๋ ˆ์ด: ์ด๋ฏธ์ง€ ์œ„์— ํฐ์ƒ‰ ๋ง‰์„ ์–น์–ด ๊ฐ€๋…์„ฑ ํ™•๋ณด (ํˆฌ๋ช…๋„ ์กฐ์ ˆ ๊ฐ€๋Šฅ) */
216
- .stApp::after{{ content:""; position:fixed; inset:0; z-index:0; pointer-events:none; background: rgba(255,255,255,{overlay_alpha}); }}
217
- /* ๋ชจ๋ฐ”์ผ์€ fixed ์ด์Šˆ๊ฐ€ ์žˆ์–ด ๊ณ ์ • ํ•ด์ œ */
218
 
219
- @media (max-width:768px){{ .stApp{{ background-attachment: initial; }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  }}
221
- </style>
222
- """, unsafe_allow_html=True)
223
- else:
224
- # โœ… ๋‹จ์ƒ‰ ๋ฐฐ๊ฒฝ (๋Š๊น€ ์—†์Œ: ์š”์†Œ ์ž์ฒด์˜ background-color ์‚ฌ์šฉ)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  color = st.session_state.get("bg_color", "#F1F1F1")
226
- st.markdown(f"""
227
  <style>
228
- .stApp{{ background-color: {color} !important; }}
229
- </style>
230
- """, unsafe_allow_html=True)
231
-
232
- # ํ˜ธ์ถœ
 
 
233
  apply_background()
234
 
235
 
 
194
  st.sidebar.subheader("๐ŸŽจ ๋ฐฐ๊ฒฝ ์„ค์ •")
195
  st.sidebar.toggle("๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์‚ฌ์šฉ", key="bg_on", value=True)
196
 
197
+ # ๋‚˜๋จธ์ง€ ์ƒ์„ธ ์„ค์ •์€ expander ์•ˆ์— ๋„ฃ์–ด ๊น”๋”ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
198
+ with st.expander("๋ฐฐ๊ฒฝ ์˜ต์…˜ ํŽผ์น˜๊ธฐ"):
199
+ st.text_input("๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ URL", key="bg_url", value="https://images.unsplash.com/photo-1506744038136-46273834b3fb")
200
+ st.slider("๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์˜ค๋ฒ„๋ ˆ์ด (%)", 0, 100, 15, key="bg_overlay_pct")
201
+ st.color_picker("๋‹จ์ƒ‰ ๋ฐฐ๊ฒฝ ์ƒ‰์ƒ", key="bg_color", value="#F1F1F1")
202
+
203
+
204
+ def apply_background():
205
+ # ๋ณดํ˜ธ: ๊ธฐ์กด ::before ๋ฐฐ๊ฒฝ์ด ์žˆ์œผ๋ฉด ๋„๊ธฐ (๊ฒน์นจ/๋Š๊น€ ๋ฐฉ์ง€)
206
+ base_reset_css = """
207
+ <style>
208
+ .stApp::before, .block-container::before { content:none !important; }
209
+ /* ์ž…๋ ฅ๋ฐ•์Šค ์•„๋ž˜ ์—ฌ๋ฐฑ */
210
+ div[data-testid="stTextInput"] { margin-bottom:18px !important; }
211
+ </style>
212
+ """
213
+ st.markdown(base_reset_css, unsafe_allow_html=True)
214
+
215
+ if st.session_state.get("bg_on") and st.session_state.get("bg_url"):
216
+ url = st.session_state["bg_url"]
217
+ overlay_alpha = float(st.session_state.get("bg_overlay_pct", 15)) / 100.0
218
 
219
+ # โœ… ์ด๋ฏธ์ง€ ๋ฐฐ๊ฒฝ (๋ฉ”์ธ ์ปจํ…์ธ  ์˜์—ญ์—๋งŒ ๊ณ ์ • ๋ฐฐ๊ฒฝ ์ ์šฉ)
220
+ st.markdown(f"""
221
+ <style>
222
+ [data-testid="stAppViewContainer"] {{
223
+ background: url('{url}') center / cover no-repeat fixed;
224
+ position: relative; /* ์˜ค๋ฒ„๋ ˆ์ด์˜ ๊ธฐ์ค€์ ์ด ๋˜๋„๋ก ์„ค์ • */
225
+ z-index: 0; /* ์ปจํ…์ธ ๊ฐ€ ์œ„์— ์˜ค๋„๋ก */
226
+ }}
227
+
228
+ /* ์˜ค๋ฒ„๋ ˆ์ด: ์ด๋ฏธ์ง€ ์œ„์— ํฐ์ƒ‰ ๋ง‰์„ ์–น์–ด ๊ฐ€๋…์„ฑ ํ™•๋ณด */
229
+ [data-testid="stAppViewContainer"]::after {{
230
+ content: "";
231
+ position: absolute; /* ๋ถ€๋ชจ(stAppViewContainer)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์œ„์น˜ */
232
+ inset: 0;
233
+ background: rgba(255, 255, 255, {overlay_alpha});
234
+ z-index: -1; /* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ๋ฐ”๋กœ ์œ„์— ์˜ค๋„๋ก */
235
+ pointer-events: none;
236
  }}
237
+
238
+ /* ์ปจํ…์ธ ์™€ ์‚ฌ์ด๋“œ๋ฐ”๊ฐ€ ๋ฐฐ๊ฒฝ๋ณด๋‹ค ์œ„์— ์˜ค๋„๋ก */
239
+ .block-container, [data-testid="stSidebar"] {{
240
+ position: relative;
241
+ z-index: 1;
242
+ }}
243
+
244
+ /* ๋ชจ๋ฐ”์ผ์€ fixed ์ด์Šˆ๊ฐ€ ์žˆ์–ด ๊ณ ์ • ํ•ด์ œ */
245
+ @media (max-width: 768px) {{
246
+ [data-testid="stAppViewContainer"] {{
247
+ background-attachment: initial;
248
+ }}
249
+ }}
250
+ </style>
251
+ """, unsafe_allow_html=True)
252
+
253
+ else:
254
+ # โœ… ๋‹จ์ƒ‰ ๋ฐฐ๊ฒฝ (๋ฉ”์ธ ์ปจํ…์ธ  ์˜์—ญ์—๋งŒ ์ ์šฉ)
255
  color = st.session_state.get("bg_color", "#F1F1F1")
256
+ st.markdown(f"""
257
  <style>
258
+ [data-testid="stAppViewContainer"] {{
259
+ background-color: {color} !important;
260
+ }}
261
+ </style>
262
+ """, unsafe_allow_html=True)
263
+
264
+ # ํ•จ์ˆ˜ ํ˜ธ์ถœ
265
  apply_background()
266
 
267