File size: 2,163 Bytes
a668d50
ae7f82d
 
 
 
 
2e64708
902f4db
61b6129
0eb03f0
244c61e
 
77822de
902f4db
61b6129
 
4dd7935
3455e4c
 
61b6129
ae7f82d
 
 
 
 
 
3455e4c
 
 
55445e1
 
3455e4c
 
ae7f82d
 
 
 
 
 
 
7ff01ac
77822de
 
 
 
 
3455e4c
 
 
 
77822de
 
3455e4c
 
 
 
 
 
ae7f82d
 
 
141f481
329ae81
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
from gtts import gTTS
from pydub import AudioSegment
from pydub.playback import play
import tempfile
import os

# 학생 리슀트
student_list = ["홍길동", "κΉ€μ² μˆ˜", "이영희", "λ°•μ˜μˆ˜"]

# κ²°μ„μž 리슀트 μ΄ˆκΈ°ν™”
absentees = []
attendance_status = {student: "미확인" for student in student_list}

# Streamlit UI
st.title("μΆœμ„ 확인 μ‹œμŠ€ν…œ")

if 'current_index' not in st.session_state:
    st.session_state.current_index = 0

# μ˜€λ””μ˜€ 파일 생성 ν•¨μˆ˜
def create_audio_for_student(student):
    tts = gTTS(text=f"{student} 학생", lang='ko')
    temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')
    tts.save(temp_file.name)
    return temp_file.name

# 학생 이름 뢈러였기
if st.button("λ‹€μŒ 학생"):
    current_student = student_list[st.session_state.current_index]
    
    # 화면에 ν˜„μž¬ 학생 이름 ν‘œμ‹œ
    st.subheader(f"ν˜„μž¬ 학생: {current_student}")
    
    # 학생 이름을 TTS둜 읽기 (gTTS μ‚¬μš©)
    audio_file = create_audio_for_student(current_student)
    
    # μ˜€λ””μ˜€ νŒŒμΌμ„ μž¬μƒ
    audio_segment = AudioSegment.from_mp3(audio_file)
    play(audio_segment)
    
    # μΆœμ„ μ—¬λΆ€ 선택
    attendance = st.radio(f"{current_student} μΆœμ„ μ—¬λΆ€", ("μΆœμ„", "결석"))
    attendance_status[current_student] = attendance

    if attendance == "결석":
        absentees.append(current_student)
        with open("absentees.txt", "a") as f:
            f.write(f"{current_student}\n")
        st.success(f"{current_student}κ°€ κ²°μ„μžλ‘œ λ“±λ‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
    elif attendance == "μΆœμ„":
        st.success(f"{current_student}κ°€ μΆœμ„μœΌλ‘œ λ“±λ‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
    
    # λ‹€μŒ ν•™μƒμœΌλ‘œ 인덱슀 이동
    if st.session_state.current_index < len(student_list) - 1:
        st.session_state.current_index += 1
    else:
        st.write("λͺ¨λ“  ν•™μƒμ˜ 이름을 λΆˆλ €μŠ΅λ‹ˆλ‹€.")
    
    # μž„μ‹œ 파일 μ‚­μ œ
    os.remove(audio_file)

# κ²°μ„μž 리슀트 보여주기
st.subheader("κ²°μ„μž 리슀트")
if absentees:
    st.write(absentees)
else:
    st.write("κ²°μ„μžκ°€ μ—†μŠ΅λ‹ˆλ‹€.")