awacke1 commited on
Commit
88421dd
Β·
1 Parent(s): c60f2fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -115,26 +115,23 @@ def display_quote(index):
115
  st.markdown(f"### {number}. {topic}")
116
  st.markdown(quote)
117
 
 
 
118
  # Streamlit app
119
  def main():
120
 
121
  # Session state to hold the value of AutoRepeat button across reruns
122
  if "auto_repeat" not in st.session_state:
123
  st.session_state.auto_repeat = "On"
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 = """
@@ -144,11 +141,17 @@ def main():
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
 
 
115
  st.markdown(f"### {number}. {topic}")
116
  st.markdown(quote)
117
 
118
+
119
+
120
  # Streamlit app
121
  def main():
122
 
123
  # Session state to hold the value of AutoRepeat button across reruns
124
  if "auto_repeat" not in st.session_state:
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
132
  st.session_state.auto_repeat = st.radio("πŸ”„ AutoRepeat", ["On", "Off"])
133
 
134
+ # Display the current quote
 
 
 
 
 
 
 
135
  display_quote(st.session_state.current_index)
136
 
137
  timer_html = """
 
141
  const timerElement = document.getElementById('timer');
142
 
143
  function updateTimer() {
144
+ if (countdown > 1) {
145
  timerElement.innerHTML = `Time left: ${countdown} seconds`;
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