Lashtw commited on
Commit
d07506b
·
verified ·
1 Parent(s): cdc59b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -3
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 {
@@ -33,7 +33,7 @@ st.markdown("""
33
  .st-ds {
34
  justify-content: space-between; /* 兩列間距均等 */
35
  }
36
- /* 添加右下角資訊 */
37
  .footer {
38
  position: fixed;
39
  bottom: 10px;
@@ -42,6 +42,48 @@ st.markdown("""
42
  color: #666;
43
  padding: 5px;
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  </style>
46
  """, unsafe_allow_html=True)
47
 
@@ -255,8 +297,58 @@ def main():
255
  )
256
  # 顯示圖表
257
  st.plotly_chart(fig, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  else:
259
- st.warning("無有效的查詢結果可供繪製長條圖。請確認資料是否正確。")
260
 
261
  except Exception as e:
262
  st.error(f"處理檔案時發生錯誤: {str(e)}")
 
8
  from PIL import Image
9
  import io
10
 
11
+ # 自訂 CSS 確保標題不換行、調整圖片大小、優化按鈕布局、右下角資訊並添加頒獎台樣式
12
  st.markdown("""
13
  <style>
14
  .stApp header h1 {
 
33
  .st-ds {
34
  justify-content: space-between; /* 兩列間距均等 */
35
  }
36
+ /* 右下角資訊 */
37
  .footer {
38
  position: fixed;
39
  bottom: 10px;
 
42
  color: #666;
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
+ display: flex;
55
+ flex-direction: column;
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
+ .podium-step.first {
67
+ width: 100px;
68
+ height: 150px; /* 第一名台子最高 */
69
+ background-color: #ffd700; /* 金色 */
70
+ }
71
+ .podium-step.second {
72
+ width: 100px;
73
+ height: 120px; /* 第二名次之 */
74
+ background-color: #c0c0c0; /* 銀色 */
75
+ }
76
+ .podium-step.third {
77
+ width: 100px;
78
+ height: 90px; /* 第三名最低 */
79
+ background-color: #cd7f32; /* 銅色 */
80
+ }
81
+ .podium-label {
82
+ margin-top: 5px;
83
+ font-size: 1rem;
84
+ text-align: center;
85
+ color: #333;
86
+ }
87
  </style>
88
  """, unsafe_allow_html=True)
89
 
 
297
  )
298
  # 顯示圖表
299
  st.plotly_chart(fig, use_container_width=True)
300
+
301
+ # 新增頒獎台功能
302
+ st.subheader("頒獎台:查詢結果前三名")
303
+ # 獲取前三名(已按查詢結果降序排序)
304
+ top_3 = valid_df.head(3)
305
+
306
+ if len(top_3) > 0:
307
+ # 準備頒獎台 HTML
308
+ podium_html = '<div class="podium-container">'
309
+
310
+ # 第二名(如果有)
311
+ if len(top_3) >= 2:
312
+ second = top_3.iloc[1]
313
+ podium_html += f'''
314
+ <div class="podium">
315
+ <div class="podium-step second">{int(second['查詢結果'])}</div>
316
+ <div class="podium-label">{second['姓名']}<br>{second['幸運號碼']}</div>
317
+ </div>
318
+ '''
319
+ else:
320
+ podium_html += '<div class="podium"><div class="podium-step second"></div><div class="podium-label"></div></div>'
321
+
322
+ # 第一名(如果有)
323
+ if len(top_3) >= 1:
324
+ first = top_3.iloc[0]
325
+ podium_html += f'''
326
+ <div class="podium">
327
+ <div class="podium-step first">{int(first['查詢結果'])}</div>
328
+ <div class="podium-label">{first['姓名']}<br>{first['幸運號碼']}</div>
329
+ </div>
330
+ '''
331
+ else:
332
+ podium_html += '<div class="podium"><div class="podium-step first"></div><div class="podium-label"></div></div>'
333
+
334
+ # 第三名(如果有)
335
+ if len(top_3) >= 3:
336
+ third = top_3.iloc[2]
337
+ podium_html += f'''
338
+ <div class="podium">
339
+ <div class="podium-step third">{int(third['查詢結果'])}</div>
340
+ <div class="podium-label">{third['姓名']}<br>{third['幸運號碼']}</div>
341
+ </div>
342
+ '''
343
+ else:
344
+ podium_html += '<div class="podium"><div class="podium-step third"></div><div class="podium-label"></div></div>'
345
+
346
+ podium_html += '</div>'
347
+ st.markdown(podium_html, unsafe_allow_html=True)
348
+ else:
349
+ st.warning("無有效的查詢結果可供顯示頒獎台。")
350
  else:
351
+ st.warning("無有效的查詢結果可供繪製長條圖或頒獎台。請確認資料是否正確。")
352
 
353
  except Exception as e:
354
  st.error(f"處理檔案時發生錯誤: {str(e)}")