Chatbot2 / app.py
Phoenix21's picture
UPDATE APP.PY WITH SESSION ID
87cd864 verified
raw
history blame
1.43 kB
# 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()