File size: 1,081 Bytes
87cd864 f36f021 87cd864 a8d22a4 87cd864 c3235ac 2cc6ea2 c3235ac 87cd864 2cc6ea2 87cd864 2cc6ea2 c585131 87cd864 c585131 87cd864 2cc6ea2 87cd864 2cc6ea2 87cd864 2cc6ea2 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 |
# app.py
import gradio as gr
from my_memory_logic import run_with_session_memory
def chat_interface_fn(message, history, session_id):
"""
Single-turn function for Gradio's ChatInterface.
'session_id' is used to store conversation across turns.
"""
answer = run_with_session_memory(message, session_id)
# Update local 'history' for the UI
history.append((message, answer))
# Convert to 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
with gr.Blocks() as demo:
session_id_box = gr.Textbox(label="Session ID", value="abc123", interactive=True)
chat_interface = gr.ChatInterface(
fn=lambda msg, hist: chat_interface_fn(msg, hist, session_id_box.value),
title="DailyWellnessAI (Session-based Memory)",
description="Multi-turn chat using session ID and RunnableWithMessageHistory."
)
demo.launch()
|