File size: 2,372 Bytes
6df4ebe
7b5e88a
 
6df4ebe
7b5e88a
 
6df4ebe
7b5e88a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6df4ebe
7b5e88a
 
 
 
 
 
 
 
 
 
 
 
 
013a880
7b5e88a
 
 
 
6df4ebe
7b5e88a
 
 
 
 
6df4ebe
7b5e88a
 
 
 
 
 
 
 
6df4ebe
7b5e88a
 
 
 
 
 
 
 
 
6df4ebe
c57d0e3
 
6df4ebe
7b5e88a
c57d0e3
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
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)