Lashtw commited on
Commit
5ffd753
·
verified ·
1 Parent(s): 3ca060c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -148
app.py CHANGED
@@ -90,92 +90,49 @@ st.markdown("""
90
  background-color: rgba(0, 0, 0, 0.5); /* 半透明背景,提升可讀性 */
91
  white-space: pre-line; /* 允許換行 */
92
  }
93
- /* 全螢幕頒獎台樣式 */
94
- .podium-fullscreen-container {
95
- width: 100%;
96
- height: 100vh;
97
- background-color: #1a1a1a; /* 背景與主頁一致 */
98
- display: flex;
99
- justify-content: center;
100
- align-items: flex-end;
101
- padding: 20px;
102
- box-sizing: border-box;
103
- }
104
- .podium-fullscreen-container .podium {
105
- width: 30%; /* 按比例放大 */
106
- margin: 0 2%;
107
- }
108
- .podium-fullscreen-container .podium-step.first {
109
- height: 40vh; /* 按比例放大高度 */
110
- }
111
- .podium-fullscreen-container .podium-step.second {
112
- height: 32vh; /* 按比例放大高度 */
113
- }
114
- .podium-fullscreen-container .podium-step.third {
115
- height: 24vh; /* 按比例放大高度 */
116
- }
117
- .podium-fullscreen-container .podium-filler {
118
- flex-grow: 0; /* 確保填充塊不自動填充 */
119
- background-color: rgba(255, 255, 255, 0.1); /* 半透明白色,方便調試 */
120
- border: 1px dashed #666; /* 添加邊框,確認填充塊是否渲染 */
121
- }
122
- .podium-fullscreen-container .podium-filler.second {
123
- height: 8vh; /* 填充高度按比例調整 (40vh - 32vh) */
124
- }
125
- .podium-fullscreen-container .podium-filler.third {
126
- height: 16vh; /* 填充高度按比例調整 (40vh - 24vh) */
127
- }
128
- .podium-fullscreen-container .podium-step {
129
- font-size: 2rem; /* 放大數字字體 */
130
- }
131
- .podium-fullscreen-container .podium-label {
132
- font-size: 1.5rem; /* 放大標籤字體 */
133
- padding: 10px;
134
- }
135
  </style>
136
  """, unsafe_allow_html=True)
137
 
138
  # 圓周率與無限猴子定理的介紹與分頁圖片展示
139
- if not st.session_state.get("show_fullscreen", False):
140
- st.title("探索圓周率與無限猴子定理的奇妙世界")
141
- st.write("""
142
- 歡迎參加這個有趣的活動!我們將一起探索圓周率 (π) 和無限猴子定理的奧秘,並透過幸運數字查詢系統,發現你選的數字在 π 中的秘密。
143
- """)
144
 
145
- # 定義圖片和標題
146
- image_data = [
147
- {"path": "m1.GIF", "caption": "圓周率與無限猴子定理的奇妙關聯"},
148
- {"path": "m2.GIF", "caption": "重複與不重複"},
149
- {"path": "m3.GIF", "caption": "圓周率裡藏著你的幸運號碼"},
150
- {"path": "m4.GIF", "caption": "無限猴子定理是什麼?"},
151
- {"path": "m5.GIF", "caption": "圓周率是無限長的數字打字機"},
152
- ]
153
 
154
- # 初始化 session state 用於追蹤當前頁面和全螢幕狀態
155
- if 'page' not in st.session_state:
156
- st.session_state.page = 0
157
 
158
- # 顯示當前頁面的圖片,放大至幾乎全版面
159
- st.image(image_data[st.session_state.page]["path"],
160
- caption=image_data[st.session_state.page]["caption"],
161
- use_container_width=True)
162
 
163
- # 換頁按鈕
164
- col1, col2 = st.columns(2)
165
- with col1:
166
- if st.button("上一頁", disabled=st.session_state.page <= 0):
167
- st.session_state.page -= 1
168
- st.rerun()
169
- with col2:
170
- if st.button("下一頁", disabled=st.session_state.page >= len(image_data) - 1):
171
- st.session_state.page += 1
172
- st.rerun()
173
 
