Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -124,13 +124,19 @@ def main():
|
|
124 |
|
125 |
st.title("Quote Timer")
|
126 |
|
127 |
-
# Select a random quote to start
|
128 |
-
index = random.randint(0, len(quotes)-1)
|
129 |
-
display_quote(index)
|
130 |
-
|
131 |
# AutoRepeat radio button
|
132 |
st.session_state.auto_repeat = st.radio("π AutoRepeat", ["On", "Off"])
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
timer_html = """
|
135 |
<div id="timer">Time left: 5 seconds</div>
|
136 |
<script>
|
@@ -138,12 +144,11 @@ def main():
|
|
138 |
const timerElement = document.getElementById('timer');
|
139 |
|
140 |
function updateTimer() {
|
141 |
-
if (countdown >
|
142 |
timerElement.innerHTML = `Time left: ${countdown} seconds`;
|
143 |
countdown -= 1;
|
144 |
} else {
|
145 |
-
|
146 |
-
location.reload();
|
147 |
}
|
148 |
}
|
149 |
|
@@ -156,5 +161,8 @@ def main():
|
|
156 |
|
157 |
st.components.v1.html(timer_html, height=50)
|
158 |
|
|
|
|
|
|
|
159 |
if __name__ == "__main__":
|
160 |
main()
|
|
|
124 |
|
125 |
st.title("Quote Timer")
|
126 |
|
|
|
|
|
|
|
|
|
127 |
# AutoRepeat radio button
|
128 |
st.session_state.auto_repeat = st.radio("π AutoRepeat", ["On", "Off"])
|
129 |
|
130 |
+
# Check if we should change the quote (using a hidden button)
|
131 |
+
if st.button("change_quote", key="hidden_button", on_click=_change_quote):
|
132 |
+
pass
|
133 |
+
|
134 |
+
# Display a random quote
|
135 |
+
if "current_index" not in st.session_state:
|
136 |
+
st.session_state.current_index = random.randint(0, len(quotes)-1)
|
137 |
+
|
138 |
+
display_quote(st.session_state.current_index)
|
139 |
+
|
140 |
timer_html = """
|
141 |
<div id="timer">Time left: 5 seconds</div>
|
142 |
<script>
|
|
|
144 |
const timerElement = document.getElementById('timer');
|
145 |
|
146 |
function updateTimer() {
|
147 |
+
if (countdown > 2) { // Change here
|
148 |
timerElement.innerHTML = `Time left: ${countdown} seconds`;
|
149 |
countdown -= 1;
|
150 |
} else {
|
151 |
+
document.querySelector("[data-testid='hidden_button']").click();
|
|
|
152 |
}
|
153 |
}
|
154 |
|
|
|
161 |
|
162 |
st.components.v1.html(timer_html, height=50)
|
163 |
|
164 |
+
def _change_quote():
|
165 |
+
st.session_state.current_index = random.randint(0, len(quotes)-1)
|
166 |
+
|
167 |
if __name__ == "__main__":
|
168 |
main()
|