SorrelC commited on
Commit
7d33242
Β·
verified Β·
1 Parent(s): e2b5dec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -22
app.py CHANGED
@@ -313,7 +313,7 @@ def collect_entities_from_records(
313
  </div>
314
  '''
315
 
316
- # Return summary and update all 10 dropdowns (5 source + 5 target)
317
  return (
318
  summary_html,
319
  gr.update(choices=entity_names, value=None), # source 1
@@ -326,6 +326,12 @@ def collect_entities_from_records(
326
  gr.update(choices=entity_names, value=None), # target 4
327
  gr.update(choices=entity_names, value=None), # source 5
328
  gr.update(choices=entity_names, value=None), # target 5
 
 
 
 
 
 
329
  )
330
 
331
 
@@ -342,7 +348,10 @@ def generate_network_graph(
342
  src2, rel2, tgt2,
343
  src3, rel3, tgt3,
344
  src4, rel4, tgt4,
345
- src5, rel5, tgt5
 
 
 
346
  ):
347
  """Generate the network graph from all inputs"""
348
  try:
@@ -372,13 +381,16 @@ def generate_network_graph(
372
  if date:
373
  builder.add_entity(date, 'DATE', record_id)
374
 
375
- # Process relationships
376
  relationships = [
377
  (src1, rel1, tgt1),
378
  (src2, rel2, tgt2),
379
  (src3, rel3, tgt3),
380
  (src4, rel4, tgt4),
381
  (src5, rel5, tgt5),
 
 
 
382
  ]
383
 
384
  for source, rel_type, target in relationships:
@@ -394,7 +406,7 @@ def generate_network_graph(
394
  <div style="text-align: center; color: white;">
395
  <div style="font-size: 48px; margin-bottom: 20px;">πŸ“Š</div>
396
  <h3>No entities to display</h3>
397
- <p style="color: #888;">Enter entities above and click "Identify Entities" first</p>
398
  </div>
399
  </div>
400
  '''
@@ -479,24 +491,30 @@ def load_austen_example():
479
  """Load the Jane Austen Pride and Prejudice example"""
480
  return (
481
  # Record 1
482
- "Elizabeth Bennet", "Longbourn", "Meryton Ball", "Bennet Family", "1811",
483
  # Record 2
484
- "Mr. Darcy", "Pemberley", "Netherfield Ball", "Darcy Estate", "",
485
  # Record 3
486
  "Jane Bennet", "Netherfield", "", "", "",
487
  # Record 4
488
  "Mr. Bingley", "London", "", "", "",
489
  # Record 5
490
- "Mr. Wickham", "Meryton", "", "Militia", "",
491
  # Record 6
492
- "Charlotte Lucas", "Hunsford", "", "", "",
493
  # Record 7
494
- "", "", "", "", "",
495
  # Record 8
496
- "", "", "", "", "",
497
  )
498
 
499
 
 
 
 
 
 
 
500
  def load_wwii_example():
501
  """Load a WWII history example"""
502
  return (
@@ -544,7 +562,7 @@ def create_interface():
544
 
545
  ### How to use this tool:
546
  1. **πŸ“ Enter entities** in the records below (or load an example to get started)
547
- 2. **πŸ” Click "Identify Entities"** to collect and list all entities
548
  3. **🀝 Define relationships** between entities using the dropdowns
549
  4. **🎨 Click "Generate Network Graph"** to visualise
550
  5. **πŸ‘οΈ Explore** - drag nodes to rearrange, scroll to zoom, hover for details
@@ -686,19 +704,25 @@ def create_interface():
686
  d8 = gr.Textbox(label="", show_label=False)
687
  entity_inputs.extend([p8, l8, e8, o8, d8])
688
 
689
- # Identify button
690
- collect_btn = gr.Button("πŸ” Identify Entities", variant="primary", size="lg")
 
 
 
 
 
 
691
 
692
  # Full-width entity summary
693
  entity_summary = gr.HTML()
694
 
695
  gr.HTML("<hr style='margin: 20px 0;'>")
696
 
697
- # ==================== STEP 2: RELATIONSHIPS (Grid) ====================
698
- gr.Markdown("## 🀝 Step 2: Define Relationships")
699
- gr.Markdown("*Select entities from the dropdowns to create connections (click 'Identify Entities' first)*")
700
 
701
- # Relationship inputs in a grid (5 columns)
702
  relationship_inputs = []
703
 
704
  with gr.Row():
@@ -737,10 +761,34 @@ def create_interface():
737
  tgt5 = gr.Dropdown(label="To", choices=[])
738
  relationship_inputs.extend([src5, rel5, tgt5])
739
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
740
  gr.HTML("<hr style='margin: 20px 0;'>")
741
 
742
- # ==================== STEP 3: GENERATE & VIEW ====================
743
- gr.Markdown("## 🎨 Step 3: Generate Network Graph")
744
 
745
  generate_btn = gr.Button("🎨 Generate Network Graph", variant="primary", size="lg")
746
 
@@ -777,7 +825,7 @@ def create_interface():
777
  Date
778
  </span>
779
  </div>
780
- <p style="color: #888; margin: 15px 0 0 0; font-size: 13px;">
781
  πŸ–±οΈ <strong>Interaction:</strong> Drag nodes to rearrange β€’ Scroll to zoom β€’ Hover for details
782
  </p>
783
  </div>
@@ -798,7 +846,7 @@ def create_interface():
798
  outputs=entity_inputs
799
  )
800
 
801
- # Collect entities
802
  collect_btn.click(
803
  fn=collect_entities_from_records,
804
  inputs=entity_inputs,
@@ -808,7 +856,10 @@ def create_interface():
808
  src2, tgt2,
809
  src3, tgt3,
810
  src4, tgt4,
811
- src5, tgt5
 
 
 
812
  ]
813
  )