174
- # 顯示當前頁數
175
- st.write(f"頁面: {st.session_state.page + 1} / {len(image_data)}")
176
 
177
- # 分隔線
178
- st.markdown("---")
179
 
180
  # 查詢數字的函數
181
  def process_number(number):
@@ -209,69 +166,6 @@ def generate_qr_code(url):
209
  return img
210
 
211
  def main():
212
- # 全螢幕模式:僅顯示頒獎台
213
- if st.session_state.get("show_fullscreen", False):
214
- if 'top_3' in st.session_state:
215
- top_3 = st.session_state.top_3
216
- with st.container():
217
- st.markdown('<div class="podium-fullscreen-container">', unsafe_allow_html=True)
218
- col_fs1, col_fs2, col_fs3 = st.columns(3)
219
-
220
- with col_fs1:
221
- if len(top_3) >= 2:
222
- second = top_3.iloc[1]
223
- st.markdown(
224
- f'<div class="podium">'
225
- f'<div class="podium-filler second"></div>'
226
- f'<div class="podium-step second">{int(second["查詢結果"])}</div>'
227
- f'<div class="podium-label">{second["姓名"]}\n{second["幸運號碼"]}</div>'
228
- f'</div>',
229
- unsafe_allow_html=True
230
- )
231
- else:
232
- st.markdown('<div class="podium"><div class="podium-filler second"></div><div class="podium-step second"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
233
-
234
- with col_fs2:
235
- if len(top_3) >= 1:
236
- first = top_3.iloc[0]
237
- st.markdown(
238
- f'<div class="podium">'
239
- f'<div class="podium-step first">{int(first["查詢結果"])}</div>'
240
- f'<div class="podium-label">{first["姓名"]}\n{first["幸運號碼"]}</div>'
241
- f'</div>',
242
- unsafe_allow_html=True
243
- )
244
- else:
245
- st.markdown('<div class="podium"><div class="podium-step first"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
246
-
247
- with col_fs3:
248
- if len(top_3) >= 3:
249
- third = top_3.iloc[2]
250
- st.markdown(
251
- f'<div class="podium">'
252
- f'<div class="podium-filler third"></div>'
253
- f'<div class="podium-step third">{int(third["查詢結果"])}</div>'
254
- f'<div class="podium-label">{third["姓名"]}\n{third["幸運號碼"]}</div>'
255
- f'</div>',
256
- unsafe_allow_html=True
257
- )
258
- else:
259
- st.markdown('<div class="podium"><div class="podium-filler third"></div><div class="podium-step third"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
260
-
261
- st.markdown('</div>', unsafe_allow_html=True)
262
-
263
- # 關閉按鈕
264
- if st.button("關閉全螢幕"):
265
- st.session_state.show_fullscreen = False
266
- st.rerun()
267
- else:
268
- st.warning("請先生成頒獎台,然後再進入全螢幕模式。")
269
- if st.button("返回"):
270
- st.session_state.show_fullscreen = False
271
- st.rerun()
272
- return
273
-
274
- # 正常模式:顯示完整頁面
275
  st.title("幸運數字查詢系統")
276
 
277
  # 新增功能:輸入表單連結並生成 QR Code
@@ -428,7 +322,6 @@ def main():
428
  st.subheader("頒獎台:查詢結果前三名")
429
  # 獲取前三名(已按查詢結果降序排序)
430
  top_3 = valid_df.head(3)
431
- st.session_state.top_3 = top_3 # 儲存前三名數據以供全螢幕模式使用
432
 
433
  if len(top_3) > 0:
434
  # 正常顯示頒獎台
@@ -475,11 +368,6 @@ def main():
475
  else:
476
  st.markdown('<div class="podium"><div class="podium-filler" style="height: 60px;"></div><div class="podium-step third"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
477
 
478
- # 全螢幕顯示按鈕
479
- if st.button("全螢幕顯示頒獎台"):
480
- st.session_state.show_fullscreen = True
481
- st.rerun()
482
-
483
  else:
484
  st.warning("無有效的查詢結果可供顯示頒獎台。")
485
  else:
@@ -488,9 +376,8 @@ def main():
488
  except Exception as e:
489
  st.error(f"處理檔案時發生錯誤: {str(e)}")
490
 
491
- # 添加右下角資訊(僅在正常模式下顯示)
492
- if not st.session_state.get("show_fullscreen", False):
493
- st.markdown('<div class="footer">程式設計:新竹縣立精華國中 藍星宇老師</div>', unsafe_allow_html=True)
494
 
495
  if __name__ == "__main__":
496
  main()
 
90
  background-color: rgba(0, 0, 0, 0.5); /* 半透明背景,提升可讀性 */
91
  white-space: pre-line; /* 允許換行 */
92
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  </style>
94
  """, unsafe_allow_html=True)
95
 
96
  # 圓周率與無限猴子定理的介紹與分頁圖片展示
97
+ st.title("探索圓周率與無限猴子定理的奇妙世界")
98
+ st.write("""
99
+ 歡迎參加這個有趣的活動!我們將一起探索圓周率 (π) 和無限猴子定理的奧秘,並透過幸運數字查詢系統,發現你選的數字在 π 中的秘密。
100
+ """)
 
101
 
102
+ # 定義圖片和標題
103
+ image_data = [
104
+ {"path": "m1.GIF", "caption": "圓周率與無限猴子定理的奇妙關聯"},
105
+ {"path": "m2.GIF", "caption": "重複與不重複"},
106
+ {"path": "m3.GIF", "caption": "圓周率裡藏著你的幸運號碼"},
107
+ {"path": "m4.GIF", "caption": "無限猴子定理是什麼?"},
108
+ {"path": "m5.GIF", "caption": "圓周率是無限長的數字打字機"},
109
+ ]
110
 
111
+ # 初始化 session state 用於追蹤當前頁面
112
+ if 'page' not in st.session_state:
113
+ st.session_state.page = 0
114
 
115
+ # 顯示當前頁面的圖片,放大至幾乎全版面
116
+ st.image(image_data[st.session_state.page]["path"],
117
+ caption=image_data[st.session_state.page]["caption"],
118
+ use_container_width=True)
119
 
120
+ # 換頁按鈕
121
+ col1, col2 = st.columns(2)
122
+ with col1:
123
+ if st.button("上一頁", disabled=st.session_state.page <= 0):
124
+ st.session_state.page -= 1
125
+ st.rerun()
126
+ with col2:
127
+ if st.button("下一頁", disabled=st.session_state.page >= len(image_data) - 1):
128
+ st.session_state.page += 1
129
+ st.rerun()
130
 
131
+ # 顯示當前頁數
132
+ st.write(f"頁面: {st.session_state.page + 1} / {len(image_data)}")
133
 
134
+ # 分隔線
135
+ st.markdown("---")
136
 
137
  # 查詢數字的函數
138
  def process_number(number):
 
166
  return img
167
 
168
  def main():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  st.title("幸運數字查詢系統")
170
 
171
  # 新增功能:輸入表單連結並生成 QR Code
 
322
  st.subheader("頒獎台:查詢結果前三名")
323
  # 獲取前三名(已按查詢結果降序排序)
324
  top_3 = valid_df.head(3)
 
325
 
326
  if len(top_3) > 0:
327
  # 正常顯示頒獎台
 
368
  else:
369
  st.markdown('<div class="podium"><div class="podium-filler" style="height: 60px;"></div><div class="podium-step third"></div><div class="podium-label"></div></div>', unsafe_allow_html=True)
370
 
 
 
 
 
 
371
  else:
372
  st.warning("無有效的查詢結果可供顯示頒獎台。")
373
  else:
 
376
  except Exception as e:
377
  st.error(f"處理檔案時發生錯誤: {str(e)}")
378
 
379
+ # 添加右下角資訊
380
+ st.markdown('<div class="footer">程式設計:新竹縣立精華國中 藍星宇老師</div>', unsafe_allow_html=True)
 
381
 
382
  if __name__ == "__main__":
383
  main()