momo / app.py
cindyli51's picture
Update app.py
c095543 verified
raw
history blame contribute delete
580 Bytes
import gradio as gr
import random
# 定義抽籤邏輯
def draw_lottery(max_num):
# 隨機選取 1 到 max_num 之間的數字
return random.randint(1, max_num)
# 設定 Gradio 介面
with gr.Blocks() as demo:
# 輸入最大班級座號
max_num = gr.Number(label="輸入班級座號的最大值", value=30, precision=0)
# 結果顯示
result = gr.Textbox(label="抽中的號碼")
# 抽籤按鈕
btn = gr.Button("抽籤")
# 連接按鈕與抽籤邏輯
btn.click(draw_lottery, inputs=max_num, outputs=result)
# 啟動介面
demo.launch()