File size: 2,189 Bytes
08efb1b
 
 
 
 
65f214d
 
 
08efb1b
739922c
08efb1b
739922c
08efb1b
 
 
 
 
739922c
08efb1b
739922c
08efb1b
 
739922c
08efb1b
739922c
 
 
08efb1b
 
739922c
 
 
 
 
 
 
 
 
65f214d
739922c
65f214d
739922c
65f214d
 
739922c
65f214d
 
739922c
 
65f214d
 
739922c
 
65f214d
 
 
 
 
 
739922c
 
65f214d
 
1
2
3
4
5
6
7
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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)