Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
def 抽籤(max_number):
|
| 5 |
+
# 確保輸入的最大號碼是有效的整數
|
| 6 |
+
try:
|
| 7 |
+
max_number = int(max_number)
|
| 8 |
+
if max_number <= 0:
|
| 9 |
+
return "請輸入一個正整數!"
|
| 10 |
+
except ValueError:
|
| 11 |
+
return "請輸入有效的整數!"
|
| 12 |
+
|
| 13 |
+
# 隨機選擇一個號碼
|
| 14 |
+
winner = random.randint(1, max_number)
|
| 15 |
+
return f"抽中的號碼是: {winner}"
|
| 16 |
+
|
| 17 |
+
# 建立 Gradio 介面
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=抽籤,
|
| 20 |
+
inputs=gr.Textbox(label="請輸入班級座號的最大號"),
|
| 21 |
+
outputs=gr.Textbox(label="抽籤結果"),
|
| 22 |
+
title="班級座號抽籤系統",
|
| 23 |
+
description="輸入班級座號的最大號,然後點擊按鈕進行抽籤!"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# 啟動介面
|
| 27 |
+
iface.launch()
|