Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
|
4 |
-
# 定義抽籤選項
|
5 |
-
choices = ["大吉", "中吉", "小吉", "吉", "凶"]
|
6 |
-
|
7 |
# 抽籤函數
|
8 |
-
def draw_lot():
|
9 |
-
return random.
|
10 |
|
11 |
# 建立 Gradio 介面
|
12 |
with gr.Blocks() as demo:
|
13 |
-
gr.Markdown("###
|
|
|
|
|
|
|
|
|
|
|
14 |
result = gr.Textbox(label="抽籤結果", interactive=False)
|
15 |
-
button = gr.Button("抽籤")
|
16 |
|
17 |
-
#
|
18 |
-
button
|
|
|
|
|
|
|
19 |
|
20 |
# 啟動 Gradio 介面
|
21 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
|
|
|
|
|
|
|
4 |
# 抽籤函數
|
5 |
+
def draw_lot(max_number):
|
6 |
+
return random.randint(1, max_number)
|
7 |
|
8 |
# 建立 Gradio 介面
|
9 |
with gr.Blocks() as demo:
|
10 |
+
gr.Markdown("### 座號抽籤系統")
|
11 |
+
|
12 |
+
# 輸入框: 座號最大值
|
13 |
+
max_number_input = gr.Number(label="輸入班級座號的最大值", value=50)
|
14 |
+
|
15 |
+
# 顯示抽籤結果
|
16 |
result = gr.Textbox(label="抽籤結果", interactive=False)
|
|
|
17 |
|
18 |
+
# 按鈕: 點擊抽籤
|
19 |
+
button = gr.Button("開始抽籤")
|
20 |
+
|
21 |
+
# 點擊按鈕後呼叫 draw_lot 函數,並更新結果
|
22 |
+
button.click(fn=draw_lot, inputs=[max_number_input], outputs=[result])
|
23 |
|
24 |
# 啟動 Gradio 介面
|
25 |
demo.launch()
|