LIC_Agent / app.py
dschandra's picture
Update app.py
d458480 verified
raw
history blame
1.78 kB
import gradio as gr
import pandas as pd
from sentence_transformers import SentenceTransformer, util
# Load FAQ data
faq_df = pd.read_csv("lic_faq.csv")
model = SentenceTransformer('all-MiniLM-L6-v2')
faq_embeddings = model.encode(faq_df['question'].tolist(), convert_to_tensor=True)
def chatbot(query):
query_embedding = model.encode(query, convert_to_tensor=True)
scores = util.pytorch_cos_sim(query_embedding, faq_embeddings)[0]
best_score = float(scores.max()) # Get max similarity score
best_idx = int(scores.argmax())
if best_score < 0.6: # Threshold can be adjusted
return (
"🤖 I'm not confident I have the right answer for that.\n"
"Please ask a question related to LIC policies, claims, onboarding, or commissions."
)
else:
return faq_df.iloc[best_idx]['answer']
with gr.Blocks(title="LIC Agent Assistant") as demo:
gr.Markdown(
"""
<h1 style='text-align: center; color: #1a237e;'>🧑‍💼 LIC Agent Assistant Chatbot</h1>
<p style='text-align: center;'>Ask questions about LIC policies, commissions, claims, onboarding, and more!</p>
""",
elem_id="header"
)
with gr.Row():
with gr.Column(scale=1):
user_input = gr.Textbox(
label="Your Question",
placeholder="E.g., How do I file a claim?",
lines=2
)
submit_btn = gr.Button("Get Answer", variant="primary")
with gr.Column(scale=1):
output = gr.Textbox(
label="Answer",
placeholder="Response will appear here...",
lines=6
)
submit_btn.click(fn=chatbot, inputs=user_input, outputs=output)
demo.launch()