Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
from sentence_transformers import SentenceTransformer, util
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
faq_df = pd.read_csv("lic_faq.csv")
|
| 7 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 8 |
faq_embeddings = model.encode(faq_df['question'].tolist(), convert_to_tensor=True)
|
|
@@ -10,10 +10,40 @@ faq_embeddings = model.encode(faq_df['question'].tolist(), convert_to_tensor=Tru
|
|
| 10 |
def chatbot(query):
|
| 11 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
| 12 |
scores = util.pytorch_cos_sim(query_embedding, faq_embeddings)[0]
|
| 13 |
-
best_idx = scores.argmax()
|
| 14 |
return faq_df.iloc[best_idx]['answer']
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from sentence_transformers import SentenceTransformer, util
|
| 4 |
|
| 5 |
+
# Load FAQ data
|
| 6 |
faq_df = pd.read_csv("lic_faq.csv")
|
| 7 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 8 |
faq_embeddings = model.encode(faq_df['question'].tolist(), convert_to_tensor=True)
|
|
|
|
| 10 |
def chatbot(query):
|
| 11 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
| 12 |
scores = util.pytorch_cos_sim(query_embedding, faq_embeddings)[0]
|
| 13 |
+
best_idx = int(scores.argmax()) # Fix: convert tensor to int
|
| 14 |
return faq_df.iloc[best_idx]['answer']
|
| 15 |
|
| 16 |
+
# Custom theme and layout using Gradio Blocks
|
| 17 |
+
custom_theme = gr.themes.Base(
|
| 18 |
+
primary_hue="blue",
|
| 19 |
+
secondary_hue="gray",
|
| 20 |
+
font=["Inter", "sans-serif"],
|
| 21 |
+
radius_size=8,
|
| 22 |
+
spacing_size=4
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
with gr.Blocks(theme=custom_theme, title="LIC Agent Assistant") as demo:
|
| 26 |
+
gr.Markdown(
|
| 27 |
+
"""
|
| 28 |
+
# 🧑💼 LIC Agent Assistant Chatbot
|
| 29 |
+
Welcome! Ask any question related to LIC policies, claims, commissions, onboarding, or KYC.
|
| 30 |
+
"""
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
user_input = gr.Textbox(
|
| 35 |
+
lines=2,
|
| 36 |
+
placeholder="Ask your LIC agent question here...",
|
| 37 |
+
label="Your Question"
|
| 38 |
+
)
|
| 39 |
+
with gr.Row():
|
| 40 |
+
output = gr.Textbox(
|
| 41 |
+
label="Answer",
|
| 42 |
+
placeholder="Bot response will appear here...",
|
| 43 |
+
lines=5
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
submit_btn = gr.Button("Get Answer", variant="primary")
|
| 47 |
+
submit_btn.click(fn=chatbot, inputs=user_input, outputs=output)
|
| 48 |
+
|
| 49 |
+
demo.launch()
|