|
import streamlit as st
|
|
import pandas as pd
|
|
import json
|
|
import os
|
|
from qa_loader import load_qa_and_create_vectorstore
|
|
from langchain_chroma import Chroma
|
|
|
|
|
|
st.set_page_config(page_title="Admin Dashboard", layout="wide")
|
|
|
|
|
|
log_dir = "logs"
|
|
log_files = [f for f in os.listdir(log_dir) if f.startswith("auto_test_results")]
|
|
|
|
|
|
if log_files:
|
|
latest_log = sorted(log_files)[-1]
|
|
log_path = os.path.join(log_dir, latest_log)
|
|
with open(log_path, "r", encoding="utf-8") as f:
|
|
log_data = f.readlines()
|
|
else:
|
|
log_data = []
|
|
|
|
|
|
st.title("π Admin Dashboard")
|
|
st.subheader("π AI Model Log Analysis")
|
|
|
|
if log_data:
|
|
correct_count = sum(1 for line in log_data if "β
Correct" in line)
|
|
incorrect_count = sum(1 for line in log_data if "β Incorrect" in line)
|
|
total_count = correct_count + incorrect_count
|
|
accuracy = (correct_count / total_count) * 100 if total_count > 0 else 0
|
|
|
|
st.metric("β
Correct Answers", correct_count)
|
|
st.metric("β Incorrect Answers", incorrect_count)
|
|
st.metric("π― Accuracy", f"{accuracy:.2f}%")
|
|
|
|
|
|
question_lines = [line for line in log_data if line.startswith("Q:")]
|
|
question_counts = pd.Series(question_lines).value_counts().head(10)
|
|
|
|
st.subheader("π Most Frequently Asked Questions")
|
|
st.write(question_counts)
|
|
|
|
else:
|
|
st.warning("β οΈ No log records found. Please run the automated tests.")
|
|
|
|
|
|
st.subheader("π Update Q&A Database")
|
|
|
|
|
|
qa_file = "Q&A_cleaned.json"
|
|
if os.path.exists(qa_file):
|
|
with open(qa_file, "r", encoding="utf-8") as f:
|
|
qa_data = json.load(f)
|
|
else:
|
|
qa_data = []
|
|
|
|
|
|
new_question = st.text_input("π New Question:")
|
|
new_answer = st.text_area("π Answer:")
|
|
|
|
if st.button("πΎ Save"):
|
|
if new_question and new_answer:
|
|
qa_data.append({"QUESTION": new_question, "ANSWER": new_answer})
|
|
with open(qa_file, "w", encoding="utf-8") as f:
|
|
json.dump(qa_data, f, indent=4)
|
|
st.success("β
New question added!")
|
|
else:
|
|
st.warning("β οΈ Please enter both a question and an answer.")
|
|
|
|
|
|
st.subheader("π Edit Incorrect Answers")
|
|
|
|
if qa_data:
|
|
question_list = [q["QUESTION"] for q in qa_data]
|
|
selected_question = st.selectbox("π Select Question to Edit:", question_list)
|
|
|
|
selected_item = next((q for q in qa_data if q["QUESTION"] == selected_question), None)
|
|
updated_answer = st.text_area("βοΈ Updated Answer:", selected_item["ANSWER"] if selected_item else "")
|
|
|
|
if st.button("π Update"):
|
|
if selected_item:
|
|
selected_item["ANSWER"] = updated_answer
|
|
with open(qa_file, "w", encoding="utf-8") as f:
|
|
json.dump(qa_data, f, indent=4)
|
|
st.success("β
Answer updated!")
|
|
|
|
|
|
st.subheader("π Update Vector Database")
|
|
if st.button("π₯ Re-train"):
|
|
retriever = load_qa_and_create_vectorstore()
|
|
st.success("β
Vector database successfully updated!")
|
|
|