import gradio as gr from rag_store import add_memory, search from llm import generate_answer DESCRIPTION = """ ### 🧠 MnemoSense – Tiny External Memory Demo - **Add memory**: type a short summary of something that happened. - **Ask**: query MnemoSense and it will retrieve the most relevant memories and answer using only those. - This demo stores **only text summaries** on-disk, no audio or video. """ def ingest_memory(text: str): text = (text or "").strip() if not text: return "⚠️ Please type something to remember.", "" add_memory(text) return "✅ Saved to MnemoSense memory.", text def ask_question(query: str): query = (query or "").strip() if not query: return "⚠️ Please ask a question." hits = search(query, k=5) contexts = [h["text"] for h in hits] answer = generate_answer(query, contexts) return answer def build_demo(): with gr.Blocks(title="MnemoSense", theme="soft") as demo: gr.Markdown("# 🧠 MnemoSense\nYour tiny external memory assistant.") gr.Markdown(DESCRIPTION) with gr.Tab("Add memory"): mem_in = gr.Textbox( label="What happened?", lines=4, placeholder="Example: I talked to my doctor this morning about my health routine…", ) save_btn = gr.Button("Save memory") status = gr.Markdown() echo = gr.Textbox(label="Saved snippet", interactive=False) save_btn.click( ingest_memory, inputs=mem_in, outputs=[status, echo], ) with gr.Tab("Ask"): q = gr.Textbox( label="Ask MnemoSense", lines=2, placeholder="Example: What did we say about the mission?", ) ask_btn = gr.Button("Ask") ans = gr.Textbox(label="Answer", lines=6) ask_btn.click( ask_question, inputs=q, outputs=ans, ) gr.Markdown("⚠️ Demo note: this Space keeps only text memories in `memories.jsonl`.") return demo demo = build_demo() if __name__ == "__main__": # HF Spaces: bind to 0.0.0.0 and hide API docs (they were causing a schema crash) demo.launch(server_name="0.0.0.0", show_api=False)