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