Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import random
|
3 |
|
4 |
-
|
5 |
quotes = [
|
6 |
{"Number": 1, "Quote Topic": "Stages of Life π±", "Quote": "Every age unfolds a new lesson. Life's chapters evolve, each teaching us anew."},
|
7 |
{"Number": 2, "Quote Topic": "Stages of Life π±", "Quote": "From infancy to twilight, our journey is painted in growth. Every stage shines with its own wisdom."},
|
@@ -105,8 +105,6 @@ quotes = [
|
|
105 |
{"Number": 100, "Quote Topic": "Love β€οΈ", "Quote": "Through love, we find connection, unity, and the essence of existence."}
|
106 |
]
|
107 |
|
108 |
-
|
109 |
-
|
110 |
def display_quote(index):
|
111 |
'''Function to display the quote using st.markdown()'''
|
112 |
number = quotes[index]['Number']
|
@@ -115,8 +113,6 @@ def display_quote(index):
|
|
115 |
st.markdown(f"### {number}. {topic}")
|
116 |
st.markdown(quote)
|
117 |
|
118 |
-
|
119 |
-
|
120 |
# Streamlit app
|
121 |
def main():
|
122 |
|
@@ -125,7 +121,7 @@ def main():
|
|
125 |
st.session_state.auto_repeat = "On"
|
126 |
if "current_index" not in st.session_state:
|
127 |
st.session_state.current_index = random.randint(0, len(quotes)-1)
|
128 |
-
|
129 |
st.title("Quote Timer")
|
130 |
|
131 |
# AutoRepeat radio button
|
@@ -134,38 +130,15 @@ def main():
|
|
134 |
# Display the current quote
|
135 |
display_quote(st.session_state.current_index)
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
countdown -= 1;
|
147 |
-
} else {
|
148 |
-
countdown = 5;
|
149 |
-
timerElement.innerHTML = `Time left: ${countdown} seconds`;
|
150 |
-
fetch('/stream').then(response => response.text()).then(data => {
|
151 |
-
if (data) {
|
152 |
-
location.reload();
|
153 |
-
}
|
154 |
-
});
|
155 |
-
}
|
156 |
-
}
|
157 |
-
|
158 |
-
const autoRepeatSetting = '%s';
|
159 |
-
if (autoRepeatSetting === 'On') {
|
160 |
-
setInterval(updateTimer, 1000);
|
161 |
-
}
|
162 |
-
</script>
|
163 |
-
""" % st.session_state.auto_repeat
|
164 |
-
|
165 |
-
st.components.v1.html(timer_html, height=50)
|
166 |
-
|
167 |
-
def _change_quote():
|
168 |
-
st.session_state.current_index = random.randint(0, len(quotes)-1)
|
169 |
|
170 |
if __name__ == "__main__":
|
171 |
-
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
import time
|
3 |
import random
|
4 |
|
|
|
5 |
quotes = [
|
6 |
{"Number": 1, "Quote Topic": "Stages of Life π±", "Quote": "Every age unfolds a new lesson. Life's chapters evolve, each teaching us anew."},
|
7 |
{"Number": 2, "Quote Topic": "Stages of Life π±", "Quote": "From infancy to twilight, our journey is painted in growth. Every stage shines with its own wisdom."},
|
|
|
105 |
{"Number": 100, "Quote Topic": "Love β€οΈ", "Quote": "Through love, we find connection, unity, and the essence of existence."}
|
106 |
]
|
107 |
|
|
|
|
|
108 |
def display_quote(index):
|
109 |
'''Function to display the quote using st.markdown()'''
|
110 |
number = quotes[index]['Number']
|
|
|
113 |
st.markdown(f"### {number}. {topic}")
|
114 |
st.markdown(quote)
|
115 |
|
|
|
|
|
116 |
# Streamlit app
|
117 |
def main():
|
118 |
|
|
|
121 |
st.session_state.auto_repeat = "On"
|
122 |
if "current_index" not in st.session_state:
|
123 |
st.session_state.current_index = random.randint(0, len(quotes)-1)
|
124 |
+
|
125 |
st.title("Quote Timer")
|
126 |
|
127 |
# AutoRepeat radio button
|
|
|
130 |
# Display the current quote
|
131 |
display_quote(st.session_state.current_index)
|
132 |
|
133 |
+
# Timer logic
|
134 |
+
if st.session_state.auto_repeat == "On":
|
135 |
+
timer_placeholder = st.empty()
|
136 |
+
for i in range(5, 0, -1):
|
137 |
+
timer_placeholder.text(f"Time left: {i} seconds")
|
138 |
+
time.sleep(1)
|
139 |
+
if i == 1:
|
140 |
+
st.session_state.current_index = random.randint(0, len(quotes)-1)
|
141 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
if __name__ == "__main__":
|
144 |
+
main()
|