Spaces:
No application file

File size: 1,526 Bytes
b62fc5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from datetime import datetime, timedelta
import time
import threading
from playsound import playsound

# Function to play the alarm sound
def play_alarm_sound():
    playsound('alarm_sound.mp3')  # You need an alarm_sound.mp3 in your project directory

# Function to check and trigger alarm
def check_alarm(alarm_time):
    while True:
        current_time = datetime.now().strftime('%H:%M:%S')
        if current_time == alarm_time:
            st.session_state['alarm_triggered'] = True
            play_alarm_sound()
            break
        time.sleep(1)

# Streamlit app
def main():
    st.title("Alarm Clock App")

    if 'alarm_triggered' not in st.session_state:
        st.session_state['alarm_triggered'] = False

    st.write("Set an alarm by choosing the time below.")

    # User input for alarm time
    alarm_hour = st.number_input("Hour (24-hour format)", min_value=0, max_value=23, step=1)
    alarm_minute = st.number_input("Minute", min_value=0, max_value=59, step=1)
    alarm_second = st.number_input("Second", min_value=0, max_value=59, step=1)

    # Convert alarm time to string format
    alarm_time = f"{int(alarm_hour):02}:{int(alarm_minute):02}:{int(alarm_second):02}"

    if st.button("Set Alarm"):
        st.success(f"Alarm set for {alarm_time}.")
        threading.Thread(target=check_alarm, args=(alarm_time,), daemon=True).start()

    if st.session_state['alarm_triggered']:
        st.warning("Alarm is ringing! Time's up!")

if __name__ == "__main__":
    main()