bappiahk commited on
Commit
86adfcf
·
verified ·
1 Parent(s): 4bc09ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -52
app.py CHANGED
@@ -1,52 +1,34 @@
1
- import gradio as gr
2
- from policy_retriever import PolicyRetriever
3
-
4
- # Initialize the retriever
5
- retriever = PolicyRetriever()
6
-
7
- def search(query):
8
- results = retriever.search(query)
9
- for result in results:
10
- if len(result['content'].strip()) > 50:
11
- return f"""
12
- Search Results for: '{query}'
13
-
14
- Relevance Score: {result['score']:.3f}
15
-
16
- Section:
17
- {'-' * 40}
18
- {result['heading']}
19
-
20
- Content:
21
- {'-' * 40}
22
- {result['content']}
23
-
24
- {'=' * 80}
25
- """
26
- return "No relevant results found."
27
-
28
- # Create the Gradio interface
29
- demo = gr.Interface(
30
- fn=search,
31
- inputs=[
32
- gr.Textbox(
33
- label="Enter your question about the insurance policy",
34
- placeholder="e.g., What are the liability limits?",
35
- lines=2
36
- )
37
- ],
38
- outputs=gr.Textbox(label="Policy Information", lines=10),
39
- title="Insurance Policy Search",
40
- description="""
41
- Ask any question about your insurance policy!
42
- """,
43
- examples=[
44
- ["What are the liability limits?"],
45
- ["How does insurance work with multiple vehicles?"],
46
- ["What happens if there is other insurance?"],
47
- ["How do medical payments work?"]
48
- ]
49
- )
50
-
51
- if __name__ == "__main__":
52
- demo.launch()
 
1
+ import gradio as gr
2
+ from policy_retriever_2 import PolicyRetriever
3
+
4
+ # Initialize the PolicyRetriever
5
+ retriever = PolicyRetriever()
6
+
7
+ def process_query(query):
8
+ """Process a query and return the answer"""
9
+ if not query.strip():
10
+ return "Please enter a question about the policy."
11
+
12
+ try:
13
+ answer = retriever.search_and_generate(query)
14
+ return answer
15
+ except Exception as e:
16
+ return f"An error occurred: {str(e)}"
17
+
18
+ # Create the Gradio interface
19
+ demo = gr.Interface(
20
+ fn=process_query,
21
+ inputs=gr.Textbox(label="Ask a question about your policy", placeholder="e.g., What are the liability limits?"),
22
+ outputs=gr.Textbox(label="Answer"),
23
+ title="Insurance Policy Q&A",
24
+ description="Ask questions about your insurance policy and get answers based on the policy document.",
25
+ examples=[
26
+ ["What are the liability limits for bodily injury and property damage?"],
27
+ ["Who is considered an insured person under this policy?"],
28
+ ["What types of vehicles are covered under insured autos?"],
29
+ ["What is excluded from liability coverage?"]
30
+ ]
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()