Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
# 定義抽籤邏輯
|
5 |
+
def draw_lottery(max_num):
|
6 |
+
# 隨機選取 1 到 max_num 之間的數字
|
7 |
+
return random.randint(1, max_num)
|
8 |
+
|
9 |
+
# 設定 Gradio 介面
|
10 |
+
with gr.Blocks() as demo:
|
11 |
+
# 輸入最大班級座號
|
12 |
+
max_num = gr.Number(label="輸入班級座號的最大值", value=30, precision=0)
|
13 |
+
# 結果顯示
|
14 |
+
result = gr.Textbox(label="抽中的號碼")
|
15 |
+
# 抽籤按鈕
|
16 |
+
btn = gr.Button("抽籤")
|
17 |
+
|
18 |
+
# 連接按鈕與抽籤邏輯
|
19 |
+
btn.click(draw_lottery, inputs=max_num, outputs=result)
|
20 |
+
|
21 |
+
# 啟動介面
|
22 |
+
demo.launch()
|