faq-chatbot / app.py
gerinsp's picture
update
739922c
Raw
History Blame Contribute Delete
2.19 kB
import streamlit as st
import os
from src.database import initialize_vector_database, load_vector_database
from src.rag_pipeline import get_answer
from src.config import FAQ_CSV_PATH, VECTOR_DB_PATH
from src.evaluation import evaluate_faq_model
import seaborn as sns
import matplotlib.pyplot as plt
st.title("πŸ’¬ Chatbot FAQ with LangChain + Streamlit")
uploaded_file = st.file_uploader("πŸ“‚ Upload a CSV file containing FAQs", type=["csv"])
if uploaded_file:
with open(FAQ_CSV_PATH, "wb") as f:
f.write(uploaded_file.getbuffer())
st.write("πŸ”„ Processing vector database...")
initialize_vector_database(FAQ_CSV_PATH)
st.success("βœ… FAQ successfully processed! The chatbot is ready to use.")
if os.path.exists(VECTOR_DB_PATH):
st.write("βœ… Vector database found! You can start asking questions.")
use_rag = st.toggle("πŸ”„ Use RAG", value=True)
question = st.text_input("❓ Enter your question:")
if question:
with st.spinner("πŸ”„ Generating answer..."):
answer = get_answer(question, use_rag)
st.success("βœ… Answer generated!")
if isinstance(answer, dict):
st.write(f"πŸ’¬ **Answer:** {answer['result']}")
else:
st.write(f"πŸ’¬ **Answer:** {answer}")
st.title("πŸ“Š FAQ Chatbot Evaluation")
if st.button("πŸ” Evaluate Model"):
st.write("πŸ”„ Evaluating...")
# Call the evaluation function
report_df, similarity_gemini, similarity_rag = evaluate_faq_model()
# Display classification report
st.subheader("πŸ“Œ Evaluation Metrics")
st.dataframe(report_df)
# Visualize cosine similarity distribution
st.subheader("πŸ“Š Cosine Similarity Distribution")
fig, ax = plt.subplots(figsize=(6, 4))
sns.histplot(similarity_gemini, bins=20, kde=True, color="blue", label="Gemini")
sns.histplot(similarity_rag, bins=20, kde=True, color="green", label="Gemini + RAG")
plt.axvline(0.8, color="red", linestyle="--", label="Threshold 0.8")
plt.xlabel("Cosine Similarity")
plt.ylabel("Frequency")
plt.title("Cosine Similarity Distribution between Ground Truth and Predictions")
plt.legend()
st.pyplot(fig)