wjbmattingly commited on
Commit
b6a5508
·
verified ·
1 Parent(s): fb0da86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -9
app.py CHANGED
@@ -72,10 +72,10 @@ def highlight_matching_words(text: str, query: str) -> str:
72
  for token in tokens:
73
  token_lc = token.lower()
74
  if token_lc in query_words:
75
- highlighted.append(f'<span style="background:yellow">{token}</span>')
76
  elif token.strip() and token.isalpha() and any(w in token_lc and w != token_lc for w in query_words):
77
  def green_sub(m):
78
- return f'<span style="background:lightgreen">{m.group(0)}</span>'
79
  highlighted.append(partial_pattern.sub(green_sub, token))
80
  else:
81
  highlighted.append(token)
@@ -151,14 +151,82 @@ def format_results_html(results: List[Dict[str, Any]]) -> str:
151
  return f'<div style="color:red">Error: {results[0]["Error"]}</div>'
152
  html = [
153
  '<style>',
154
- '/* Light mode styles */',
155
- 'td,th{padding:8px;}th{background:#f4f1e9;}tr:nth-child(even){background:#f9f9f9;}tr:hover{background:#e6e2d3;}table{border-radius:8px;overflow:hidden;box-shadow:0 2px 8px #e6e2d3;}td{vertical-align:top;}',
156
- 'html, body, #root, .gradio-container {',
157
- ' background: #fff !important;',
158
- ' color: #222 !important;',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  '}',
160
  '</style>',
161
- '<table style="border-collapse:collapse;width:100%;font-size:1em;">',
162
  '<thead><tr>'
163
  '<th>Reference</th><th>Text</th><th>Similarity</th><th>Book</th><th>Chapter</th><th>Verse</th>'
164
  '</tr></thead><tbody>'
@@ -186,7 +254,7 @@ with gr.Blocks(title="Latin Vulgate Verse Similarity Search", theme=gr.themes.So
186
  # Latin Vulgate Verse Similarity Search
187
 
188
  Search for similar verses in the Latin Vulgate Bible using semantic similarity.
189
- <br>Words matching your query will be <span style='background:yellow'>highlighted yellow</span> (exact) or <span style='background:lightgreen'>green</span> (partial).
190
  """)
191
  with gr.Row():
192
  query = gr.Textbox(
 
72
  for token in tokens:
73
  token_lc = token.lower()
74
  if token_lc in query_words:
75
+ highlighted.append(f'<span class="exact-match">{token}</span>')
76
  elif token.strip() and token.isalpha() and any(w in token_lc and w != token_lc for w in query_words):
77
  def green_sub(m):
78
+ return f'<span class="partial-match">{m.group(0)}</span>'
79
  highlighted.append(partial_pattern.sub(green_sub, token))
80
  else:
81
  highlighted.append(token)
 
151
  return f'<div style="color:red">Error: {results[0]["Error"]}</div>'
152
  html = [
153
  '<style>',
154
+ '/* CSS variables for theming */',
155
+ ':root {',
156
+ ' --table-bg: #fff;',
157
+ ' --table-text: #222;',
158
+ ' --header-bg: #f4f1e9;',
159
+ ' --row-even-bg: #f9f9f9;',
160
+ ' --row-hover-bg: #e6e2d3;',
161
+ ' --table-shadow: 0 2px 8px #e6e2d3;',
162
+ ' --exact-match-bg: #ffeb3b;',
163
+ ' --exact-match-text: #000;',
164
+ ' --partial-match-bg: #c8e6c9;',
165
+ ' --partial-match-text: #000;',
166
+ '}',
167
+ '',
168
+ '/* Dark mode styles */',
169
+ '@media (prefers-color-scheme: dark) {',
170
+ ' :root {',
171
+ ' --table-bg: #2d2d2d;',
172
+ ' --table-text: #e0e0e0;',
173
+ ' --header-bg: #3d3d3d;',
174
+ ' --row-even-bg: #333333;',
175
+ ' --row-hover-bg: #404040;',
176
+ ' --table-shadow: 0 2px 8px rgba(0,0,0,0.5);',
177
+ ' --exact-match-bg: #fbc02d;',
178
+ ' --exact-match-text: #000;',
179
+ ' --partial-match-bg: #4caf50;',
180
+ ' --partial-match-text: #fff;',
181
+ ' }',
182
+ '}',
183
+ '',
184
+ '/* Table styles */',
185
+ 'table {',
186
+ ' border-collapse: collapse;',
187
+ ' width: 100%;',
188
+ ' font-size: 1em;',
189
+ ' background: var(--table-bg);',
190
+ ' color: var(--table-text);',
191
+ ' border-radius: 8px;',
192
+ ' overflow: hidden;',
193
+ ' box-shadow: var(--table-shadow);',
194
+ '}',
195
+ '',
196
+ 'td, th {',
197
+ ' padding: 8px;',
198
+ ' vertical-align: top;',
199
+ '}',
200
+ '',
201
+ 'th {',
202
+ ' background: var(--header-bg);',
203
+ ' font-weight: bold;',
204
+ '}',
205
+ '',
206
+ 'tr:nth-child(even) {',
207
+ ' background: var(--row-even-bg);',
208
+ '}',
209
+ '',
210
+ 'tr:hover {',
211
+ ' background: var(--row-hover-bg);',
212
+ '}',
213
+ '',
214
+ '/* Highlighting styles */',
215
+ '.exact-match {',
216
+ ' background: var(--exact-match-bg);',
217
+ ' color: var(--exact-match-text);',
218
+ ' padding: 1px 2px;',
219
+ ' border-radius: 2px;',
220
+ '}',
221
+ '',
222
+ '.partial-match {',
223
+ ' background: var(--partial-match-bg);',
224
+ ' color: var(--partial-match-text);',
225
+ ' padding: 1px 2px;',
226
+ ' border-radius: 2px;',
227
  '}',
228
  '</style>',
229
+ '<table>',
230
  '<thead><tr>'
231
  '<th>Reference</th><th>Text</th><th>Similarity</th><th>Book</th><th>Chapter</th><th>Verse</th>'
232
  '</tr></thead><tbody>'
 
254
  # Latin Vulgate Verse Similarity Search
255
 
256
  Search for similar verses in the Latin Vulgate Bible using semantic similarity.
257
+ <br>Words matching your query will be highlighted (exact matches and partial matches).
258
  """)
259
  with gr.Row():
260
  query = gr.Textbox(