RDF Validation Deployment commited on
Commit
3bbd742
Β·
1 Parent(s): 1af1e67

Major UI improvements: add theme, use Code blocks for JSON, simplify markdown, add elem_ids to fix tab rendering - 2025-10-04 15:49:03

Browse files
Files changed (1) hide show
  1. app.py +79 -71
app.py CHANGED
@@ -517,88 +517,88 @@ def get_property_usage(property_name: str, class_name: str = "") -> str:
517
 
518
  # Create Gradio interface
519
  def create_interface():
520
- # Custom CSS to make HF logo smaller and reduce page size
521
  custom_css = """
 
522
  .svelte-1rjryqp {
523
  max-width: 48px !important;
524
  max-height: 48px !important;
525
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  """
527
 
528
- with gr.Blocks(title="BIBFRAME Ontology Documentation MCP Server", css=custom_css) as demo:
529
  gr.Markdown(f"""
530
  # πŸ“š BIBFRAME Ontology Documentation MCP Server
531
 
532
  **Status:** {'βœ… Loaded' if kb._loaded else '⚠️ Using fallback data'} - {len(kb.properties)} properties, {len(kb.classes)} classes
533
 
534
  This server provides BIBFRAME ontology documentation via MCP tools.
535
- Data is loaded from the official BIBFRAME ontology at [id.loc.gov](https://id.loc.gov/ontologies/bibframe.html).
536
-
537
- ## Available MCP Tools:
538
- - `get_property_info`: Get detailed information about a BIBFRAME property
539
- - `get_class_info`: Get detailed information about a BIBFRAME class
540
- - `search_ontology`: Search for properties or classes by term
541
- - `get_property_usage`: Get usage information for a property in context
542
-
543
- ## MCP Configuration:
544
- ```json
545
- {{
546
- "mcpServers": {{
547
- "bibframe-docs": {{
548
- "url": "https://your-space.hf.space/gradio_api/mcp/"
549
- }}
550
- }}
551
- }}
552
- ```
553
-
554
- ## Data Sources:
555
- - [BIBFRAME Ontology](https://id.loc.gov/ontologies/bibframe.html) - Official ontology from Library of Congress
556
- - [LC BIBFRAME Profiles](https://github.com/lcnetdev/bfe-profiles) - Application profiles
557
- - [DCTap Validation](https://github.com/bf-interop/DCTap) - Community validation patterns
558
  """)
559
 
560
- with gr.Tabs():
561
  # Tab 1: Property Lookup
562
- with gr.Tab("Property Lookup"):
563
  with gr.Row():
564
  with gr.Column():
565
  property_input = gr.Textbox(
566
  label="Property Name",
567
- placeholder="e.g., assigner, bf:assigner, or title"
 
568
  )
569
  property_btn = gr.Button("πŸ” Look Up Property", variant="primary")
570
- property_output = gr.Textbox(label="Property Information", lines=20)
571
-
572
- property_btn.click(
573
- fn=get_property_info,
574
- inputs=[property_input],
575
- outputs=[property_output]
576
- )
 
577
 
578
  # Tab 2: Class Lookup
579
- with gr.Tab("Class Lookup"):
580
  with gr.Row():
581
  with gr.Column():
582
  class_input = gr.Textbox(
583
  label="Class Name",
584
- placeholder="e.g., Work, AdminMetadata, or Instance"
 
585
  )
586
  class_btn = gr.Button("πŸ” Look Up Class", variant="primary")
587
- class_output = gr.Textbox(label="Class Information", lines=20)
588
-
589
- class_btn.click(
590
- fn=get_class_info,
591
- inputs=[class_input],
592
- outputs=[class_output]
593
- )
 
594
 
595
  # Tab 3: Search
596
- with gr.Tab("Search Ontology"):
597
  with gr.Row():
598
  with gr.Column():
599
  search_input = gr.Textbox(
600
  label="Search Term",
601
- placeholder="e.g., title, agent, date, or admin"
 
602
  )
603
  search_type = gr.Radio(
604
  label="Search Type",
@@ -606,46 +606,54 @@ def create_interface():
606
  value="all"
607
  )
608
  search_btn = gr.Button("πŸ” Search", variant="primary")
609
- search_output = gr.Textbox(label="Search Results", lines=20)
610
-
611
- search_btn.click(
612
- fn=search_ontology,
613
- inputs=[search_input, search_type],
614
- outputs=[search_output]
615
- )
 
616
 
617
  # Tab 4: Property Usage
618
- with gr.Tab("Property Usage Context"):
619
  with gr.Row():
620
  with gr.Column():
621
  usage_prop_input = gr.Textbox(
622
  label="Property Name",
623
- placeholder="e.g., assigner, title, or adminMetadata"
 
624
  )
625
  usage_class_input = gr.Textbox(
626
  label="Class Context (optional)",
627
- placeholder="e.g., AdminMetadata, Work, or Instance"
 
628
  )
629
  usage_btn = gr.Button("πŸ” Get Usage Info", variant="primary")
630
- usage_output = gr.Textbox(label="Usage Information", lines=20)
631
-
632
- usage_btn.click(
633
- fn=get_property_usage,
634
- inputs=[usage_prop_input, usage_class_input],
635
- outputs=[usage_output]
636
- )
 
