File size: 2,224 Bytes
f639904
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""InsuranceKnowledgeAgent - RAG-Powered Policy Q&A

Built using BDR Agent Factory v1
"""

import gradio as gr
from agents.retrieval_agent import RetrievalAgent

class InsuranceKnowledgeAgent:
    def __init__(self):
        self.retrieval_agent = RetrievalAgent()
    
    def answer_question(self, question: str):
        results = self.retrieval_agent.process(question)
        
        answer_text = f"**Answer:**\n{results['answer']}"
        
        clauses_text = f"**Supporting Clauses:**\n"
        if results['supporting_clauses']:
            clauses_text += "\n".join("- " + c for c in results['supporting_clauses'])
        else:
            clauses_text += "No clauses cited"
        
        confidence_text = f"**Confidence:** {results['confidence']:.1%}"
        
        return answer_text, clauses_text, confidence_text

app = InsuranceKnowledgeAgent()

with gr.Blocks(title="InsuranceKnowledgeAgent", theme=gr.themes.Soft()) as demo:
    gr.Markdown("""
# 📚 InsuranceKnowledgeAgent
## RAG-Powered Insurance Policy Knowledge

**Clause citation | Version-aware | Policy conflict resolution**

*Built using [BDR Agent Factory v1](https://huggingface.co/spaces/bdr-ai-org/BDR-Agent-Factory)*
""")
    
    with gr.Row():
        with gr.Column():
            gr.Markdown("### ❓ Ask a Question")
            question_input = gr.Textbox(label="Question", placeholder="What does the policy cover?", lines=3)
            ask_btn = gr.Button("🔍 Get Answer", variant="primary", size="lg")
        
        with gr.Column():
            gr.Markdown("### 💡 Answer")
            answer_output = gr.Textbox(label="Answer", lines=3)
            clauses_output = gr.Textbox(label="Supporting Clauses", lines=3)
            confidence_output = gr.Textbox(label="Confidence", lines=1)
    
    gr.Examples(
        examples=[
            ["What does the policy cover?"],
            ["What are the exclusions?"],
            ["How do I file a claim?"],
        ],
        inputs=[question_input]
    )
    
    ask_btn.click(
        fn=app.answer_question,
        inputs=[question_input],
        outputs=[answer_output, clauses_output, confidence_output]
    )

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