Download app.py from mafada33/test1: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/mafada33/test1/resolve/main/app.py
- Command line
-
hf download hf://spaces/mafada33/test1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mafada33/test1/resolve/main/app.py
1.45 kB
| import gradio as gr | |
| import random | |
| # 定義座位排法邏輯 | |
| def arrange_seating(input_data): | |
| # 將輸入的班級座號與姓名轉換為列表 | |
| students = [line.strip() for line in input_data.strip().split('\n') if line.strip()] | |
| # 檢查學生數量 | |
| total_seats = 32 | |
| empty_seats = total_seats - len(students) | |
| # 如果學生數量少於32,補充空位(使用固定長度的 "-- --" 來佔位) | |
| if empty_seats > 0: | |
| students.extend(['-- --'] * empty_seats) # 使用 "-- --" 保持格式對齊 | |
| # 隨機打亂學生列表 | |
| random.shuffle(students) | |
| # 排座位 4 直排,每排 8 個座位 | |
| seating_arrangement = [[] for _ in range(8)] # 8行 | |
| for i in range(total_seats): | |
| seating_arrangement[i % 8].append(students[i]) # 每列填充一個學生 | |
| # 將結果轉換成表格顯示 | |
| seating_table = "\n".join(["\t".join(row) for row in seating_arrangement]) | |
| return seating_table | |
| # 使用 Gradio 構建介面 | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## 座位排法系統") | |
| input_text = gr.Textbox(lines=10, label="請輸入班級座號與姓名(每行一個)", placeholder="1 張三\n2 李四\n3 王五") | |
| arrange_button = gr.Button("排座位") | |
| result = gr.Textbox(label="座位安排結果", lines=10) | |
| arrange_button.click(arrange_seating, inputs=input_text, outputs=result) | |
| # 啟動 Gradio 應用 | |
| demo.launch() | |