hchsuk's picture
Update app.py
e5e1c1e verified
Raw History Blame Contribute Delete
911 Bytes
import gradio as gr
import random
def draw_lottery(max_number):
"""Randomly select a number between 1 and the provided max_number."""
if not max_number or max_number <= 0:
return "請輸入有效的班級座號最大值!"
return f"抽中的號碼是: {random.randint(1, max_number)}"
# Define the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("## 抽籤系統")
gr.Markdown("請輸入班級座號的最大值,然後按下抽籤按鈕。")
# Input for maximum seat number
max_number = gr.Number(label="班級座號最大值", value=30, precision=0)
# Button to trigger the draw
draw_button = gr.Button("抽籤")
# Output area to display the result
result = gr.Textbox(label="抽籤結果")
# Link the button click to the function
draw_button.click(draw_lottery, inputs=[max_number], outputs=[result])
# Launch the app
demo.launch()