Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import qrcode
|
|
| 8 |
from PIL import Image
|
| 9 |
import io
|
| 10 |
|
| 11 |
-
# 自訂 CSS
|
| 12 |
st.markdown("""
|
| 13 |
<style>
|
| 14 |
.stApp header h1 {
|
|
@@ -18,7 +18,6 @@ st.markdown("""
|
|
| 18 |
font-size: 2rem; /* 調整字體大小為 2rem,約 32px */
|
| 19 |
}
|
| 20 |
.stImage > img {
|
| 21 |
-
max-width: 95%; /* 圖片寬度幾乎填滿 */
|
| 22 |
max-height: 80vh; /* 圖片高度接近視窗高度 */
|
| 23 |
object-fit: contain; /* 保持比例 */
|
| 24 |
}
|
|
@@ -43,50 +42,31 @@ st.markdown("""
|
|
| 43 |
padding: 5px;
|
| 44 |
}
|
| 45 |
/* 頒獎台樣式 */
|
| 46 |
-
.podium-container {
|
| 47 |
-
display: flex;
|
| 48 |
-
justify-content: center;
|
| 49 |
-
align-items: flex-end;
|
| 50 |
-
margin-top: 20px;
|
| 51 |
-
margin-bottom: 20px;
|
| 52 |
-
}
|
| 53 |
.podium {
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
align-items: center;
|
| 57 |
margin: 0 10px;
|
| 58 |
-
|
| 59 |
-
.podium-step {
|
| 60 |
-
background-color: #d3d3d3; /* 灰色台子 */
|
| 61 |
border: 2px solid #000;
|
| 62 |
-
text-align: center;
|
| 63 |
-
font-weight: bold;
|
| 64 |
color: #333;
|
| 65 |
-
|
| 66 |
-
align-items: center;
|
| 67 |
-
justify-content: center;
|
| 68 |
}
|
| 69 |
-
.podium
|
| 70 |
-
|
| 71 |
-
height: 150px; /* 第一名台子最高 */
|
| 72 |
background-color: #ffd700; /* 金色 */
|
| 73 |
}
|
| 74 |
-
.podium
|
| 75 |
-
width: 120px;
|
| 76 |
height: 120px; /* 第二名次之 */
|
| 77 |
background-color: #c0c0c0; /* 銀色 */
|
| 78 |
}
|
| 79 |
-
.podium
|
| 80 |
-
width: 120px;
|
| 81 |
height: 90px; /* 第三名最低 */
|
| 82 |
background-color: #cd7f32; /* 銅色 */
|
| 83 |
}
|
| 84 |
.podium-label {
|
| 85 |
margin-top: 5px;
|
| 86 |
font-size: 1rem;
|
| 87 |
-
text-align: center;
|
| 88 |
color: #333;
|
| 89 |
-
white-space: pre-line; /* 允許換行 */
|
| 90 |
}
|
| 91 |
</style>
|
| 92 |
""", unsafe_allow_html=True)
|
|
@@ -308,47 +288,43 @@ def main():
|
|
| 308 |
top_3 = valid_df.head(3)
|
| 309 |
|
| 310 |
if len(top_3) > 0:
|
| 311 |
-
#
|
| 312 |
-
podium_html = '<div class="podium-container">'
|
| 313 |
|
| 314 |
# 第二名(如果有)
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
|
| 326 |
# 第一名(如果有)
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
|
| 338 |
# 第三名(如果有)
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
podium_html += '</div>'
|
| 351 |
-
st.markdown(podium_html, unsafe_allow_html=True)
|
| 352 |
else:
|
| 353 |
st.warning("無有效的查詢結果可供顯示頒獎台。")
|
| 354 |
else:
|
|
|
|
| 8 |
from PIL import Image
|
| 9 |
import io
|
| 10 |
|
| 11 |
+
# 自訂 CSS 確保標題不換行、調整圖片大小、優化按鈕布局、右下角資訊
|
| 12 |
st.markdown("""
|
| 13 |
<style>
|
| 14 |
.stApp header h1 {
|
|
|
|
| 18 |
font-size: 2rem; /* 調整字體大小為 2rem,約 32px */
|
| 19 |
}
|
| 20 |
.stImage > img {
|
|
|
|
| 21 |
max-height: 80vh; /* 圖片高度接近視窗高度 */
|
| 22 |
object-fit: contain; /* 保持比例 */
|
| 23 |
}
|
|
|
|
| 42 |
padding: 5px;
|
| 43 |
}
|
| 44 |
/* 頒獎台樣式 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
.podium {
|
| 46 |
+
text-align: center;
|
| 47 |
+
padding: 10px;
|
|
|
|
| 48 |
margin: 0 10px;
|
| 49 |
+
background-color: #d3d3d3;
|
|
|
|
|
|
|
| 50 |
border: 2px solid #000;
|
|
|
|
|
|
|
| 51 |
color: #333;
|
| 52 |
+
font-weight: bold;
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
+
.podium.first {
|
| 55 |
+
height: 150px; /* 第一名最高 */
|
|
|
|
| 56 |
background-color: #ffd700; /* 金色 */
|
| 57 |
}
|
| 58 |
+
.podium.second {
|
|
|
|
| 59 |
height: 120px; /* 第二名次之 */
|
| 60 |
background-color: #c0c0c0; /* 銀色 */
|
| 61 |
}
|
| 62 |
+
.podium.third {
|
|
|
|
| 63 |
height: 90px; /* 第三名最低 */
|
| 64 |
background-color: #cd7f32; /* 銅色 */
|
| 65 |
}
|
| 66 |
.podium-label {
|
| 67 |
margin-top: 5px;
|
| 68 |
font-size: 1rem;
|
|
|
|
| 69 |
color: #333;
|
|
|
|
| 70 |
}
|
| 71 |
</style>
|
| 72 |
""", unsafe_allow_html=True)
|
|
|
|
| 288 |
top_3 = valid_df.head(3)
|
| 289 |
|
| 290 |
if len(top_3) > 0:
|
| 291 |
+
col1, col2, col3 = st.columns(3) # 創建三列
|
|
|
|
| 292 |
|
| 293 |
# 第二名(如果有)
|
| 294 |
+
with col1:
|
| 295 |
+
if len(top_3) >= 2:
|
| 296 |
+
second = top_3.iloc[1]
|
| 297 |
+
st.markdown(
|
| 298 |
+
f'<div class="podium second">{int(second["查詢結果"])}</div>'
|
| 299 |
+
f'<div class="podium-label">{second["姓名"]}\n{second["幸運號碼"]}</div>',
|
| 300 |
+
unsafe_allow_html=True
|
| 301 |
+
)
|
| 302 |
+
else:
|
| 303 |
+
st.markdown('<div class="podium second"></div><div class="podium-label"></div>', unsafe_allow_html=True)
|
| 304 |
|
| 305 |
# 第一名(如果有)
|
| 306 |
+
with col2:
|
| 307 |
+
if len(top_3) >= 1:
|
| 308 |
+
first = top_3.iloc[0]
|
| 309 |
+
st.markdown(
|
| 310 |
+
f'<div class="podium first">{int(first["查詢結果"])}</div>'
|
| 311 |
+
f'<div class="podium-label">{first["姓名"]}\n{first["幸運號碼"]}</div>',
|
| 312 |
+
unsafe_allow_html=True
|
| 313 |
+
)
|
| 314 |
+
else:
|
| 315 |
+
st.markdown('<div class="podium first"></div><div class="podium-label"></div>', unsafe_allow_html=True)
|
| 316 |
|
| 317 |
# 第三名(如果有)
|
| 318 |
+
with col3:
|
| 319 |
+
if len(top_3) >= 3:
|
| 320 |
+
third = top_3.iloc[2]
|
| 321 |
+
st.markdown(
|
| 322 |
+
f'<div class="podium third">{int(third["查詢結果"])}</div>'
|
| 323 |
+
f'<div class="podium-label">{third["姓名"]}\n{third["幸運號碼"]}</div>',
|
| 324 |
+
unsafe_allow_html=True
|
| 325 |
+
)
|
| 326 |
+
else:
|
| 327 |
+
st.markdown('<div class="podium third"></div><div class="podium-label"></div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
| 328 |
else:
|
| 329 |
st.warning("無有效的查詢結果可供顯示頒獎台。")
|
| 330 |
else:
|