Spaces:
Runtime error
Runtime error
| 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) | |