240805Test / app.py
geneh's picture
First commit
70e59aa verified
raw
history blame contribute delete
578 Bytes
import gradio as gr
import random
# 定義抽籤函數
def draw_lottery(max_number):
if max_number <= 0:
return "請輸入一個正整數"
return random.randint(1, max_number)
# 創建 Gradio 介面
with gr.Blocks() as demo:
with gr.Row():
max_number_input = gr.Number(label="班級座號的最大值", value=40, precision=0)
result_output = gr.Textbox(label="抽中的號碼")
draw_button = gr.Button("抽籤")
draw_button.click(draw_lottery, inputs=max_number_input, outputs=result_output)
# 啟動介面
demo.launch()