Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -72,53 +72,61 @@ status_container = st.empty()
|
|
72 |
progress_container = st.empty()
|
73 |
results_container = st.container()
|
74 |
|
75 |
-
#
|
76 |
def create_timer():
|
77 |
return """
|
78 |
-
<div style="
|
79 |
-
<div id="timer" style="font-size:16px;color:#666;margin-bottom:10px;">⏱️ Elapsed: 00:00</div>
|
80 |
-
</div>
|
81 |
<script>
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
// Clear any existing timer
|
88 |
-
if (window[timerID]) {
|
89 |
-
clearInterval(window[timerID]);
|
90 |
}
|
91 |
|
92 |
-
|
93 |
-
const
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
const
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
</script>
|
111 |
"""
|
112 |
|
113 |
def stop_timer():
|
114 |
return """
|
115 |
-
<div style="height:0px;"></div>
|
116 |
<script>
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
</script>
|
123 |
"""
|
124 |
|
@@ -151,7 +159,7 @@ if uploaded_file is not None:
|
|
151 |
st.session_state.current_file = uploaded_file.name
|
152 |
st.session_state.timer_active = True
|
153 |
|
154 |
-
# Display timer
|
155 |
timer_container.html(create_timer())
|
156 |
|
157 |
# Progress indicators
|
@@ -188,7 +196,7 @@ if uploaded_file is not None:
|
|
188 |
# Final status
|
189 |
status_text.success("**✅ Generation complete!**")
|
190 |
|
191 |
-
# Stop timer
|
192 |
timer_container.html(stop_timer())
|
193 |
|
194 |
# Show results
|
|
|
72 |
progress_container = st.empty()
|
73 |
results_container = st.container()
|
74 |
|
75 |
+
# More reliable timer implementation
|
76 |
def create_timer():
|
77 |
return """
|
78 |
+
<div id="timer-display" style="font-size:16px;color:#666;margin-bottom:10px;">⏱️ Elapsed: 00:00</div>
|
|
|
|
|
79 |
<script>
|
80 |
+
(function() {
|
81 |
+
// Make sure we have a clean start
|
82 |
+
if (window.timerInterval) {
|
83 |
+
clearInterval(window.timerInterval);
|
84 |
+
window.timerInterval = null;
|
|
|
|
|
|
|
85 |
}
|
86 |
|
87 |
+
// Set start time
|
88 |
+
const startTime = new Date().getTime();
|
89 |
|
90 |
+
// Update function
|
91 |
+
function updateTimer() {
|
92 |
+
const timerElement = document.getElementById('timer-display');
|
93 |
+
if (!timerElement) return; // Safety check
|
94 |
+
|
95 |
+
const currentTime = new Date().getTime();
|
96 |
+
const elapsedMs = currentTime - startTime;
|
97 |
+
|
98 |
+
const minutes = Math.floor(elapsedMs / 60000);
|
99 |
+
const seconds = Math.floor((elapsedMs % 60000) / 1000);
|
100 |
+
|
101 |
+
const minStr = (minutes < 10) ? '0' + minutes : minutes;
|
102 |
+
const secStr = (seconds < 10) ? '0' + seconds : seconds;
|
103 |
+
|
104 |
+
timerElement.innerHTML = `⏱️ Elapsed: ${minStr}:${secStr}`;
|
105 |
+
}
|
106 |
+
|
107 |
+
// Initial update
|
108 |
+
updateTimer();
|
109 |
+
|
110 |
+
// Set interval for updates
|
111 |
+
window.timerInterval = setInterval(updateTimer, 1000);
|
112 |
+
})();
|
113 |
</script>
|
114 |
"""
|
115 |
|
116 |
def stop_timer():
|
117 |
return """
|
|
|
118 |
<script>
|
119 |
+
(function() {
|
120 |
+
if (window.timerInterval) {
|
121 |
+
clearInterval(window.timerInterval);
|
122 |
+
window.timerInterval = null;
|
123 |
+
|
124 |
+
const timerElement = document.getElementById('timer-display');
|
125 |
+
if (timerElement) {
|
126 |
+
timerElement.style.color = '#00cc00';
|
127 |
+
}
|
128 |
+
}
|
129 |
+
})();
|
130 |
</script>
|
131 |
"""
|
132 |
|
|
|
159 |
st.session_state.current_file = uploaded_file.name
|
160 |
st.session_state.timer_active = True
|
161 |
|
162 |
+
# Display timer
|
163 |
timer_container.html(create_timer())
|
164 |
|
165 |
# Progress indicators
|
|
|
196 |
# Final status
|
197 |
status_text.success("**✅ Generation complete!**")
|
198 |
|
199 |
+
# Stop timer
|
200 |
timer_container.html(stop_timer())
|
201 |
|
202 |
# Show results
|