Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,61 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from datetime import datetime, timedelta
|
| 3 |
+
import pytz
|
| 4 |
import time
|
| 5 |
|
| 6 |
+
# Function to convert seconds to minutes:seconds format
|
| 7 |
+
def format_time(seconds):
|
| 8 |
+
return f"{seconds // 60:02d}:{seconds % 60:02d}"
|
| 9 |
+
|
| 10 |
+
# Custom CSS for big timer digits
|
| 11 |
+
st.markdown("""
|
| 12 |
+
<style>
|
| 13 |
+
.big-font {
|
| 14 |
+
font-size: 60px !important;
|
| 15 |
+
font-weight: bold;
|
| 16 |
+
}
|
| 17 |
+
</style>
|
| 18 |
+
""", unsafe_allow_html=True)
|
| 19 |
+
|
| 20 |
+
# Check if countdown and timer_active keys exist in the session state
|
| 21 |
+
if 'countdown' not in st.session_state:
|
| 22 |
+
st.session_state.countdown = 0
|
| 23 |
+
if 'timer_active' not in st.session_state:
|
| 24 |
+
st.session_state.timer_active = False
|
| 25 |
|
| 26 |
+
# Start the timer
|
| 27 |
+
def start_timer():
|
| 28 |
+
st.session_state.timer_active = True
|
| 29 |
+
st.session_state.countdown_end_time = time.time() + st.session_state.countdown
|
| 30 |
|
| 31 |
+
# Timer input form
|
| 32 |
+
with st.form("Timer"):
|
| 33 |
+
input_seconds = st.number_input("Set timer (in seconds):", min_value=10, max_value=3600, value=180, step=10)
|
| 34 |
+
submitted = st.form_submit_button("Start Timer")
|
| 35 |
+
if submitted:
|
| 36 |
+
st.session_state.countdown = input_seconds
|
| 37 |
+
start_timer()
|
| 38 |
+
|
| 39 |
+
# Update and display the timer
|
| 40 |
+
if st.session_state.timer_active:
|
| 41 |
+
elapsed_time = int(time.time() - (st.session_state.countdown_end_time - st.session_state.countdown))
|
| 42 |
+
if elapsed_time < st.session_state.countdown:
|
| 43 |
+
st.markdown(f'<div class="big-font">{format_time(st.session_state.countdown - elapsed_time)}</div>', unsafe_allow_html=True)
|
| 44 |
+
time.sleep(1)
|
| 45 |
+
st.experimental_rerun()
|
| 46 |
+
else:
|
| 47 |
+
st.session_state.timer_active = False
|
| 48 |
+
st.markdown('<div class="big-font">00:00</div>', unsafe_allow_html=True)
|
| 49 |
+
st.balloons()
|
| 50 |
+
# Suggestion: Use Streamlit's st.audio to play a sound notification here
|
| 51 |
|
| 52 |
+
# World Clock
|
| 53 |
+
st.header("World Clock")
|
| 54 |
+
selected_timezone = st.selectbox("Select Timezone", pytz.all_timezones, index=pytz.all_timezones.index('UTC'))
|
| 55 |
+
current_time = datetime.now(pytz.timezone(selected_timezone))
|
| 56 |
+
st.write(f"Current time in {selected_timezone}: {current_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 57 |
|
| 58 |
+
# Audio notification (example suggestion)
|
| 59 |
+
# Due to Streamlit's architecture, directly playing sound on the server won't be heard by the user.
|
| 60 |
+
# Instead, you could provide a button to play a sound or link to a sound file.
|
| 61 |
+
# st.audio('path_to_your_audio_file.mp3')
|