Spaces:
Build error
Build error
Upload 2 files
Browse files- app.py +19 -4
- data_processing.py +15 -13
app.py
CHANGED
|
@@ -9,6 +9,19 @@ import matplotlib.pyplot as plt
|
|
| 9 |
# Page Title
|
| 10 |
st.title("RAG7 - Real World RAG System")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# global retrieved_documents
|
| 13 |
# retrieved_documents = []
|
| 14 |
|
|
@@ -80,10 +93,11 @@ recent_questions = load_recent_questions()
|
|
| 80 |
# ax.legend()
|
| 81 |
# st.sidebar.pyplot(fig)
|
| 82 |
if recent_questions and "questions" in recent_questions and recent_questions["questions"]:
|
|
|
|
| 83 |
st.sidebar.title("Analytics")
|
| 84 |
|
| 85 |
# Extract response times and labels
|
| 86 |
-
response_time = [q["response_time"] for q in
|
| 87 |
labels = [f"Q{i+1}" for i in range(len(response_time))]
|
| 88 |
|
| 89 |
# Plot graph
|
|
@@ -100,7 +114,7 @@ if recent_questions and "questions" in recent_questions and recent_questions["qu
|
|
| 100 |
|
| 101 |
# Display Recent Questions
|
| 102 |
st.sidebar.title("Recent Questions")
|
| 103 |
-
for q in
|
| 104 |
st.sidebar.write(f"🔹 {q['question']}")
|
| 105 |
else:
|
| 106 |
st.sidebar.write("No recent questions")
|
|
@@ -147,11 +161,12 @@ col1, col2 = st.columns([1, 3]) # Creating two columns for button and metrics d
|
|
| 147 |
|
| 148 |
# Calculate Metrics Button
|
| 149 |
with col1:
|
| 150 |
-
if st.button("Show Metrics"):
|
| 151 |
st.session_state.metrics = calculate_metrics(question, st.session_state.query_dataset, st.session_state.response, st.session_state.retrieved_documents, st.session_state.time_taken_for_response)
|
| 152 |
else:
|
| 153 |
metrics_ = {}
|
| 154 |
|
| 155 |
with col2:
|
| 156 |
#st.text_area("Metrics:", value=metrics, height=100, disabled=True)
|
| 157 |
-
st.json(st.session_state.metrics)
|
|
|
|
|
|
| 9 |
# Page Title
|
| 10 |
st.title("RAG7 - Real World RAG System")
|
| 11 |
|
| 12 |
+
st.markdown(
|
| 13 |
+
"""
|
| 14 |
+
<style>
|
| 15 |
+
.stTextArea textarea {
|
| 16 |
+
background-color: white !important;
|
| 17 |
+
color: black !important;
|
| 18 |
+
font-weight: bold;
|
| 19 |
+
}
|
| 20 |
+
</style>
|
| 21 |
+
""",
|
| 22 |
+
unsafe_allow_html=True
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
# global retrieved_documents
|
| 26 |
# retrieved_documents = []
|
| 27 |
|
|
|
|
| 93 |
# ax.legend()
|
| 94 |
# st.sidebar.pyplot(fig)
|
| 95 |
if recent_questions and "questions" in recent_questions and recent_questions["questions"]:
|
| 96 |
+
recent_qns = list(reversed(recent_questions["questions"]))
|
| 97 |
st.sidebar.title("Analytics")
|
| 98 |
|
| 99 |
# Extract response times and labels
|
| 100 |
+
response_time = [q["response_time"] for q in recent_qns]
|
| 101 |
labels = [f"Q{i+1}" for i in range(len(response_time))]
|
| 102 |
|
| 103 |
# Plot graph
|
|
|
|
| 114 |
|
| 115 |
# Display Recent Questions
|
| 116 |
st.sidebar.title("Recent Questions")
|
| 117 |
+
for q in recent_qns: # Show latest first
|
| 118 |
st.sidebar.write(f"🔹 {q['question']}")
|
| 119 |
else:
|
| 120 |
st.sidebar.write("No recent questions")
|
|
|
|
| 161 |
|
| 162 |
# Calculate Metrics Button
|
| 163 |
with col1:
|
| 164 |
+
if st.button("Show Metrics"):
|
| 165 |
st.session_state.metrics = calculate_metrics(question, st.session_state.query_dataset, st.session_state.response, st.session_state.retrieved_documents, st.session_state.time_taken_for_response)
|
| 166 |
else:
|
| 167 |
metrics_ = {}
|
| 168 |
|
| 169 |
with col2:
|
| 170 |
#st.text_area("Metrics:", value=metrics, height=100, disabled=True)
|
| 171 |
+
st.json(st.session_state.metrics)
|
| 172 |
+
|
data_processing.py
CHANGED
|
@@ -146,17 +146,19 @@ def load_recent_questions():
|
|
| 146 |
def save_recent_question(question, response_time):
|
| 147 |
data = load_recent_questions()
|
| 148 |
|
| 149 |
-
data["questions"] = [q for q in data["questions"] if q["question"] != question]
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
| 158 |
-
data["questions"] = data["questions"][-5:]
|
| 159 |
-
|
| 160 |
-
# Write back to file
|
| 161 |
-
with open(RECENT_QUESTIONS_FILE, "w") as file:
|
| 162 |
-
json.dump(data, file, indent=4)
|
|
|
|
| 146 |
def save_recent_question(question, response_time):
|
| 147 |
data = load_recent_questions()
|
| 148 |
|
| 149 |
+
#data["questions"] = [q for q in data["questions"] if q["question"] != question]
|
| 150 |
+
if "question" in data["questions"] and question not in data["questions"]["question"]:
|
| 151 |
+
# Append new question & metrics
|
| 152 |
+
data["questions"].append({
|
| 153 |
+
"question": question,
|
| 154 |
+
"response_time": response_time
|
| 155 |
+
})
|
| 156 |
+
|
| 157 |
+
# Keep only the last 5 questions
|
| 158 |
+
data["questions"] = data["questions"][-5:]
|
| 159 |
+
|
| 160 |
+
# Write back to file
|
| 161 |
+
with open(RECENT_QUESTIONS_FILE, "w") as file:
|
| 162 |
+
json.dump(data, file, indent=4)
|
| 163 |
|
| 164 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|