637
 
 
638
  gr.Markdown("""
639
  ---
640
- ### πŸ’‘ Usage Tips:
641
- - Property names can be entered with or without the `bf:` prefix
642
- - Search is case-insensitive and matches against names, labels, and definitions
643
- - Use the "Property Usage Context" tab to understand how properties work with specific classes
 
 
 
 
 
 
644
 
645
- ### πŸ”— Related Resources:
646
- - **For SHACL validation**: Use the [mcp4rdf validator](https://huggingface.co/spaces/jimfhahn/mcp4rdf)
647
- - **BIBFRAME Homepage**: [https://www.loc.gov/bibframe/](https://www.loc.gov/bibframe/)
648
- - **BIBFRAME Documentation**: [https://www.loc.gov/bibframe/docs/](https://www.loc.gov/bibframe/docs/)
649
  """)
650
 
651
  return demo
 
517
 
518
  # Create Gradio interface
519
  def create_interface():
520
+ # Custom CSS to improve rendering and reduce page weight
521
  custom_css = """
522
+ /* Make HF logo smaller */
523
  .svelte-1rjryqp {
524
  max-width: 48px !important;
525
  max-height: 48px !important;
526
  }
527
+
528
+ /* Improve container layout */
529
+ .gradio-container {
530
+ max-width: 1200px !important;
531
+ margin: auto !important;
532
+ }
533
+
534
+ /* Fix tab rendering */
535
+ .tabs {
536
+ overflow: visible !important;
537
+ }
538
+
539
+ /* Better code display */
540
+ .code-wrap {
541
+ font-family: 'Courier New', monospace !important;
542
+ font-size: 12px !important;
543
+ }
544
  """
545
 
546
+ with gr.Blocks(title="BIBFRAME Ontology Documentation MCP Server", css=custom_css, theme=gr.themes.Soft()) as demo:
547
  gr.Markdown(f"""
548
  # πŸ“š BIBFRAME Ontology Documentation MCP Server
549
 
550
  **Status:** {'βœ… Loaded' if kb._loaded else '⚠️ Using fallback data'} - {len(kb.properties)} properties, {len(kb.classes)} classes
551
 
552
  This server provides BIBFRAME ontology documentation via MCP tools.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  """)
554
 
555
+ with gr.Tabs(visible=True, elem_id="main-tabs"):
556
  # Tab 1: Property Lookup
557
+ with gr.Tab("Property Lookup", elem_id="property-tab"):
558
  with gr.Row():
559
  with gr.Column():
560
  property_input = gr.Textbox(
561
  label="Property Name",
562
+ placeholder="e.g., assigner, bf:assigner, or title",
563
+ max_lines=1
564
  )
565
  property_btn = gr.Button("πŸ” Look Up Property", variant="primary")
566
+
567
+ property_output = gr.Code(label="Property Information", language="json", lines=20)
568
+
569
+ property_btn.click(
570
+ fn=get_property_info,
571
+ inputs=[property_input],
572
+ outputs=[property_output]
573
+ )
574
 
575
  # Tab 2: Class Lookup
576
+ with gr.Tab("Class Lookup", elem_id="class-tab"):
577
  with gr.Row():
578
  with gr.Column():
579
  class_input = gr.Textbox(
580
  label="Class Name",
581
+ placeholder="e.g., Work, AdminMetadata, or Instance",
582
+ max_lines=1
583
  )
584
  class_btn = gr.Button("πŸ” Look Up Class", variant="primary")
585
+
586
+ class_output = gr.Code(label="Class Information", language="json", lines=20)
587
+
588
+ class_btn.click(
589
+ fn=get_class_info,
590
+ inputs=[class_input],
591
+ outputs=[class_output]
592
+ )
593
 
594
  # Tab 3: Search
595
+ with gr.Tab("Search Ontology", elem_id="search-tab"):
596
  with gr.Row():
597
  with gr.Column():
598
  search_input = gr.Textbox(
599
  label="Search Term",
600
+ placeholder="e.g., title, agent, date, or admin",
601
+ max_lines=1
602
  )
603
  search_type = gr.Radio(
604
  label="Search Type",
 
606
  value="all"
607
  )
608
  search_btn = gr.Button("πŸ” Search", variant="primary")
609
+
610
+ search_output = gr.Code(label="Search Results", language="json", lines=20)
611
+
612
+ search_btn.click(
613
+ fn=search_ontology,
614
+ inputs=[search_input, search_type],
615
+ outputs=[search_output]
616
+ )
617
 
618
  # Tab 4: Property Usage
619
+ with gr.Tab("Property Usage Context", elem_id="usage-tab"):
620
  with gr.Row():
621
  with gr.Column():
622
  usage_prop_input = gr.Textbox(
623
  label="Property Name",
624
+ placeholder="e.g., assigner, title, or adminMetadata",
625
+ max_lines=1
626
  )
627
  usage_class_input = gr.Textbox(
628
  label="Class Context (optional)",
629
+ placeholder="e.g., AdminMetadata, Work, or Instance",
630
+ max_lines=1
631
  )
632
  usage_btn = gr.Button("πŸ” Get Usage Info", variant="primary")
633
+
634
+ usage_output = gr.Code(label="Usage Information", language="json", lines=20)
635
+
636
+ usage_btn.click(
637
+ fn=get_property_usage,
638
+ inputs=[usage_prop_input, usage_class_input],
639
+ outputs=[usage_output]
640
+ )
641
 
642
+ # Simplified footer to reduce page weight
643
  gr.Markdown("""
644
  ---
645
+ ### MCP Configuration:
646
+ ```json
647
+ {
648
+ "mcpServers": {
649
+ "bibframe-docs": {
650
+ "url": "https://your-space.hf.space/gradio_api/mcp/"
651
+ }
652
+ }
653
+ }
654
+ ```
655
 
656
+ **Resources:** [BIBFRAME Docs](https://www.loc.gov/bibframe/) | [Validator](https://huggingface.co/spaces/jimfhahn/mcp4rdf)
 
 
 
657
  """)
658
 
659
  return demo