Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -110,9 +110,9 @@ def active_timer():
|
|
110 |
return timer_html
|
111 |
|
112 |
def frozen_timer(time_display):
|
113 |
-
|
114 |
<div style="font-size:16px;color:#00cc00;font-weight:bold;margin-bottom:10px;">
|
115 |
-
<span id="timer-display">⏱️ Elapsed:
|
116 |
</div>
|
117 |
|
118 |
<script>
|
@@ -123,13 +123,15 @@ def frozen_timer(time_display):
|
|
123 |
}
|
124 |
</script>
|
125 |
"""
|
|
|
126 |
|
127 |
def empty_timer():
|
128 |
-
|
129 |
<div style="font-size:16px;color:#666;margin-bottom:10px;">
|
130 |
<span id="timer-display">⏱️ Elapsed: 00:00</span>
|
131 |
</div>
|
132 |
"""
|
|
|
133 |
|
134 |
# Display empty timer initially
|
135 |
if not st.session_state.timer_active:
|
@@ -215,41 +217,8 @@ if st.button("Play Audio of the Story Generated"):
|
|
215 |
if st.session_state.image_data is not None:
|
216 |
image_container.image(st.session_state.image_data, caption="Uploaded Image", use_container_width=True)
|
217 |
|
218 |
-
#
|
219 |
-
|
220 |
-
<script>
|
221 |
-
// Function to get current timer text and send to Streamlit
|
222 |
-
function getCurrentTime() {
|
223 |
-
var timerElement = document.getElementById("timer-display");
|
224 |
-
if (timerElement) {
|
225 |
-
var timerText = timerElement.innerText;
|
226 |
-
// Extract just the time part
|
227 |
-
var timePart = timerText.replace("⏱️ Elapsed: ", "");
|
228 |
-
|
229 |
-
// Use Streamlit's setComponentValue to send the value back
|
230 |
-
if (window.parent.Streamlit) {
|
231 |
-
window.parent.Streamlit.setComponentValue(timePart);
|
232 |
-
}
|
233 |
-
} else {
|
234 |
-
// Default if timer not found
|
235 |
-
if (window.parent.Streamlit) {
|
236 |
-
window.parent.Streamlit.setComponentValue("00:00");
|
237 |
-
}
|
238 |
-
}
|
239 |
-
}
|
240 |
-
|
241 |
-
// Execute immediately
|
242 |
-
getCurrentTime();
|
243 |
-
</script>
|
244 |
-
"""
|
245 |
-
|
246 |
-
# Use a simple trick: Place a dummy component to execute this JavaScript
|
247 |
-
# The actual freezing will be done in the next step
|
248 |
-
dummy_component = html(get_time_js, height=0)
|
249 |
-
|
250 |
-
# For now, just freeze with a default time
|
251 |
-
# (We can't easily get the current time value from JS to Python in Streamlit)
|
252 |
-
timer_container.markdown(frozen_timer("00:00"), unsafe_allow_html=True)
|
253 |
|
254 |
# Set timer as inactive since we've frozen it
|
255 |
st.session_state.timer_active = False
|
|
|
110 |
return timer_html
|
111 |
|
112 |
def frozen_timer(time_display):
|
113 |
+
timer_html = """
|
114 |
<div style="font-size:16px;color:#00cc00;font-weight:bold;margin-bottom:10px;">
|
115 |
+
<span id="timer-display">⏱️ Elapsed: """ + time_display + """ ✓</span>
|
116 |
</div>
|
117 |
|
118 |
<script>
|
|
|
123 |
}
|
124 |
</script>
|
125 |
"""
|
126 |
+
return timer_html
|
127 |
|
128 |
def empty_timer():
|
129 |
+
timer_html = """
|
130 |
<div style="font-size:16px;color:#666;margin-bottom:10px;">
|
131 |
<span id="timer-display">⏱️ Elapsed: 00:00</span>
|
132 |
</div>
|
133 |
"""
|
134 |
+
return timer_html
|
135 |
|
136 |
# Display empty timer initially
|
137 |
if not st.session_state.timer_active:
|
|
|
217 |
if st.session_state.image_data is not None:
|
218 |
image_container.image(st.session_state.image_data, caption="Uploaded Image", use_container_width=True)
|
219 |
|
220 |
+
# Freeze the timer (with a default value since we can't easily get the real time)
|
221 |
+
timer_container.markdown(frozen_timer("00:30"), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
|
223 |
# Set timer as inactive since we've frozen it
|
224 |
st.session_state.timer_active = False
|