File size: 731 Bytes
7951e48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
import random

# 定義抽籤的邏輯
def draw_lottery(max_number):
    if max_number.isdigit():
        max_number = int(max_number)
        if max_number > 0:
            return random.randint(1, max_number)
        else:
            return "請輸入大於 0 的數字"
    else:
        return "請輸入有效的數字"

# 使用 Gradio 構建介面
with gr.Blocks() as demo:
    gr.Markdown("## 抽籤系統")
    
    with gr.Row():
        max_number = gr.Textbox(label="班級座號最大值")
        
    draw_button = gr.Button("抽籤")
    result = gr.Textbox(label="抽籤結果")
    
    draw_button.click(draw_lottery, inputs=max_number, outputs=result)

# 啟動 Gradio 應用
demo.launch()