import streamlit as st
import json
from datetime import datetime
st.set_page_config(page_title="Vault Index Viewer", layout="wide")
st.title("🔍 Vault Index Viewer")
try:
with open("vault_index.json", "r") as f:
index = json.load(f)
except FileNotFoundError:
st.error("vault_index.json not found. Run `cargo run --bin vault_indexer` first.")
st.stop()
st.sidebar.header("Filter Vaults")
emotion_filter = st.sidebar.text_input("Emotion contains...", "")
min_congruence = st.sidebar.slider("Minimum congruence score", 0.0, 1.0, 0.7)
start_date = st.sidebar.date_input("Start date", None)
end_date = st.sidebar.date_input("End date", None)
def vault_matches(entry):
try:
if emotion_filter.lower() not in entry["emotion"].lower():
return False
if float(entry["congruence_score"]) < min_congruence:
return False
ts = datetime.fromisoformat(entry["timestamp"])
if start_date and ts.date() < start_date:
return False
if end_date and ts.date() > end_date:
return False
return True
except:
return False
matches = [v for v in index if vault_matches(v)]
st.success(f"🔎 {len(matches)} matching Vaults found")
for v in matches:
st.json(v)