code-slicer commited on
Commit
2b477ef
·
verified ·
1 Parent(s): dc7c184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -45
app.py CHANGED
@@ -190,51 +190,47 @@ st.markdown(
190
  # 고정 이미지 URL
191
  #BG_URL = "https://plus.unsplash.com/premium_photo-1679830513869-cd3648acb1db?q=80&w=2127&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
192
 
193
- COLOR = "#F1F1F1"
194
-
195
- st.markdown(f"""
196
- <style>
197
- /* 기존 배경/레이어 정리 */
198
- .stApp {{ background: transparent !important; }}
199
- .stApp::after, .block-container::before, .block-container::after {{ content: none !important; }}
200
-
201
- /* 중앙 변수 (페이지 레이아웃에 맞춰 필요시 1000~1200px 튜닝) */
202
- :root {{ --col-w: min(1200px, 95vw); }}
203
-
204
- /* 상단·배경 투명 처리 */
205
- header[data-testid="stHeader"],
206
- [data-testid="stAppViewContainer"],
207
- main, section.main {{ background: transparent !important; }}
208
-
209
- /* 남아있을 있는 레이어 제거 */
210
- .stApp::before, .stApp::after,
211
- .block-container::before, .block-container::after {{ content:none !important; }}
212
-
213
- /* ✅ 단색 배경: '한 장'을 viewport에 고정 → 스크롤해도 안 잘림
214
- 중앙 컬럼 폭만 보이도록 좌우를 clip-path로 잘라냄 */
215
- .stApp::before {{
216
- content:"";
217
- position: fixed;
218
- inset: 0; /* 풀스크린 */
219
- background: {COLOR};
220
- pointer-events: none;
221
- z-index: 0;
222
-
223
- /* 가운데 정렬된 컬럼 폭만 남기고 좌우는 가림 */
224
- clip-path: inset(0 calc((100vw - var(--col-w))/2) 0 calc((100vw - var(--col-w))/2));
225
-
226
- /* 재합성 이음새 방지 보정 */
227
- will-change: transform;
228
- transform: translateZ(0);
229
- }}
230
-
231
- /* 실제 콘텐츠는 배경 위로 */
232
- .block-container, [data-testid="stSidebar"] {{
233
- position: relative;
234
- z-index: 1;
235
- }}
236
- </style>
237
- """, unsafe_allow_html=True)
238
 
239
 
240
 
 
190
  # 고정 이미지 URL
191
  #BG_URL = "https://plus.unsplash.com/premium_photo-1679830513869-cd3648acb1db?q=80&w=2127&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
192
 
193
+ # === 배경 설정 UI ===
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
 
236