frankai98 commited on
Commit
caadcc0
·
verified ·
1 Parent(s): 52fd13b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -37
app.py CHANGED
@@ -72,53 +72,61 @@ status_container = st.empty()
72
  progress_container = st.empty()
73
  results_container = st.container()
74
 
75
- # JavaScript timer component with stop function
76
  def create_timer():
77
  return """
78
- <div style="height:60px;">
79
- <div id="timer" style="font-size:16px;color:#666;margin-bottom:10px;">⏱️ Elapsed: 00:00</div>
80
- </div>
81
  <script>
82
- // Create a unique timer ID for this session
83
- const timerID = 'timer-' + Date.now();
84
- window[timerID] = null;
85
-
86
- function startTimer() {
87
- // Clear any existing timer
88
- if (window[timerID]) {
89
- clearInterval(window[timerID]);
90
  }
91
 
92
- const start = Date.now();
93
- const timerElement = document.getElementById('timer');
94
 
95
- window[timerID] = setInterval(function() {
96
- const elapsed = Date.now() - start;
97
- const minutes = Math.floor(elapsed / 60000);
98
- const seconds = Math.floor((elapsed % 60000) / 1000);
99
- timerElement.innerHTML = '⏱️ Elapsed: ' +
100
- (minutes < 10 ? '0' : '') + minutes + ':' +
101
- (seconds < 10 ? '0' : '') + seconds;
102
- }, 1000);
103
- }
104
-
105
- // Start the timer immediately
106
- startTimer();
107
-
108
- // Expose the timer ID so it can be stopped later
109
- window.currentTimerID = timerID;
 
 
 
 
 
 
 
 
110
  </script>
111
  """
112
 
113
  def stop_timer():
114
  return """
115
- <div style="height:0px;"></div>
116
  <script>
117
- if (window.currentTimerID && window[window.currentTimerID]) {
118
- clearInterval(window[window.currentTimerID]);
119
- window[window.currentTimerID] = null;
120
- document.getElementById('timer').style.color = '#00cc00';
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 (removed height parameter)
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 (removed height parameter)
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