File size: 7,441 Bytes
32a5a16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import gradio as gr
import json
import os

# Load capability registry
def load_registry():
    registry_path = os.path.join(os.path.dirname(__file__), '..', 'data', 'capability_registry.json')
    with open(registry_path, 'r') as f:
        return json.load(f)

registry = load_registry()
capabilities = registry['capabilities']

# Extract unique values for filters
all_categories = sorted(list(set([cap['category'] for cap in capabilities])))
all_spaces = sorted(list(set([space for cap in capabilities for space in cap['used_in_spaces']])))
all_models = sorted(list(set([model for cap in capabilities for model in cap['models']])))
all_datasets = sorted(list(set([dataset for cap in capabilities for dataset in cap['datasets']])))

def search_capabilities(search_text, category_filter, space_filter, model_filter, dataset_filter):
    """Search and filter capabilities based on user inputs"""
    filtered_caps = capabilities
    
    # Apply search text filter
    if search_text:
        search_lower = search_text.lower()
        filtered_caps = [
            cap for cap in filtered_caps 
            if search_lower in cap['capability_name'].lower() 
            or search_lower in cap['category'].lower()
            or search_lower in ' '.join(cap['insurance_decisions']).lower()
        ]
    
    # Apply category filter
    if category_filter and category_filter != "All":
        filtered_caps = [cap for cap in filtered_caps if cap['category'] == category_filter]
    
    # Apply space filter
    if space_filter and space_filter != "All":
        filtered_caps = [cap for cap in filtered_caps if space_filter in cap['used_in_spaces']]
    
    # Apply model filter
    if model_filter and model_filter != "All":
        filtered_caps = [cap for cap in filtered_caps if model_filter in cap['models']]
    
    # Apply dataset filter
    if dataset_filter and dataset_filter != "All":
        filtered_caps = [cap for cap in filtered_caps if dataset_filter in cap['datasets']]
    
    # Generate HTML output
    if not filtered_caps:
        return "<div style='padding: 20px; text-align: center;'><h3>No capabilities found matching your criteria.</h3></div>"
    
    html_output = f"<div style='padding: 20px;'><h3>Found {len(filtered_caps)} Capability(ies)</h3>"
    
    for cap in filtered_caps:
        html_output += f"""
        <div style='border: 1px solid #ddd; border-radius: 8px; padding: 20px; margin: 15px 0; background: #f9f9f9;'>
            <h3 style='margin-top: 0; color: #2c3e50;'>πŸ”Ή {cap['capability_name']}</h3>
            <p><strong>Category:</strong> {cap['category']}</p>
            <p><strong>Used in Spaces:</strong> {', '.join(cap['used_in_spaces'])}</p>
            <p><strong>Models:</strong> {', '.join(cap['models'])}</p>
            <p><strong>Datasets:</strong> {', '.join(cap['datasets'])}</p>
            <p><strong>Insurance Decisions:</strong> {', '.join(cap['insurance_decisions'])}</p>
            <p><strong>Governance Required:</strong> {'βœ… Yes' if cap['governance_required'] else '❌ No'}</p>
        </div>
        """
    
    html_output += "</div>"
    return html_output

def create_capability_browser():
    """Create the Gradio interface for capability browsing"""
    
    with gr.Blocks(title="BDR Agent Factory - Capability Browser", theme=gr.themes.Soft()) as demo:
        gr.Markdown("""
        # 🏭 BDR Agent Factory β€” Capability Browser
        
        **Enterprise Decision Intelligence Architecture for Insurance & Regulated Markets**
        
        Browse and search AI capabilities used across the Bader AI platform. Filter by category, system, model, or dataset to understand how capabilities map to insurance decisions.
        """)
        
        with gr.Row():
            with gr.Column(scale=2):
                search_box = gr.Textbox(
                    label="πŸ” Search Capabilities",
                    placeholder="Search by capability name, category, or decision...",
                    lines=1
                )
            
        with gr.Row():
            category_dropdown = gr.Dropdown(
                choices=["All"] + all_categories,
                value="All",
                label="πŸ“‚ Filter by Category",
                interactive=True
            )
            space_dropdown = gr.Dropdown(
                choices=["All"] + all_spaces,
                value="All",
                label="πŸš€ Filter by Space",
                interactive=True
            )
            model_dropdown = gr.Dropdown(
                choices=["All"] + all_models,
                value="All",
                label="πŸ€– Filter by Model",
                interactive=True
            )
            dataset_dropdown = gr.Dropdown(
                choices=["All"] + all_datasets,
                value="All",
                label="πŸ“Š Filter by Dataset",
                interactive=True
            )
        
        search_button = gr.Button("Search", variant="primary", size="lg")
        
        results_html = gr.HTML(
            value=search_capabilities("", "All", "All", "All", "All"),
            label="Results"
        )
        
        # Set up event handlers
        search_button.click(
            fn=search_capabilities,
            inputs=[search_box, category_dropdown, space_dropdown, model_dropdown, dataset_dropdown],
            outputs=results_html
        )
        
        # Also trigger search on Enter key in search box
        search_box.submit(
            fn=search_capabilities,
            inputs=[search_box, category_dropdown, space_dropdown, model_dropdown, dataset_dropdown],
            outputs=results_html
        )
        
        gr.Markdown("""
        ---
        
        ## πŸ“š Documentation
        
        - **[Overview](https://huggingface.co/spaces/bdr-ai-org/BDR-Agent-Factory/blob/main/docs/00_OVERVIEW.md)**: What is BDR Agent Factory?
        - **[Capability Dictionary](https://huggingface.co/spaces/bdr-ai-org/BDR-Agent-Factory/blob/main/docs/01_CAPABILITY_DICTIONARY.md)**: Full catalog of AI capabilities (A–N)
        - **[Capability Map](https://huggingface.co/spaces/bdr-ai-org/BDR-Agent-Factory/blob/main/docs/02_CAPABILITY_MAP.md)**: Mappings to systems, models, datasets, decisions
        - **[Governance Standards](https://huggingface.co/spaces/bdr-ai-org/BDR-Agent-Factory/blob/main/docs/03_GOVERNANCE.md)**: Unified governance policies
        - **[Extension Guide](https://huggingface.co/spaces/bdr-ai-org/BDR-Agent-Factory/blob/main/docs/04_EXTENSION_GUIDE.md)**: How to add new capabilities
        
        ## πŸ”— Linked Systems
        
        - **[ClaimsGPT](https://huggingface.co/spaces/bdr-ai-org/ClaimsGPT)**: AI-powered claim decision intelligence
        - **[FraudSimulator-AI](https://huggingface.co/spaces/bdr-ai-org/FraudSimulator-AI)**: Fraud risk and anomaly detection
        - **[AutoRiskScoreEngine](https://huggingface.co/spaces/bdr-ai-org/AutoRiskScoreEngine)**: IFRS-ready underwriting risk assessment
        - **[InsuranceKnowledgeAgent](https://huggingface.co/spaces/bdr-ai-org/InsuranceKnowledgeAgent)**: RAG-powered policy knowledge
        
        ---
        
        **BDR Agent Factory** β€” The authoritative capability registry for Bader AI, the GCC Insurance Decision Intelligence Platform.
        """)
    
    return demo

if __name__ == "__main__":
    demo = create_capability_browser()
    demo.launch()