|
import numpy as np |
|
import streamlit as st |
|
|
|
|
|
def brain(supabase): |
|
|
|
response = supabase.table("documents").select("name:metadata->>file_name, size:metadata->>file_size", count="exact").filter('metadata->>user', 'eq', st.session_state["username"]).execute() |
|
|
|
documents = response.data |
|
|
|
|
|
unique_data = [dict(t) for t in set(tuple(d.items()) for d in documents)] |
|
|
|
|
|
unique_data.sort(key=lambda x: int(x['size']), reverse=True) |
|
|
|
|
|
col1, col2 = st.columns(2) |
|
col1.metric(label="Total Documents", value=len(unique_data)) |
|
col2.metric(label="Total Size (bytes)", value=sum(int(doc['size']) for doc in unique_data)) |
|
|
|
for document in unique_data: |
|
|
|
button_key = f"delete_{document['name']}" |
|
|
|
|
|
col1, col2, col3 = st.columns([3, 1, 1]) |
|
col1.markdown(f"**{document['name']}** ({document['size']} bytes)") |
|
|
|
if col2.button('β', key=button_key): |
|
delete_document(supabase, document['name']) |
|
|
|
def delete_document(supabase, document_name): |
|
|
|
response = supabase.table("documents").delete().match({"metadata->>file_name": document_name}).execute() |
|
|
|
if len(response.data) > 0: |
|
st.write(f"βοΈ {document_name} was deleted.") |
|
else: |
|
st.write(f"β {document_name} was not deleted.") |
|
|