814
 
 
313
  </div>
314
  '''
315
 
316
+ # Return summary and update all 16 dropdowns (8 source + 8 target)
317
  return (
318
  summary_html,
319
  gr.update(choices=entity_names, value=None), # source 1
 
326
  gr.update(choices=entity_names, value=None), # target 4
327
  gr.update(choices=entity_names, value=None), # source 5
328
  gr.update(choices=entity_names, value=None), # target 5
329
+ gr.update(choices=entity_names, value=None), # source 6
330
+ gr.update(choices=entity_names, value=None), # target 6
331
+ gr.update(choices=entity_names, value=None), # source 7
332
+ gr.update(choices=entity_names, value=None), # target 7
333
+ gr.update(choices=entity_names, value=None), # source 8
334
+ gr.update(choices=entity_names, value=None), # target 8
335
  )
336
 
337
 
 
348
  src2, rel2, tgt2,
349
  src3, rel3, tgt3,
350
  src4, rel4, tgt4,
351
+ src5, rel5, tgt5,
352
+ src6, rel6, tgt6,
353
+ src7, rel7, tgt7,
354
+ src8, rel8, tgt8
355
  ):
356
  """Generate the network graph from all inputs"""
357
  try:
 
381
  if date:
382
  builder.add_entity(date, 'DATE', record_id)
383
 
384
+ # Process relationships (now 8 total)
385
  relationships = [
386
  (src1, rel1, tgt1),
387
  (src2, rel2, tgt2),
388
  (src3, rel3, tgt3),
389
  (src4, rel4, tgt4),
390
  (src5, rel5, tgt5),
391
+ (src6, rel6, tgt6),
392
+ (src7, rel7, tgt7),
393
+ (src8, rel8, tgt8),
394
  ]
395
 
396
  for source, rel_type, target in relationships:
 
406
  <div style="text-align: center; color: white;">
407
  <div style="font-size: 48px; margin-bottom: 20px;">πŸ“Š</div>
408
  <h3>No entities to display</h3>
409
+ <p style="color: #888;">Enter entities above and click "Process Entities" first</p>
410
  </div>
411
  </div>
412
  '''
 
491
  """Load the Jane Austen Pride and Prejudice example"""
492
  return (
493
  # Record 1
494
+ "Elizabeth Bennet", "Longbourn", "Meryton Ball", "", "",
495
  # Record 2
496
+ "Mr. Darcy", "Pemberley", "Netherfield Ball", "", "",
497
  # Record 3
498
  "Jane Bennet", "Netherfield", "", "", "",
499
  # Record 4
500
  "Mr. Bingley", "London", "", "", "",
501
  # Record 5
502
+ "Mr. Wickham", "", "", "Militia", "",
503
  # Record 6
504
+ "Charlotte Lucas", "", "", "", "",
505
  # Record 7
506
+ "Mr. Collins", "", "Excellent Boiled Potatoes", "", "",
507
  # Record 8
508
+ "Caroline Bingley", "", "", "", "",
509
  )
510
 
511
 
