import gradio as gr | |
import random | |
# 抽籤函數 | |
def draw_lot(max_number): | |
return random.randint(1, max_number) | |
# 建立 Gradio 介面 | |
with gr.Blocks() as demo: | |
gr.Markdown("### 座號抽籤系統") | |
# 輸入框: 座號最大值 | |
max_number_input = gr.Number(label="輸入班級座號的最大值", value=50) | |
# 顯示抽籤結果 | |
result = gr.Textbox(label="抽籤結果", interactive=False) | |
# 按鈕: 點擊抽籤 | |
button = gr.Button("開始抽籤") | |
# 點擊按鈕後呼叫 draw_lot 函數,並更新結果 | |
button.click(fn=draw_lot, inputs=[max_number_input], outputs=[result]) | |
# 啟動 Gradio 介面 | |
demo.launch() | |