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("결석자가 없습니다.")