|
|
|
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. |
|
""" |
|
|
|
answer = run_with_session_memory(message, session_id) |
|
|
|
|
|
history.append((message, answer)) |
|
|
|
|
|
|
|
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 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() |
|
|