import random | |
import gradio as gr | |
# 定義抽籤功能 | |
def draw_lottery(max_number): | |
return random.randint(1, max_number) | |
# 定義 Gradio 介面 | |
with gr.Blocks() as demo: | |
gr.Markdown("## 班級座號抽籤系統") | |
max_number_input = gr.Number(label="請輸入班級座號的最大值", value=50) | |
draw_button = gr.Button("開始抽籤") | |
result = gr.Textbox(label="抽出的號碼") | |
# 綁定按鈕事件 | |
draw_button.click(fn=draw_lottery, inputs=max_number_input, outputs=result) | |
# 啟動 Gradio 介面 | |
demo.launch() | |