512
+ def load_austen_example_extra():
513
+ """Return additional Austen characters for records 5-8 area - but we handle in main example"""
514
+ # This is handled by main example now
515
+ pass
516
+
517
+
518
  def load_wwii_example():
519
  """Load a WWII history example"""
520
  return (
 
562
 
563
  ### How to use this tool:
564
  1. **πŸ“ Enter entities** in the records below (or load an example to get started)
565
+ 2. **βš™οΈ Click "Process Entities"** to collect and prepare all entities for relationships
566
  3. **🀝 Define relationships** between entities using the dropdowns
567
  4. **🎨 Click "Generate Network Graph"** to visualise
568
  5. **πŸ‘οΈ Explore** - drag nodes to rearrange, scroll to zoom, hover for details
 
704
  d8 = gr.Textbox(label="", show_label=False)
705
  entity_inputs.extend([p8, l8, e8, o8, d8])
706
 
707
+ gr.HTML("<hr style='margin: 20px 0;'>")
708
+
709
+ # ==================== STEP 2: PROCESS ENTITIES ====================
710
+ gr.Markdown("## βš™οΈ Step 2: Process Entities")
711
+ gr.Markdown("*Click the button below to collect all entities before defining relationships*")
712
+
713
+ # Process button
714
+ collect_btn = gr.Button("βš™οΈ Process Entities", variant="primary", size="lg")
715
 
716
  # Full-width entity summary
717
  entity_summary = gr.HTML()
718
 
719
  gr.HTML("<hr style='margin: 20px 0;'>")
720
 
721
+ # ==================== STEP 3: RELATIONSHIPS (Grid) ====================
722
+ gr.Markdown("## 🀝 Step 3: Define Relationships")
723
+ gr.Markdown("*Select entities from the dropdowns to create connections (click 'Process Entities' first)*")
724
 
725
+ # Relationship inputs in a grid (5 columns for first 5)
726
  relationship_inputs = []
727
 
728
  with gr.Row():
 
761
  tgt5 = gr.Dropdown(label="To", choices=[])
762
  relationship_inputs.extend([src5, rel5, tgt5])
763
 
764
+ # Additional relationships 6-8
765
+ with gr.Accordion("βž• Additional Relationships (6-8)", open=False):
766
+ with gr.Row():
767
+ with gr.Column(scale=1, min_width=180):
768
+ gr.Markdown("**Relationship 6**")
769
+ src6 = gr.Dropdown(label="From", choices=[])
770
+ rel6 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
771
+ tgt6 = gr.Dropdown(label="To", choices=[])
772
+ relationship_inputs.extend([src6, rel6, tgt6])
773
+
774
+ with gr.Column(scale=1, min_width=180):
775
+ gr.Markdown("**Relationship 7**")
776
+ src7 = gr.Dropdown(label="From", choices=[])
777
+ rel7 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
778
+ tgt7 = gr.Dropdown(label="To", choices=[])
779
+ relationship_inputs.extend([src7, rel7, tgt7])
780
+
781
+ with gr.Column(scale=1, min_width=180):
782
+ gr.Markdown("**Relationship 8**")
783
+ src8 = gr.Dropdown(label="From", choices=[])
784
+ rel8 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
785
+ tgt8 = gr.Dropdown(label="To", choices=[])
786
+ relationship_inputs.extend([src8, rel8, tgt8])
787
+
788
  gr.HTML("<hr style='margin: 20px 0;'>")
789
 
790
+ # ==================== STEP 4: GENERATE & VIEW ====================
791
+ gr.Markdown("## 🎨 Step 4: Generate Network Graph")
792
 
793
  generate_btn = gr.Button("🎨 Generate Network Graph", variant="primary", size="lg")
794
 
 
825
  Date
826
  </span>
827
  </div>
828
+ <p style="color: white; margin: 15px 0 0 0; font-size: 13px;">
829
  πŸ–±οΈ <strong>Interaction:</strong> Drag nodes to rearrange β€’ Scroll to zoom β€’ Hover for details
830
  </p>
831
  </div>
 
846
  outputs=entity_inputs
847
  )
848
 
849
+ # Collect entities - now updates 16 dropdowns (8 relationships x 2)
850
  collect_btn.click(
851
  fn=collect_entities_from_records,
852
  inputs=entity_inputs,
 
856
  src2, tgt2,
857
  src3, tgt3,
858
  src4, tgt4,
859
+ src5, tgt5,
860
+ src6, tgt6,
861
+ src7, tgt7,
862
+ src8, tgt8
863
  ]
864
  )
865