frankai98 commited on
Commit
58f22e2
·
verified ·
1 Parent(s): ef13d6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -45
app.py CHANGED
@@ -22,53 +22,26 @@ if 'processed_data' not in st.session_state:
22
  }
23
 
24
 
25
- # Modified JavaScript timer component
26
  def timer():
27
  return """
28
- <div id="main-timer" style="
29
  position: fixed;
30
- top: 20px;
31
- right: 20px;
 
 
 
 
 
 
 
32
  font-size: 16px;
33
- color: #666;
34
- padding: 8px 15px;
35
- background: #f0f2f6;
36
- border-radius: 20px;
37
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
38
- z-index: 1000000;
39
- border: 1px solid #ddd;
40
  ">
41
- ⏱️ <span id="time-display">00:00</span>
42
  </div>
43
- <script>
44
- // Timer system
45
- let shouldRun = true;
46
- const startTime = Date.now();
47
- const timerElement = document.getElementById('time-display');
48
-
49
- function updateTimer() {
50
- if (!shouldRun) return;
51
-
52
- const elapsed = Math.floor((Date.now() - startTime) / 1000);
53
- const minutes = Math.floor(elapsed / 60).toString().padStart(2, '0');
54
- const seconds = (elapsed % 60).toString().padStart(2, '0');
55
-
56
- timerElement.textContent = `${minutes}:${seconds}`;
57
- requestAnimationFrame(updateTimer);
58
- }
59
-
60
- // Store control in parent window
61
- window.parent.timerControls = {
62
- stop: () => {
63
- shouldRun = false;
64
- document.getElementById('main-timer').style.backgroundColor = '#e6ffe6';
65
- document.getElementById('main-timer').style.borderColor = '#99ff99';
66
- }
67
- };
68
-
69
- // Start updates
70
- updateTimer();
71
- </script>
72
  """
73
 
74
  # Modified stop command
@@ -129,8 +102,14 @@ if uploaded_file is not None:
129
  status_text = st.empty()
130
  progress_bar = st.progress(0)
131
 
132
- # Start JavaScript timer
133
- html(timer(), height=0)
 
 
 
 
 
 
134
 
135
  try:
136
  # Save uploaded file
@@ -168,7 +147,15 @@ if uploaded_file is not None:
168
 
169
  # Final status and stop timer
170
  status_text.success("**✅ Generation complete!**")
171
- html(stop_timer())
 
 
 
 
 
 
 
 
172
 
173
  # Show results
174
  # st.subheader("Results")
@@ -176,7 +163,14 @@ if uploaded_file is not None:
176
  st.write("**Story:**", st.session_state.processed_data['story'])
177
 
178
  except Exception as e:
179
- html(stop_timer())
 
 
 
 
 
 
 
180
  status_text.error(f"**❌ Error:** {str(e)}")
181
  progress_bar.empty()
182
  raise e
 
22
  }
23
 
24
 
25
+ # Timer component with direct DOM manipulation
26
  def timer():
27
  return """
28
+ <div id="streamlit-timer" style="
29
  position: fixed;
30
+ top: 15px;
31
+ right: 15px;
32
+ padding: 10px 20px;
33
+ background: #ffffff;
34
+ border-radius: 25px;
35
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
36
+ z-index: 999999;
37
+ border: 1px solid #e0e0e0;
38
+ font-family: Arial, sans-serif;
39
  font-size: 16px;
40
+ color: #333;
 
 
 
 
 
 
41
  ">
42
+ ⏱️ <span id="timer-display">00:00</span>
43
  </div>
44
+ <script src="https://gist.githubusercontent.com/streamlit-resources/1837910cd9e3d5f8b7e4a/raw/timer.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  """
46
 
47
  # Modified stop command
 
102
  status_text = st.empty()
103
  progress_bar = st.progress(0)
104
 
105
+ # Inject timer HTML
106
+ st.markdown("""
107
+ <div id="timer-container"></div>
108
+ """, unsafe_allow_html=True)
109
+
110
+ # Load timer system
111
+ html(timer(), height=0, width=0)
112
+
113
 
114
  try:
115
  # Save uploaded file
 
147
 
148
  # Final status and stop timer
149
  status_text.success("**✅ Generation complete!**")
150
+ html("""
151
+ <script>
152
+ if (window.timerInterval) {
153
+ clearInterval(window.timerInterval);
154
+ document.getElementById('streamlit-timer').style.background = '#e8f5e9';
155
+ document.getElementById('streamlit-timer').style.color = '#2e7d32';
156
+ }
157
+ </script>
158
+ """)
159
 
160
  # Show results
161
  # st.subheader("Results")
 
163
  st.write("**Story:**", st.session_state.processed_data['story'])
164
 
165
  except Exception as e:
166
+ html("""
167
+ <script>
168
+ if (window.timerInterval) {
169
+ clearInterval(window.timerInterval);
170
+ document.getElementById('streamlit-timer').remove();
171
+ }
172
+ </script>
173
+ """)
174
  status_text.error(f"**❌ Error:** {str(e)}")
175
  progress_bar.empty()
176
  raise e