-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
693 lines (554 loc) Β· 30.3 KB
/
app.py
File metadata and controls
693 lines (554 loc) Β· 30.3 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
import streamlit as st
import tempfile
import os
import re
import json
import subprocess
import requests
from pathlib import Path
from datetime import datetime, timezone, timedelta
from datetime import datetime, timezone, timedelta
def is_valid_email(email: str) -> bool:
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
return bool(re.match(pattern, email))
def to_rfc3339(dt_obj):
"""Convert datetime to UTC RFC3339 format: YYYY-MM-DDTHH:MM:SS.sssZ"""
if dt_obj.tzinfo is None:
dt_obj = dt_obj.replace(tzinfo=timezone.utc)
else:
dt_obj = dt_obj.astimezone(timezone.utc)
return dt_obj.strftime('%Y-%m-%dT%H:%M:%S.') + f'{dt_obj.microsecond // 1000:03d}Z'
def render_teach_mode_page():
"""Render the Teach Mode page for INTERNAL users - Self-Healing & Maintenance"""
st.title("π§ Teach Mode")
st.caption("Add and manage manual knowledge fixes for the AI assistant")
tab1, tab2 = st.tabs(["Add Knowledge", "Manage Fixes"])
with tab1:
st.subheader("π§ Teach the Bot")
st.write("Add a new Q&A pair to fix knowledge gaps in the assistant.")
with st.form("add_knowledge_form"):
question = st.text_input(
"Question",
placeholder="What question should the bot be able to answer?",
help="Enter the question that users might ask"
)
answer = st.text_area(
"Answer",
placeholder="What is the correct answer to this question?",
height=150,
help="Enter the accurate answer that the bot should provide"
)
col1, col2 = st.columns(2)
with col1:
product_options = ["RazorpayX", "POS", "Payroll", "SmartCollect", "Miscellaneous"]
product = st.selectbox("Product", product_options)
with col2:
access_level = st.radio(
"Access Level",
["INTERNAL", "EXTERNAL"],
horizontal=True,
help="INTERNAL = Staff only, EXTERNAL = Visible to all users"
)
submitted = st.form_submit_button("Add to Brain", type="primary", use_container_width=True)
if submitted:
if not question or not answer:
st.error("Please fill in both Question and Answer fields.")
else:
try:
res = requests.post(
"http://127.0.0.1:8000/api/v1/knowledge/teach",
json={
"question": question,
"answer": answer,
"product": product,
"access_level": access_level
}
)
res.raise_for_status()
st.success("Knowledge Added! The bot will now use this information.")
except requests.exceptions.ConnectionError:
st.error("Cannot connect to backend API.")
except requests.exceptions.HTTPError as e:
st.error(f"Failed to add knowledge: {e.response.text}")
except Exception as e:
st.error(f"Unexpected error: {str(e)}")
with tab2:
st.subheader("ποΈ Maintain Knowledge Base")
st.write("View and delete previously added manual fixes.")
df = vector_db.get_all_manual_fixes()
if df.empty:
st.info("No manual fixes found. Use the 'Add Knowledge' tab to add new Q&A pairs.")
else:
st.dataframe(df, use_container_width=True, hide_index=True)
st.divider()
col1, col2 = st.columns([2, 1])
with col1:
selected_id = st.selectbox(
"Select ID to Remove",
options=df["ID"].tolist(),
help="Select the manual fix you want to delete"
)
with col2:
st.write("")
st.write("")
if st.button("Delete Selected Fix", type="primary", use_container_width=True):
if selected_id:
try:
res = requests.delete(f"http://127.0.0.1:8000/api/v1/knowledge/teach/{selected_id}")
res.raise_for_status()
st.success(f"Deleted: {selected_id}")
st.rerun()
except requests.exceptions.ConnectionError:
st.error("Cannot connect to backend API.")
except requests.exceptions.HTTPError as e:
st.error(f"Failed to delete: {e.response.text}")
except Exception as e:
st.error(f"Unexpected error: {str(e)}")
def render_system_logs_page():
"""Render the System Logs page for INTERNAL users"""
st.title("π System Logs")
st.caption("Query and analyze Coralogix production logs")
if not os.path.exists("./coralogix-mcp"):
st.warning("β οΈ 'coralogix-mcp' binary not found. Running in MOCK mode.")
if not os.environ.get("CORA_AUTH_TOKEN"):
st.error("β οΈ CORA_AUTH_TOKEN not configured. Please add it to secrets to connect to Coralogix.")
st.divider()
st.subheader("β° Time Range")
time_mode = st.radio("Select Time Range Mode", ["Quick Filters", "Custom Range"], horizontal=True)
relative_hours = None
start_dt = None
end_dt = None
if time_mode == "Quick Filters":
col1, col2, col3, col4 = st.columns(4)
if "selected_hours" not in st.session_state:
st.session_state.selected_hours = 1
with col1:
if st.button("Last 1 Hour", use_container_width=True, type="primary" if st.session_state.selected_hours == 1 else "secondary"):
st.session_state.selected_hours = 1
with col2:
if st.button("Last 6 Hours", use_container_width=True, type="primary" if st.session_state.selected_hours == 6 else "secondary"):
st.session_state.selected_hours = 6
with col3:
if st.button("Last 24 Hours", use_container_width=True, type="primary" if st.session_state.selected_hours == 24 else "secondary"):
st.session_state.selected_hours = 24
with col4:
if st.button("Last 4 Days", use_container_width=True, type="primary" if st.session_state.selected_hours == 96 else "secondary"):
st.session_state.selected_hours = 96
relative_hours = st.session_state.selected_hours
st.info(f"π
Selected: Last {relative_hours} hour(s)")
else:
from datetime import time as dt_time
now = datetime.now()
yesterday = now - timedelta(days=1)
def get_default_hour_12(dt_obj):
hour_24 = dt_obj.hour
if hour_24 == 0:
return 12
elif hour_24 > 12:
return hour_24 - 12
else:
return hour_24 if hour_24 != 0 else 12
def get_default_meridian(dt_obj):
return 1 if dt_obj.hour >= 12 else 0
def convert_to_24_hour(hour_12, meridian):
hour = int(hour_12)
if meridian == "AM":
return 0 if hour == 12 else hour
else:
return 12 if hour == 12 else hour + 12
col1, col2 = st.columns(2)
with col1:
st.write("**Start Date & Time**")
start_date = st.date_input("Start Date", value=yesterday.date(), key="start_date", label_visibility="collapsed")
t1_c1, t1_c2, t1_c3, t1_c4, t1_c5 = st.columns([1.2, 1.2, 1.2, 0.3, 1.2])
with t1_c1:
start_hour = st.number_input("HH", min_value=1, max_value=12, value=get_default_hour_12(yesterday), key="start_hour", format="%02d")
with t1_c2:
start_minute = st.number_input("MM", min_value=0, max_value=59, value=yesterday.minute, key="start_minute", format="%02d")
with t1_c3:
start_second = st.number_input("SS", min_value=0, max_value=59, value=yesterday.second, key="start_second", format="%02d")
with t1_c4:
st.write("")
with t1_c5:
start_meridian = st.selectbox("", options=["AM", "PM"], index=get_default_meridian(yesterday), key="start_meridian", label_visibility="collapsed")
start_hour_24 = convert_to_24_hour(start_hour, start_meridian)
start_time_obj = dt_time(start_hour_24, int(start_minute), int(start_second))
start_dt = datetime.combine(start_date, start_time_obj)
with col2:
st.write("**End Date & Time** *(defaults to now if unchanged)*")
end_date = st.date_input("End Date", value=now.date(), key="end_date", label_visibility="collapsed")
t2_c1, t2_c2, t2_c3, t2_c4, t2_c5 = st.columns([1.2, 1.2, 1.2, 0.3, 1.2])
with t2_c1:
end_hour = st.number_input("HH", min_value=1, max_value=12, value=get_default_hour_12(now), key="end_hour", format="%02d")
with t2_c2:
end_minute = st.number_input("MM", min_value=0, max_value=59, value=now.minute, key="end_minute", format="%02d")
with t2_c3:
end_second = st.number_input("SS", min_value=0, max_value=59, value=now.second, key="end_second", format="%02d")
with t2_c4:
st.write("")
with t2_c5:
end_meridian = st.selectbox("", options=["AM", "PM"], index=get_default_meridian(now), key="end_meridian", label_visibility="collapsed")
end_hour_24 = convert_to_24_hour(end_hour, end_meridian)
end_time_obj = dt_time(end_hour_24, int(end_minute), int(end_second))
end_dt = datetime.combine(end_date, end_time_obj)
if start_dt >= end_dt:
st.error("Start Time must be earlier than End Time.")
st.divider()
st.subheader("π Query Parameters")
query_string = st.text_input(
"Search Query",
placeholder="Enter Payout ID, Error Code, IP, or Lucene syntax...",
help="Use Lucene query syntax for advanced searches"
)
st.divider()
if st.button("π Fetch Logs", type="primary", use_container_width=True):
if not query_string:
st.warning("Please enter a search query.")
elif time_mode == "Custom Range" and (start_dt is None or end_dt is None):
st.warning("Please fix the time format errors before fetching logs.")
elif time_mode == "Custom Range" and start_dt >= end_dt:
st.warning("Start Time must be earlier than End Time. Please adjust your selection.")
else:
with st.spinner("Fetching logs from Coralogix..."):
if time_mode == "Quick Filters":
logs_result = fetch_coralogix_logs(query_string, relative_hours=relative_hours)
else:
logs_result = fetch_coralogix_logs(query_string, start_time=start_dt, end_time=end_dt)
st.session_state.logs_result = logs_result
st.session_state.logs_query = query_string
if "logs_result" in st.session_state and st.session_state.logs_result:
logs_result = st.session_state.logs_result
query_string = st.session_state.get("logs_query", "")
st.divider()
if logs_result.get("mock_mode"):
st.warning("β οΈ Displaying MOCK data - Coralogix binary not available")
if logs_result.get("error"):
st.error(f"Error: {logs_result.get('message', 'Unknown error')}")
else:
st.subheader("π€ AI Analysis")
with st.spinner("Analyzing logs with AI..."):
analysis = analyze_logs_with_ai(logs_result, query_string)
st.info(analysis)
st.divider()
st.subheader("π Raw Logs")
with st.expander("View Raw JSON Logs", expanded=False):
st.json(logs_result)
st.set_page_config(
page_title="RazorpayX AI",
page_icon="π€",
layout="wide"
)
if "messages" not in st.session_state:
st.session_state.messages = []
if "user_info" not in st.session_state:
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
st.markdown("---")
st.markdown("<h1 style='text-align: center;'>RazorpayX AI Support</h1>", unsafe_allow_html=True)
st.markdown("<p style='text-align: center; color: gray;'>Your intelligent support assistant</p>", unsafe_allow_html=True)
st.markdown("---")
with st.container():
st.subheader("Login")
email = st.text_input("Enter your work email", placeholder="you@company.com")
if st.button("Login", type="primary", use_container_width=True):
if not email or not email.strip():
st.warning("Please enter an email.")
elif not is_valid_email(email.strip()):
st.error("Please enter a valid email address (e.g., user@company.com)")
else:
email = email.strip().lower()
if email.endswith("@razorpay.com"):
role = "INTERNAL"
else:
role = "EXTERNAL"
st.session_state["user_info"] = {
"email": email,
"role": role
}
st.rerun()
st.markdown("---")
st.markdown("<p style='text-align: center; font-size: 12px; color: gray;'>Staff members use @razorpay.com email for internal access</p>", unsafe_allow_html=True)
else:
user_info = st.session_state["user_info"]
user_email = user_info["email"]
user_role = user_info["role"]
if user_role == "EXTERNAL":
current_view = "Assistant"
else:
if "current_view" not in st.session_state:
st.session_state["current_view"] = "Assistant"
with st.sidebar:
st.markdown(f"π€ **{user_email}**")
if user_role == "INTERNAL":
st.error("π΄ Staff Access")
else:
st.success("π’ Guest Access")
if st.button("Logout", use_container_width=True):
del st.session_state["user_info"]
st.session_state.messages = []
if "current_view" in st.session_state:
del st.session_state["current_view"]
st.rerun()
st.divider()
if user_role == "INTERNAL":
current_view = st.radio(
"Navigation",
["Assistant", "Knowledge Base Admin", "System Logs", "Teach Mode"],
key="nav_radio"
)
st.session_state["current_view"] = current_view
else:
current_view = "Assistant"
if current_view == "Assistant":
st.header("π Session Context")
product_options = ["All Products", "RazorpayX", "POS", "Payroll", "SmartCollect", "Miscellaneous"]
selected_product = st.selectbox(
"Product Filter",
product_options,
help="Filter knowledge base by product"
)
if st.button("Clear Chat History", use_container_width=True):
st.session_state.messages = []
st.rerun()
elif current_view == "Knowledge Base Admin":
st.header("π§ Knowledge Admin")
admin_tab = st.radio(
"Select Action",
["Add Knowledge", "Manage Knowledge"],
horizontal=True
)
st.divider()
if admin_tab == "Add Knowledge":
st.subheader("π Configure Metadata")
product_options_admin = ["RazorpayX", "Payroll", "SmartCollect", "Other"]
selected_product_admin = st.selectbox("Product", product_options_admin)
if selected_product_admin == "Other":
custom_product = st.text_input("Enter Custom Product Name")
product = custom_product if custom_product else "Other"
else:
product = selected_product_admin
feature_options = ["General", "Payouts", "Webhooks", "API Errors", "Other"]
selected_feature = st.selectbox("Feature", feature_options)
if selected_feature == "Other":
custom_feature = st.text_input("Enter Custom Feature Name")
feature = custom_feature if custom_feature else "Other"
else:
feature = selected_feature
access_level = st.radio(
"Access Level",
["EXTERNAL", "INTERNAL"],
format_func=lambda x: f"{x} (Public)" if x == "EXTERNAL" else f"{x} (Private)",
horizontal=True
)
st.divider()
st.subheader("π Data Source")
source_type = st.radio(
"Select Source Type",
["Upload Files", "Add Web URL"],
horizontal=True
)
uploaded_file = None
url_input = None
if source_type == "Upload Files":
uploaded_file = st.file_uploader(
"Upload Document",
type=["pdf", "docx", "csv", "txt"],
help="Supported formats: PDF, DOCX, CSV, TXT"
)
if uploaded_file:
st.info(f"Selected: {uploaded_file.name}")
else:
url_input = st.text_area(
"Enter URLs (one per line)",
placeholder="https://example.com/page1\nhttps://example.com/page2",
height=100
)
st.divider()
if st.button("π Ingest into Knowledge Base", type="primary", use_container_width=True):
if source_type == "Upload Files" and uploaded_file:
with st.spinner("Processing document via backend API..."):
try:
files = {"file": (uploaded_file.name, uploaded_file.getvalue(), uploaded_file.type)}
data = {"product": product, "feature": feature, "access_level": access_level}
res = requests.post("http://127.0.0.1:8000/api/v1/knowledge/upload/file", files=files, data=data)
res.raise_for_status()
response_data = res.json()
chunk_count = response_data.get("chunks", 0)
st.success(f"Successfully ingested {chunk_count} chunks from '{uploaded_file.name}'")
except requests.exceptions.ConnectionError:
st.error("Cannot connect to backend API uploading file.")
except Exception as e:
st.error(f"Error processing file via API: {str(e)}")
elif source_type == "Add Web URL" and url_input:
urls = [url.strip() for url in url_input.strip().split("\n") if url.strip()]
if not urls:
st.warning("Please enter at least one URL")
else:
with st.spinner(f"Processing {len(urls)} URL(s) via backend API..."):
try:
payload = {
"urls": urls,
"product": product,
"feature": feature,
"access_level": access_level
}
res = requests.post("http://127.0.0.1:8000/api/v1/knowledge/upload/urls", json=payload)
res.raise_for_status()
result = res.json()
total_chunks = result.get("total_chunks", 0)
for detail in result.get("details", []):
if detail["status"] == "success":
st.success(f"Ingested {detail['chunks']} chunks from: {detail['url']}")
else:
st.error(f"Failed to process: {detail['url']}")
if total_chunks > 0:
st.success(f"Total: {total_chunks} chunks added to knowledge base")
except requests.exceptions.ConnectionError:
st.error("Cannot connect to backend API processing URLs.")
except Exception as e:
st.error(f"Error processing URLs via API: {str(e)}")
else:
st.warning("Please upload a file or enter URLs first")
else:
st.subheader("π Manage Knowledge Base")
try:
res = requests.get("http://127.0.0.1:8000/api/v1/knowledge/sources")
if res.status_code == 200:
kb_data = res.json()
source_ids = kb_data.get("source_ids", [])
total_chunks = kb_data.get("total_chunks", 0)
source_metadata = kb_data.get("metadata", {})
else:
source_ids = []
total_chunks = 0
source_metadata = {}
except Exception:
source_ids = []
total_chunks = 0
source_metadata = {}
st.error("Could not fetch knowledge base stats from backend API.")
st.metric("Total Documents", len(source_ids))
st.metric("Total Chunks", total_chunks)
st.divider()
if source_ids:
st.subheader("π Indexed Sources")
for source_id in source_ids:
metadata = source_metadata.get(source_id, {})
with st.expander(f"π {source_id}", expanded=False):
col1, col2 = st.columns(2)
with col1:
st.write(f"**Product:** {metadata.get('product', 'N/A')}")
st.write(f"**Feature:** {metadata.get('feature', 'N/A')}")
with col2:
st.write(f"**Access:** {metadata.get('access_level', 'N/A')}")
st.write(f"**Chunks:** {metadata.get('chunk_count', 0)}")
if st.button(f"ποΈ Delete", key=f"del_{source_id}", type="secondary"):
try:
delete_res = requests.delete(f"http://127.0.0.1:8000/api/v1/knowledge/source/{source_id}")
delete_res.raise_for_status()
deleted = delete_res.json().get("chunks_deleted", 0)
st.success(f"Deleted {deleted} chunks for '{source_id}'")
st.rerun()
except Exception as e:
st.error(f"Failed to delete source from API: {e}")
else:
st.info("No documents in the knowledge base yet. Add some using the 'Add Knowledge' tab.")
if current_view == "Assistant":
st.title("π€ RazorpayX AI Assistant")
if user_role == "INTERNAL":
st.caption(f"π΄ Staff Access | Product: **{selected_product}**")
else:
st.caption(f"π’ Guest Access | Product: **{selected_product}**")
st.divider()
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("Ask a question about RazorpayX..."):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
try:
api_payload = {
"query_text": prompt,
"role": user_role,
"product": selected_product,
"chat_history": st.session_state.messages[:-1]
}
endpoint = "http://127.0.0.1:8000/api/v1/chat"
res = requests.post(endpoint, json=api_payload)
res.raise_for_status()
response_data = res.json()
response = response_data.get("answer", "No answer provided from the API.")
except requests.exceptions.ConnectionError:
st.error("The RazorpayX AI backend API is currently offline or unreachable.")
response = "I cannot connect to my knowledge base right now. Please try again later."
except Exception as e:
st.error(f"API Error: {str(e)}")
response = "There was an unexpected error talking to the backend API."
st.markdown(response)
st.session_state.messages.append({"role": "assistant", "content": response})
elif current_view == "Knowledge Base Admin" and user_role == "INTERNAL":
st.title("Knowledge Base Admin")
st.subheader("π΄ Staff Access - Full knowledge base visibility")
st.divider()
col1, col2 = st.columns([2, 1])
with col1:
st.subheader("π Knowledge Base Overview")
try:
res = requests.get("http://127.0.0.1:8000/api/v1/knowledge/sources")
if res.status_code == 200:
kb_data = res.json()
source_ids = kb_data.get("source_ids", [])
total_chunks = kb_data.get("total_chunks", 0)
source_metadata = kb_data.get("metadata", {})
else:
source_ids = []
total_chunks = 0
source_metadata = {}
except Exception:
source_ids = []
total_chunks = 0
source_metadata = {}
if source_ids:
import pandas as pd
data = []
for source_id in source_ids:
metadata = source_metadata.get(source_id, {})
data.append({
"Source": source_id,
"Product": metadata.get("product", "N/A"),
"Feature": metadata.get("feature", "N/A"),
"Access Level": metadata.get("access_level", "N/A"),
"Chunks": metadata.get("chunk_count", 0)
})
df = pd.DataFrame(data)
st.dataframe(df, use_container_width=True, hide_index=True)
else:
st.info("No documents in the knowledge base. Use the sidebar to add documents or URLs.")
with col2:
st.subheader("π Statistics")
st.metric("Total Sources", len(source_ids))
st.metric("Total Chunks", total_chunks)
if source_ids:
products = {}
access_levels = {"EXTERNAL": 0, "INTERNAL": 0}
for source_id in source_ids:
metadata = source_metadata.get(source_id, {})
prod = metadata.get("product", "Unknown")
products[prod] = products.get(prod, 0) + 1
access = metadata.get("access_level", "Unknown")
if access in access_levels:
access_levels[access] += 1
st.write("**By Product:**")
for prod, count in products.items():
st.write(f"- {prod}: {count}")
st.write("**By Access Level:**")
for access, count in access_levels.items():
label = "Public" if access == "EXTERNAL" else "Private"
st.write(f"- {label}: {count}")
elif current_view == "System Logs" and user_role == "INTERNAL":
render_system_logs_page()
elif current_view == "Teach Mode" and user_role == "INTERNAL":
render_teach_mode_page()