Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +21 -13
- data_processing.py +10 -3
app.py
CHANGED
@@ -66,12 +66,12 @@ if "metrics" not in st.session_state:
|
|
66 |
if "metrics" not in st.session_state:
|
67 |
st.session_state.metrics = {}
|
68 |
|
69 |
-
|
70 |
|
71 |
import matplotlib.pyplot as plt
|
72 |
|
73 |
# for visualization
|
74 |
-
|
75 |
|
76 |
# response_time = [q["response_time"] for q in recent_data["questions"]]
|
77 |
# labels = [f"Q{i+1}" for i in range(len(response_time))] # Labels for X-axis
|
@@ -81,22 +81,30 @@ st.sidebar.title("Analytics")
|
|
81 |
# ax.set_ylabel("Time Taken for Response")
|
82 |
# ax.legend()
|
83 |
# st.sidebar.pyplot(fig)
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
-
|
88 |
-
ax.plot(labels, response_time, color="skyblue")
|
89 |
-
ax.set_xlabel("Recent Questions")
|
90 |
-
ax.set_ylabel("Time Taken for Response (seconds)")
|
91 |
-
ax.set_title("Response Time Analysis")
|
92 |
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
|
|
|
95 |
|
96 |
# Streamlit Sidebar for Recent Questions
|
97 |
-
|
98 |
-
for q in reversed(recent_data["questions"]): # Show latest first
|
99 |
-
st.sidebar.write(f"🔹 {q}")
|
100 |
|
101 |
# Submit Button
|
102 |
# if st.button("Submit"):
|
|
|
66 |
if "metrics" not in st.session_state:
|
67 |
st.session_state.metrics = {}
|
68 |
|
69 |
+
recent_questions = load_recent_questions()
|
70 |
|
71 |
import matplotlib.pyplot as plt
|
72 |
|
73 |
# for visualization
|
74 |
+
|
75 |
|
76 |
# response_time = [q["response_time"] for q in recent_data["questions"]]
|
77 |
# labels = [f"Q{i+1}" for i in range(len(response_time))] # Labels for X-axis
|
|
|
81 |
# ax.set_ylabel("Time Taken for Response")
|
82 |
# ax.legend()
|
83 |
# st.sidebar.pyplot(fig)
|
84 |
+
if recent_questions:
|
85 |
+
st.sidebar.title("Analytics")
|
86 |
+
response_time = [q["response_time"] for q in recent_questions["questions"]]
|
87 |
+
labels = [f"Q{i+1}" for i in range(len(response_time))] # Labels for X-axis
|
88 |
+
|
89 |
+
fig, ax = plt.subplots()
|
90 |
+
ax.plot(labels, response_time, color="skyblue")
|
91 |
+
ax.set_xlabel("Recent Questions")
|
92 |
+
ax.set_ylabel("Time Taken for Response (seconds)")
|
93 |
+
ax.set_title("Response Time Analysis")
|
94 |
|
95 |
+
st.sidebar.markdown("---")
|
|
|
|
|
|
|
|
|
96 |
|
97 |
+
st.sidebar.title("Recent Questions")
|
98 |
+
for q in reversed(recent_questions["questions"]): # Show latest first
|
99 |
+
st.sidebar.write(f"🔹 {q["question"]}")
|
100 |
+
else:
|
101 |
+
st.sidebar.write(f"No Recent questions")
|
102 |
|
103 |
+
|
104 |
+
# Separator
|
105 |
|
106 |
# Streamlit Sidebar for Recent Questions
|
107 |
+
|
|
|
|
|
108 |
|
109 |
# Submit Button
|
110 |
# if st.button("Submit"):
|
data_processing.py
CHANGED
@@ -19,6 +19,7 @@ embedding_model = HuggingFaceEmbeddings(
|
|
19 |
)
|
20 |
|
21 |
reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
|
|
|
22 |
|
23 |
# File path for storing recently asked questions and metrics
|
24 |
RECENT_QUESTIONS_FILE = "data_local/recent_questions.json"
|
@@ -95,12 +96,18 @@ def load_ragbench():
|
|
95 |
|
96 |
def load_query_dataset(q_dataset):
|
97 |
global query_dataset_data
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
101 |
query_dataset_data[q_dataset] = load_dataset("rungalileo/ragbench", q_dataset)
|
|
|
|
|
|
|
|
|
102 |
return query_dataset_data[q_dataset]
|
103 |
|
|
|
104 |
def load_faiss(q_dataset):
|
105 |
global index
|
106 |
faiss_index_path = f"data_local/{q_dataset}_quantized.faiss"
|
|
|
19 |
)
|
20 |
|
21 |
reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
|
22 |
+
query_dataset_data = {}
|
23 |
|
24 |
# File path for storing recently asked questions and metrics
|
25 |
RECENT_QUESTIONS_FILE = "data_local/recent_questions.json"
|
|
|
96 |
|
97 |
def load_query_dataset(q_dataset):
|
98 |
global query_dataset_data
|
99 |
+
|
100 |
+
if query_dataset_data.get(q_dataset):
|
101 |
+
return query_dataset_data[q_dataset]
|
102 |
+
try:
|
103 |
query_dataset_data[q_dataset] = load_dataset("rungalileo/ragbench", q_dataset)
|
104 |
+
except Exception as e:
|
105 |
+
print(f"Error loading dataset '{q_dataset}': {e}")
|
106 |
+
return None # Return None if the dataset fails to load
|
107 |
+
|
108 |
return query_dataset_data[q_dataset]
|
109 |
|
110 |
+
|
111 |
def load_faiss(q_dataset):
|
112 |
global index
|
113 |
faiss_index_path = f"data_local/{q_dataset}_quantized.faiss"
|