Maxi924 commited on
Commit
5e87b24
·
verified ·
1 Parent(s): 1aa60d0

Create 1215002

Browse files
Files changed (1) hide show
  1. 1215002 +48 -0
1215002 ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # 初始化學生分數資料
4
+ students = {f"學生{i+1}": 0 for i in range(40)}
5
+ teachers = ["廷宇", "柔帆", "瑩茹", "蕙如", "郁民"]
6
+
7
+ # 功能函數
8
+ def update_score(teacher, student, action):
9
+ if not student:
10
+ return "請選擇學生!", students
11
+
12
+ if action == "加分":
13
+ students[student] += 10
14
+ elif action == "扣分":
15
+ students[student] -= 10
16
+ return f"{teacher}已經為{student}{action}10分!", students
17
+
18
+ # Gradio 介面
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("# 老師加扣分系統")
21
+
22
+ # 選擇老師
23
+ teacher_dropdown = gr.Dropdown(choices=teachers, label="選擇老師")
24
+
25
+ # 選擇學生
26
+ student_dropdown = gr.Dropdown(choices=list(students.keys()), label="選擇學生")
27
+
28
+ # 選擇操作(加分或扣分)
29
+ action_radio = gr.Radio(choices=["加分", "扣分"], label="選擇操作")
30
+
31
+ # 確認按鈕
32
+ confirm_button = gr.Button("確認")
33
+
34
+ # 狀態顯示
35
+ status_output = gr.Textbox(label="狀態顯示", interactive=False)
36
+
37
+ # 分數一覽表
38
+ score_table = gr.Dataframe(value=list(students.items()), headers=["學生", "分數"], label="分數一覽表", interactive=False)
39
+
40
+ # 事件處理
41
+ confirm_button.click(
42
+ update_score,
43
+ inputs=[teacher_dropdown, student_dropdown, action_radio],
44
+ outputs=[status_output, score_table]
45
+ )
46
+
47
+ # 啟動應用程式
48
+ demo.launch()