File size: 1,426 Bytes
87cd864
f36f021
87cd864
a8d22a4
87cd864
c3235ac
87cd864
 
c3235ac
87cd864
 
 
 
 
 
 
 
c585131
87cd864
 
c585131
87cd864
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
import gradio as gr
from my_memory_logic import run_with_session_memory

def chat_interface_fn(message, history, session_id):
    """
    A single-turn chat function for Gradio's ChatInterface.
    We rely on session_id to store the conversation in our my_memory_logic store.
    """
    # 1) We call run_with_session_memory with user message and session_id
    answer = run_with_session_memory(message, session_id)

    # 2) Append the turn to the 'history' so Gradio UI displays it
    history.append((message, answer))
    
    # 3) Convert into message dicts if ChatInterface is using openai-style messages
    #    or we can just return a single string. Let's do openai-style message dicts:
    message_dicts = []
    for user_msg, ai_msg in history:
        message_dicts.append({"role": "user", "content": user_msg})
        message_dicts.append({"role": "assistant", "content": ai_msg})
    return message_dicts, history

# We'll define a small Gradio Blocks or ChatInterface
with gr.Blocks() as demo:
    session_id_box = gr.Textbox(label="Session ID", value="abc123", interactive=True)
    chat_interface = gr.ChatInterface(
        fn=lambda message, history: chat_interface_fn(
            message, history, session_id_box.value
        ),
        title="DailyWellnessAI (Session-based Memory)",
        description="Ask your questions. The session_id determines your stored memory."
    )

demo.launch()