jonghhhh commited on
Commit
0eb03f0
Β·
verified Β·
1 Parent(s): f57f092

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -22
app.py CHANGED
@@ -3,35 +3,43 @@ from gtts import gTTS
3
  from io import BytesIO
4
  import pandas as pd
5
 
6
- # μ£Όμ–΄μ§„ 학생 λͺ…단
7
- students = [
8
- "Hui Chin Nam", "Li Jiaying", "Mo Siyu", "Xu Tian", "Ye Wenting", "Zhou Qinyi",
9
- "κ°•μˆ˜λ―Ό", "κΉ€λ‚¨ν›ˆ", "κΉ€μ„œμ—°", "κΉ€μ„±μ£Ό", "κΉ€μ •ν•˜", "κΉ€νš¨μ€€", "λ‚¨μˆ˜λ―Ό", "λ‚¨μ˜ˆλ„", "민병기",
10
- "λ°•λ‚˜μ›", "λ°•μˆ˜ν˜„", "박지은", "박채연", "박채원", "λ°±μŠΉμ›", "μ„œμ •ν˜„", "μ†‘μˆ˜ν˜„", "μ†‘μ€μ˜",
11
- "μ•ˆνš¨μ •", "μ—„μ€μˆ˜", "이수민", "μ΄μœ€λ²”", "μ΄μ€μ˜", "이정민", "이정민", "μž₯ν•œλ‚˜", "μ „μœ€μ„œ",
12
- "μ •μœ€μ„œ", "μ •μ§„μš±", "μ£Όμ„ μ œ", "ν•œκ·Όνš¨", "ν•œμ€μ°¬", "ν™©λ―Όμ£Ό"
13
- ]
 
 
 
 
 
 
 
 
 
 
14
 
15
  # μΆœμ„ 기둝 μ΄ˆκΈ°ν™”
16
- if 'attendance' not in st.session_state:
17
  st.session_state.attendance = {student: None for student in students}
18
-
19
- # ν˜„μž¬ μΆœμ„ 체크 쀑인 학생 인덱슀 μ΄ˆκΈ°ν™”
20
- if 'current_index' not in st.session_state:
21
  st.session_state.current_index = 0
 
22
 
23
- # ν˜„μž¬ ν•™μƒμ˜ 이름 뢈러였기
24
  current_student = students[st.session_state.current_index]
25
 
26
- st.title("μžλ™ μΆœμ„ 체크 μ‹œμŠ€ν…œ")
27
 
28
  # 이름을 μŒμ„±μœΌλ‘œ 좜λ ₯ν•˜λŠ” ν•¨μˆ˜
29
- def play_name(student_name):
30
  tts = gTTS(text=student_name, lang='ko')
31
  fp = BytesIO()
32
  tts.write_to_fp(fp)
33
  fp.seek(0)
34
- st.audio(fp, format='audio/mp3')
35
 
36
  # 4μ—΄λ‘œ 학생 λͺ…단을 ν‘œμ‹œ
37
  st.write("학생 λͺ…단:")
@@ -43,9 +51,6 @@ for i, student in enumerate(students):
43
  else:
44
  col.write(f" {student}")
45
 
46
- # ν˜„μž¬ 학생 이름을 μŒμ„±μœΌλ‘œ 뢀름
47
- play_name(current_student)
48
-
49
  # μΆœμ„κ³Ό 결석 λ²„νŠΌ
50
  col1, col2 = st.columns(2)
51
  with col1:
@@ -53,18 +58,22 @@ with col1:
53
  st.session_state.attendance[current_student] = "μΆœμ„"
54
  if st.session_state.current_index < len(students) - 1:
55
  st.session_state.current_index += 1
 
 
 
56
  else:
57
  st.session_state.current_index = None # λͺ¨λ“  학생 μ™„λ£Œ
58
- st.session_state.query_params = {'index': st.session_state.current_index}
59
 
60
  with col2:
61
  if st.button("결석"):
62
  st.session_state.attendance[current_student] = "결석"
63
  if st.session_state.current_index < len(students) - 1:
64
  st.session_state.current_index += 1
 
 
 
65
  else:
66
  st.session_state.current_index = None # λͺ¨λ“  학생 μ™„λ£Œ
67
- st.session_state.query_params = {'index': st.session_state.current_index}
68
 
69
  # λͺ¨λ“  ν•™μƒμ˜ μΆœμ„ 체크가 μ™„λ£Œλœ ν›„ 결석 학생듀을 ν‘œμ‹œ
70
  if st.session_state.current_index is None:
@@ -82,8 +91,12 @@ if st.session_state.current_index is None:
82
  st.download_button(
83
  label="결석 학생 λͺ©λ‘ λ‹€μš΄λ‘œλ“œ",
84
  data=csv,
85
- file_name='결석_학생_λͺ©λ‘.csv',
86
  mime='text/csv',
87
  )
88
  else:
89
  st.write("κ²°μ„ν•œ 학생이 μ—†μŠ΅λ‹ˆλ‹€.")
 
 
 
 
 
3
  from io import BytesIO
4
  import pandas as pd
5
 
