|
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) |
|
|
|
|
|
if empty_seats > 0: |
|
students.extend(['空位'] * empty_seats) |
|
|
|
|
|
random.shuffle(students) |
|
|
|
|
|
seating_arrangement = [] |
|
for i in range(4): |
|
row = students[i*8:(i+1)*8] |
|
seating_arrangement.append(row) |
|
|
|
|
|
seating_table = "\n".join(["\t".join(row) for row in seating_arrangement]) |
|
|
|
return seating_table |
|
|
|
|
|
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) |
|
|
|
|
|
demo.launch() |
|
|