Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,37 +21,38 @@ if 'processed_data' not in st.session_state:
|
|
21 |
'audio': None
|
22 |
}
|
23 |
|
24 |
-
# JavaScript timer component
|
25 |
def timer():
|
26 |
return """
|
27 |
-
<div id="timer" style="font-size:16px;color:#666;margin-bottom:10px;">⏱️ Elapsed: 00:00</div>
|
28 |
<script>
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
timerInterval = setInterval(function() {
|
35 |
-
var elapsed = Date.now() - start;
|
36 |
-
var minutes = Math.floor(elapsed / 60000);
|
37 |
-
var seconds = Math.floor((elapsed % 60000) / 1000);
|
38 |
-
timerElement.innerHTML = '⏱️ Elapsed: ' +
|
39 |
-
(minutes < 10 ? '0' : '') + minutes + ':' +
|
40 |
-
(seconds < 10 ? '0' : '') + seconds;
|
41 |
-
}, 1000);
|
42 |
}
|
43 |
-
updateTimer();
|
44 |
|
45 |
-
//
|
46 |
-
document.
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
</script>
|
56 |
"""
|
57 |
|
@@ -143,7 +144,11 @@ if uploaded_file is not None:
|
|
143 |
status_text.success("**✅ Generation complete!**")
|
144 |
html("""
|
145 |
<script>
|
146 |
-
|
|
|
|
|
|
|
|
|
147 |
</script>
|
148 |
""")
|
149 |
|
@@ -155,8 +160,11 @@ if uploaded_file is not None:
|
|
155 |
except Exception as e:
|
156 |
html("""
|
157 |
<script>
|
158 |
-
|
159 |
-
document.getElementById('timer')
|
|
|
|
|
|
|
160 |
</script>
|
161 |
""")
|
162 |
status_text.error(f"**❌ Error:** {str(e)}")
|
|
|
21 |
'audio': None
|
22 |
}
|
23 |
|
24 |
+
# Modified JavaScript timer component
|
25 |
def timer():
|
26 |
return """
|
|
|
27 |
<script>
|
28 |
+
// Remove existing timer if present
|
29 |
+
var existingTimer = window.parent.document.getElementById('parent-timer');
|
30 |
+
if (existingTimer) {
|
31 |
+
existingTimer.remove();
|
32 |
+
clearInterval(window.parent.timerInterval);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
|
|
34 |
|
35 |
+
// Create new timer element in parent document
|
36 |
+
var timerDiv = window.parent.document.createElement('div');
|
37 |
+
timerDiv.id = 'parent-timer';
|
38 |
+
timerDiv.style.fontSize = '16px';
|
39 |
+
timerDiv.style.color = '#666';
|
40 |
+
timerDiv.style.marginBottom = '10px';
|
41 |
+
timerDiv.innerHTML = '⏱️ Elapsed: 00:00';
|
42 |
+
window.parent.document.body.appendChild(timerDiv);
|
43 |
|
44 |
+
var start = Date.now();
|
45 |
+
var timerInterval = setInterval(function() {
|
46 |
+
var elapsed = Date.now() - start;
|
47 |
+
var minutes = Math.floor(elapsed / 60000);
|
48 |
+
var seconds = Math.floor((elapsed % 60000) / 1000);
|
49 |
+
timerDiv.innerHTML = '⏱️ Elapsed: ' +
|
50 |
+
(minutes < 10 ? '0' : '') + minutes + ':' +
|
51 |
+
(seconds < 10 ? '0' : '') + seconds;
|
52 |
+
}, 1000);
|
53 |
+
|
54 |
+
// Store the interval ID in the parent window
|
55 |
+
window.parent.timerInterval = timerInterval;
|
56 |
</script>
|
57 |
"""
|
58 |
|
|
|
144 |
status_text.success("**✅ Generation complete!**")
|
145 |
html("""
|
146 |
<script>
|
147 |
+
clearInterval(window.parent.timerInterval);
|
148 |
+
var timerDiv = window.parent.document.getElementById('parent-timer');
|
149 |
+
if (timerDiv) {
|
150 |
+
timerDiv.style.color = '#00cc00';
|
151 |
+
}
|
152 |
</script>
|
153 |
""")
|
154 |
|
|
|
160 |
except Exception as e:
|
161 |
html("""
|
162 |
<script>
|
163 |
+
clearInterval(window.parent.timerInterval);
|
164 |
+
var timerDiv = window.parent.document.getElementById('parent-timer');
|
165 |
+
if (timerDiv) {
|
166 |
+
timerDiv.remove();
|
167 |
+
}
|
168 |
</script>
|
169 |
""")
|
170 |
status_text.error(f"**❌ Error:** {str(e)}")
|