SorrelC commited on
Commit
bfc3a86
·
verified ·
1 Parent(s): e500892

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -64
app.py CHANGED
@@ -218,11 +218,15 @@ def process_text(input_text, primary1, synonyms1, primary2, synonyms2, primary3,
218
  # Create results summary
219
  results_summary = f"""
220
  ## Results Summary
 
221
  **Keywords Found:** {len(keywords_list)}
 
222
  **Matched Keywords:** {found_keywords_str}
 
223
  **Keyword Dictionary Stats:**
224
  - Primary keywords loaded: {len(keywords_dict)}
225
  - Total searchable terms: {sum(len(synonyms) + 1 for synonyms in keywords_dict.values())}
 
226
  **Copy this result to your spreadsheet:**
227
  {found_keywords_str}
228
  """
@@ -250,8 +254,8 @@ def create_interface():
250
  text_input = gr.Textbox(
251
  label="Text to Analyze",
252
  placeholder="Enter the text you want to tag with keywords...",
253
- lines=15,
254
- max_lines=20
255
  )
256
 
257
  with gr.Column(scale=1):
@@ -282,10 +286,17 @@ def create_interface():
282
  primary5 = gr.Textbox(label="Primary Keyword 5", placeholder="Optional", scale=1)
283
  synonyms5 = gr.Textbox(label="Synonyms 5", placeholder="Optional", scale=2)
284
 
 
285
  with gr.Row():
286
  find_btn = gr.Button("Find Keywords", variant="primary", size="lg")
 
 
 
 
287
  clear_dict_btn = gr.Button("Clear Dictionary", size="lg", variant="secondary")
288
- clear_all_btn = gr.Button("Clear All", size="lg")
 
 
289
 
290
  with gr.Row():
291
  results_output = gr.Markdown(label="Results Summary")
@@ -303,55 +314,41 @@ def create_interface():
303
  max_lines=5
304
  )
305
 
306
- # Examples section with improved layout
307
  gr.Markdown("### Examples")
308
- gr.Markdown("Click on an example to load it into the tool:")
309
 
310
- # Example 1
311
- with gr.Row():
312
- with gr.Column(scale=3):
313
- gr.Markdown("**Example 1: WWII & POW Text**")
314
- gr.Markdown("*During World War II, many prisoners of war were held in camps across Europe...*")
315
- with gr.Column(scale=1):
316
- example1_btn = gr.Button("Load Example 1", variant="secondary", size="sm")
317
-
318
- # Example 2
319
- with gr.Row():
320
- with gr.Column(scale=3):
321
- gr.Markdown("**Example 2: University Text**")
322
- gr.Markdown("*The University of Oxford is located in Oxford, England...*")
323
- with gr.Column(scale=1):
324
- example2_btn = gr.Button("Load Example 2", variant="secondary", size="sm")
 
 
 
 
 
 
 
325
 
326
  # Clear functions
 
 
 
 
327
  def clear_dictionary_only():
328
  """Clear only the keyword dictionary fields"""
329
  return "", "", "", "", "", "", "", "", "", ""
330
 
331
- def clear_everything():
332
- """Clear all fields including text input"""
333
- return "", "", "", "", "", "", "", "", "", "", "", "", "", ""
334
-
335
- # Example loading functions
336
- def load_example1():
337
- return [
338
- "During World War II, many prisoners of war were held in camps across Europe. The Geneva Convention established rules for POW treatment. American soldiers and British troops were among those captured.",
339
- "Prisoner of War", "POW; POWs; prisoner of war",
340
- "World War II", "WWII; Second World War",
341
- "United States", "USA; US; America; American",
342
- "", "", "", ""
343
- ]
344
-
345
- def load_example2():
346
- return [
347
- "The University of Oxford is located in Oxford, England. Students from around the world study at this prestigious institution.",
348
- "University", "university; institution; college",
349
- "Oxford", "oxford",
350
- "England", "england; English",
351
- "Student", "student; students; pupils",
352
- "", ""
353
- ]
354
-
355
  # Button functions
356
  find_btn.click(
357
  fn=process_text,
@@ -359,26 +356,16 @@ def create_interface():
359
  outputs=[results_output, highlighted_output, results_table_output, copy_output]
360
  )
361
 
 
 
 
 
 
362
  clear_dict_btn.click(
363
  fn=clear_dictionary_only,
364
  outputs=[primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5]
365
  )
366
 
367
- clear_all_btn.click(
368
- fn=clear_everything,
369
- outputs=[text_input, primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5, results_output, highlighted_output, results_table_output, copy_output]
370
- )
371
-
372
- example1_btn.click(
373
- fn=load_example1,
374
- outputs=[text_input, primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5]
375
- )
376
-
377
- example2_btn.click(
378
- fn=load_example2,
379
- outputs=[text_input, primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5]
380
- )
381
-
382
  # Instructions
383
  gr.Markdown("""
384
  ## Format Guide
@@ -402,12 +389,20 @@ def create_interface():
402
  When ANY variant is found in your text (primary OR synonym), the tool returns the complete standardized set of terms for that concept.
403
  """)
404
 
405
- # Footer
 
