Spaces:
Sleeping
Sleeping
| 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("κ²°μμκ° μμ΅λλ€.") | |