VladBoyko commited on
Commit
4b05c32
·
verified ·
1 Parent(s): 1ff1f45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -33
app.py CHANGED
@@ -141,6 +141,52 @@ def format_output_html(thinking, answer, code_blocks, prompt_tokens, completion_
141
  total_tokens = prompt_tokens + completion_tokens
142
  thinking_tokens_est = len(thinking.split()) * 1.3 # Rough estimate
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  html = f"""
145
  <div style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; max-width: 100%; margin: 0 auto; background: #ffffff; color: #1a1a1a;">
146
 
@@ -168,18 +214,7 @@ def format_output_html(thinking, answer, code_blocks, prompt_tokens, completion_
168
  </div>
169
 
170
  <!-- Thinking Section (Collapsible) -->
171
- {f'''
172
- <details style="background: #f8f9fa; border: 2px solid #e9ecef; border-radius: 12px; padding: 20px; margin-bottom: 24px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
173
- <summary style="cursor: pointer; font-weight: 600; font-size: 16px; color: #495057; user-select: none; display: flex; align-items: center; gap: 8px;">
174
- <span style="font-size: 20px;">🧠</span>
175
- <span>Reasoning Process ({int(thinking_tokens_est):,} tokens)</span>
176
- <span style="margin-left: auto; font-size: 12px; color: #6c757d;">Click to expand/collapse</span>
177
- </summary>
178
- <div style="margin-top: 16px; padding-top: 16px; border-top: 1px solid #dee2e6; color: #212529; line-height: 1.7; white-space: pre-wrap; font-size: 14px; font-family: 'SF Mono', Monaco, Consolas, monospace; background: #ffffff; padding: 16px; border-radius: 8px;">
179
- {thinking}
180
- </div>
181
- </details>
182
- ''' if thinking else ''}
183
 
184
  <!-- Answer Section -->
185
  <div style="background: #ffffff; border: 2px solid #28a745; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 4px rgba(40,167,69,0.1);">
@@ -192,27 +227,7 @@ def format_output_html(thinking, answer, code_blocks, prompt_tokens, completion_
192
  </div>
193
 
194
  <!-- Code Blocks -->
195
- {f'''
196
- <div style="margin-top: 24px;">
197
- <h3 style="color: #1a1a1a; font-size: 18px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 8px;">
198
- <span style="font-size: 22px;">💻</span> Code
199
- </h3>
200
- {"".join([f'''
201
- <div style="margin-bottom: 16px; background: #1e1e1e; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
202
- <div style="background: #2d2d2d; padding: 12px 20px; color: #ffffff; font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #3d3d3d;">
203
- <span>{lang if lang else "code"}</span>
204
- <button onclick="navigator.clipboard.writeText(this.parentElement.nextElementSibling.textContent)"
205
- style="background: #4CAF50; color: white; border: none; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 500; transition: background 0.2s;"
206
- onmouseover="this.style.background='#45a049'"
207
- onmouseout="this.style.background='#4CAF50'">
208
- 📋 Copy
209
- </button>
210
- </div>
211
- <pre style="margin: 0; padding: 20px; color: #d4d4d4; overflow-x: auto; font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 14px; line-height: 1.6;"><code>{code.strip()}</code></pre>
212
- </div>
213
- ''' for lang, code in code_blocks])}
214
- </div>
215
- ''' if code_blocks else ''}
216
 
217
  </div>
218
  """
 
141
  total_tokens = prompt_tokens + completion_tokens
142
  thinking_tokens_est = len(thinking.split()) * 1.3 # Rough estimate
143
 
144
+ # Build thinking section HTML if exists
145
+ thinking_html = ""
146
+ if thinking:
147
+ thinking_html = f"""
148
+ <details style="background: #f8f9fa; border: 2px solid #e9ecef; border-radius: 12px; padding: 20px; margin-bottom: 24px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
149
+ <summary style="cursor: pointer; font-weight: 600; font-size: 16px; color: #495057; user-select: none; display: flex; align-items: center; gap: 8px;">
150
+ <span style="font-size: 20px;">🧠</span>
151
+ <span>Reasoning Process ({int(thinking_tokens_est):,} tokens)</span>
152
+ <span style="margin-left: auto; font-size: 12px; color: #6c757d;">Click to expand/collapse</span>
153
+ </summary>
154
+ <div style="margin-top: 16px; padding-top: 16px; border-top: 1px solid #dee2e6; color: #212529; line-height: 1.7; white-space: pre-wrap; font-size: 14px; font-family: 'SF Mono', Monaco, Consolas, monospace; background: #ffffff; padding: 16px; border-radius: 8px;">
155
+ {thinking}
156
+ </div>
157
+ </details>
158
+ """
159
+
160
+ # Build code blocks HTML if exist
161
+ code_html = ""
162
+ if code_blocks:
163
+ code_blocks_html = ""
164
+ for lang, code in code_blocks:
165
+ lang_display = lang if lang else "code"
166
+ code_blocks_html += f"""
167
+ <div style="margin-bottom: 16px; background: #1e1e1e; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
168
+ <div style="background: #2d2d2d; padding: 12px 20px; color: #ffffff; font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #3d3d3d;">
169
+ <span>{lang_display}</span>
170
+ <button onclick="navigator.clipboard.writeText(this.parentElement.nextElementSibling.textContent)"
171
+ style="background: #4CAF50; color: white; border: none; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 500; transition: background 0.2s;"
172
+ onmouseover="this.style.background='#45a049'"
173
+ onmouseout="this.style.background='#4CAF50'">
174
+ 📋 Copy
175
+ </button>
176
+ </div>
177
+ <pre style="margin: 0; padding: 20px; color: #d4d4d4; overflow-x: auto; font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 14px; line-height: 1.6;"><code>{code.strip()}</code></pre>
178
+ </div>
179
+ """
180
+
181
+ code_html = f"""
182
+ <div style="margin-top: 24px;">
183
+ <h3 style="color: #1a1a1a; font-size: 18px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 8px;">
184
+ <span style="font-size: 22px;">💻</span> Code
185
+ </h3>
186
+ {code_blocks_html}
187
+ </div>
188
+ """
189
+
190
  html = f"""
191
  <div style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; max-width: 100%; margin: 0 auto; background: #ffffff; color: #1a1a1a;">
192
 
 
214
  </div>
215
 
216
  <!-- Thinking Section (Collapsible) -->
217
+ {thinking_html}
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  <!-- Answer Section -->
220
  <div style="background: #ffffff; border: 2px solid #28a745; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 4px rgba(40,167,69,0.1);">
 
227
  </div>
228
 
229
  <!-- Code Blocks -->
230
+ {code_html}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
  </div>
233
  """