406
  gr.HTML("""
407
- <div style="margin-top: 40px; padding: 20px; background-color: #f8f9fa; border-radius: 8px; text-align: center;">
408
- <p style="margin: 0; color: #666;">
409
- Created for digital humanities keyword tagging workflows.
410
- Based on controlled vocabulary matching principles.
 
 
 
 
 
 
 
411
  </p>
412
  </div>
413
  """)
 
218
  # Create results summary
219
  results_summary = f"""
220
  ## Results Summary
221
+
222
  **Keywords Found:** {len(keywords_list)}
223
+
224
  **Matched Keywords:** {found_keywords_str}
225
+
226
  **Keyword Dictionary Stats:**
227
  - Primary keywords loaded: {len(keywords_dict)}
228
  - Total searchable terms: {sum(len(synonyms) + 1 for synonyms in keywords_dict.values())}
229
+
230
  **Copy this result to your spreadsheet:**
231
  {found_keywords_str}
232
  """
 
254
  text_input = gr.Textbox(
255
  label="Text to Analyze",
256
  placeholder="Enter the text you want to tag with keywords...",
257
+ lines=22,
258
+ max_lines=25
259
  )
260
 
261
  with gr.Column(scale=1):
 
286
  primary5 = gr.Textbox(label="Primary Keyword 5", placeholder="Optional", scale=1)
287
  synonyms5 = gr.Textbox(label="Synonyms 5", placeholder="Optional", scale=2)
288
 
289
+ # Full width Find Keywords button
290
  with gr.Row():
291
  find_btn = gr.Button("Find Keywords", variant="primary", size="lg")
292
+
293
+ # Clear buttons side by side under Find Keywords
294
+ with gr.Row():
295
+ clear_text_btn = gr.Button("Clear Text", size="lg", variant="secondary")
296
  clear_dict_btn = gr.Button("Clear Dictionary", size="lg", variant="secondary")
297
+
298
+ # Horizontal line before results
299
+ gr.HTML("<hr style='margin-top: 20px; margin-bottom: 15px;'>")
300
 
301
  with gr.Row():
302
  results_output = gr.Markdown(label="Results Summary")
 
314
  max_lines=5
315
  )
316
 
317
+ # Examples section with table format
318
  gr.Markdown("### Examples")
 
319
 
320
+ example1 = [
321
+ "During World War II, many prisoners of war were held in camps across Europe. The Geneva Convention established rules for POW treatment. American soldiers and British troops were among those captured.",
322
+ "Prisoner of War", "POW; POWs; prisoner of war",
323
+ "World War II", "WWII; Second World War",
324
+ "United States", "USA; US; America; American",
325
+ "", "", "", ""
326
+ ]
327
+
328
+ example2 = [
329
+ "The University of Oxford is located in Oxford, England. Students from around the world study at this prestigious institution.",
330
+ "University", "university; institution; college",
331
+ "Oxford", "oxford",
332
+ "England", "england; English",
333
+ "Student", "student; students; pupils",
334
+ "", ""
335
+ ]
336
+
337
+ gr.Examples(
338
+ examples=[example1, example2],
339
+ inputs=[text_input, primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5],
340
+ label="Click an example to try it out"
341
+ )
342
 
343
  # Clear functions
344
+ def clear_text_only():
345
+ """Clear only the text input field"""
346
+ return ""
347
+
348
  def clear_dictionary_only():
349
  """Clear only the keyword dictionary fields"""
350
  return "", "", "", "", "", "", "", "", "", ""
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  # Button functions
353
  find_btn.click(
354
  fn=process_text,
 
356
  outputs=[results_output, highlighted_output, results_table_output, copy_output]
357
  )
358
 
359
+ clear_text_btn.click(
360
+ fn=clear_text_only,
361
+ outputs=[text_input]
362
+ )
363
+
364
  clear_dict_btn.click(
365
  fn=clear_dictionary_only,
366
  outputs=[primary1, synonyms1, primary2, synonyms2, primary3, synonyms3, primary4, synonyms4, primary5, synonyms5]
367
  )
368
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  # Instructions
370
  gr.Markdown("""
371
  ## Format Guide
 
389
  When ANY variant is found in your text (primary OR synonym), the tool returns the complete standardized set of terms for that concept.
390
  """)
391
 
392
+ # Bottom horizontal line and footer
393
+ gr.HTML("<hr style='margin-top: 40px; margin-bottom: 20px;'>")
394
  gr.HTML("""
395
+ <div style="background-color: #f8f9fa; padding: 20px; border-radius: 8px; margin-top: 20px; text-align: center;">
396
+ <p style="font-size: 14px; line-height: 1.8; margin: 0;">
397
+ This <strong>Keyword Tagging Tool</strong> was created as part of the
398
+ <a href="https://digitalscholarship.web.ox.ac.uk/" target="_blank" style="color: #1976d2;">
399
+ Digital Scholarship at Oxford (DiSc)
400
+ </a>
401
+ funded research project:<br>
402
+ <em>Extracting Keywords from Crowdsourced Collections</em>.
403
+ </p><br><br>
404
+ <p style="font-size: 14px; line-height: 1.8; margin: 0;">
405
+ The code for this tool was built with the aid of Claude Opus 4.
406
  </p>
407
  </div>
408
  """)