Download APP.PY from mohsin06/ALARM: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/spaces/mohsin06/ALARM/resolve/main/APP.PY
- Command line
-
hf download hf://spaces/mohsin06/ALARM/APP.PY
-
curl -L -o APP.PY https://huggingface.co/spaces/mohsin06/ALARM/resolve/main/APP.PY
1.53 kB
| 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() | |