6
+ # 학생 λͺ…단을 두 개의 μˆ˜μ—…μœΌλ‘œ λ‚˜λˆ”
7
+ students_dict = {
8
+ "맀체철학": [
9
+ "Hui Chin Nam", "Li Jiaying", "Mo Siyu", "Xu Tian", "Ye Wenting", "Zhou Qinyi",
10
+ "κ°•μˆ˜λ―Ό", "κΉ€λ‚¨ν›ˆ", "κΉ€μ„œμ—°", "κΉ€μ„±μ£Ό", "κΉ€μ •ν•˜", "κΉ€νš¨μ€€", "λ‚¨μˆ˜λ―Ό", "λ‚¨μ˜ˆλ„", "민병기"
11
+ ],
12
+ "κ²½μ œμ €λ„λ¦¬μ¦˜": [
13
+ "λ°•λ‚˜μ›", "λ°•μˆ˜ν˜„", "박지은", "박채연", "박채원", "λ°±μŠΉμ›", "μ„œμ •ν˜„", "μ†‘μˆ˜ν˜„", "μ†‘μ€μ˜",
14
+ "μ•ˆνš¨μ •", "μ—„μ€μˆ˜", "이수민", "μ΄μœ€λ²”", "μ΄μ€μ˜", "이정민", "이정민", "μž₯ν•œλ‚˜", "μ „μœ€μ„œ",
15
+ "μ •μœ€μ„œ", "μ •μ§„μš±", "μ£Όμ„ μ œ", "ν•œκ·Όνš¨", "ν•œμ€μ°¬", "ν™©λ―Όμ£Ό"
16
+ ]
17
+ }
18
+
19
+ # μ‚¬μ΄λ“œλ°”μ—μ„œ μˆ˜μ—… 선택
20
+ selected_class = st.sidebar.selectbox("μˆ˜μ—… 선택", list(students_dict.keys()))
21
+
22
+ # μ„ νƒλœ μˆ˜μ—…μ˜ 학생 λͺ…단을 κ°€μ Έμ˜΄
23
+ students = students_dict[selected_class]
24
 
25
  # μΆœμ„ 기둝 μ΄ˆκΈ°ν™”
26
+ if 'attendance' not in st.session_state or 'current_class' not in st.session_state or st.session_state.current_class != selected_class:
27
  st.session_state.attendance = {student: None for student in students}
 
 
 
28
  st.session_state.current_index = 0
29
+ st.session_state.current_class = selected_class
30
 
31
+ # ν˜„μž¬ μΆœμ„ 체크 쀑인 학생 인덱슀 μ΄ˆκΈ°ν™”
32
  current_student = students[st.session_state.current_index]
33
 
34
+ st.title(f"{selected_class} μΆœμ„ 체크 μ‹œμŠ€ν…œ")
35
 
36
  # 이름을 μŒμ„±μœΌλ‘œ 좜λ ₯ν•˜λŠ” ν•¨μˆ˜
37
+ def generate_audio(student_name):
38
  tts = gTTS(text=student_name, lang='ko')
39
  fp = BytesIO()
40
  tts.write_to_fp(fp)
41
  fp.seek(0)
42
+ return fp
43
 
44
  # 4μ—΄λ‘œ 학생 λͺ…단을 ν‘œμ‹œ
45
  st.write("학생 λͺ…단:")
 
51
  else:
52
  col.write(f" {student}")
53
 
 
 
 
54
  # μΆœμ„κ³Ό 결석 λ²„νŠΌ
55
  col1, col2 = st.columns(2)
56
  with col1:
 
58
  st.session_state.attendance[current_student] = "μΆœμ„"
59
  if st.session_state.current_index < len(students) - 1:
60
  st.session_state.current_index += 1
61
+ next_student = students[st.session_state.current_index]
62
+ audio_file = generate_audio(next_student)
63
+ st.audio(audio_file, format='audio/mp3') # λ‹€μŒ 학생 이름을 μžλ™μœΌλ‘œ μž¬μƒ
64
  else:
65
  st.session_state.current_index = None # λͺ¨λ“  학생 μ™„λ£Œ
 
66
 
67
  with col2:
68
  if st.button("결석"):
69
  st.session_state.attendance[current_student] = "결석"
70
  if st.session_state.current_index < len(students) - 1:
71
  st.session_state.current_index += 1
72
+ next_student = students[st.session_state.current_index]
73
+ audio_file = generate_audio(next_student)
74
+ st.audio(audio_file, format='audio/mp3') # λ‹€μŒ 학생 이름을 μžλ™μœΌλ‘œ μž¬μƒ
75
  else:
76
  st.session_state.current_index = None # λͺ¨λ“  학생 μ™„λ£Œ
 
77
 
78
  # λͺ¨λ“  ν•™μƒμ˜ μΆœμ„ 체크가 μ™„λ£Œλœ ν›„ 결석 학생듀을 ν‘œμ‹œ
79
  if st.session_state.current_index is None:
 
91
  st.download_button(
92
  label="결석 학생 λͺ©λ‘ λ‹€μš΄λ‘œλ“œ",
93
  data=csv,
94
+ file_name=f'{selected_class}_결석_학생_λͺ©λ‘.csv',
95
  mime='text/csv',
96
  )
97
  else:
98
  st.write("κ²°μ„ν•œ 학생이 μ—†μŠ΅λ‹ˆλ‹€.")
99
+ else:
100
+ # ν˜„μž¬ 학생 이름을 μŒμ„±μœΌλ‘œ 뢀름 (νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ)
101
+ audio_file = generate_audio(current_student)
102
+ st.audio(audio_file, format='audio/mp3')