Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,34 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
# Initialize the
|
| 5 |
-
retriever = PolicyRetriever()
|
| 6 |
-
|
| 7 |
-
def
|
| 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 |
-
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|