Update app.py
Browse files
app.py
CHANGED
|
@@ -3,36 +3,21 @@ import gradio as gr
|
|
| 3 |
from my_memory_logic import run_with_session_memory
|
| 4 |
|
| 5 |
def chat_interface_fn(message, history, session_id):
|
| 6 |
-
"""
|
| 7 |
-
Multi-turn chat function for Gradio's ChatInterface.
|
| 8 |
-
'session_id' is used to store conversation across turns.
|
| 9 |
-
"""
|
| 10 |
-
# 1) Call run_with_session_memory with user message and session_id
|
| 11 |
answer = run_with_session_memory(message, session_id)
|
| 12 |
-
|
| 13 |
-
# 2) Append the turn to the 'history' so Gradio UI displays it
|
| 14 |
history.append((message, answer))
|
| 15 |
-
|
| 16 |
-
# 3) Convert into message dicts for ChatInterface
|
| 17 |
message_dicts = []
|
| 18 |
for user_msg, ai_msg in history:
|
| 19 |
message_dicts.append({"role": "user", "content": user_msg})
|
| 20 |
message_dicts.append({"role": "assistant", "content": ai_msg})
|
| 21 |
return message_dicts, history
|
| 22 |
|
| 23 |
-
# Define custom CSS to align messages
|
| 24 |
my_chat_css = """
|
| 25 |
-
/* Center the container horizontally so there's some margin */
|
| 26 |
.gradio-container {
|
| 27 |
margin: auto;
|
| 28 |
}
|
| 29 |
-
|
| 30 |
-
/* Right-align user messages */
|
| 31 |
.user .wrap {
|
| 32 |
text-align: right !important;
|
| 33 |
}
|
| 34 |
-
|
| 35 |
-
/* Left-align assistant messages */
|
| 36 |
.assistant .wrap {
|
| 37 |
text-align: left !important;
|
| 38 |
}
|
|
|
|
| 3 |
from my_memory_logic import run_with_session_memory
|
| 4 |
|
| 5 |
def chat_interface_fn(message, history, session_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
answer = run_with_session_memory(message, session_id)
|
|
|
|
|
|
|
| 7 |
history.append((message, answer))
|
|
|
|
|
|
|
| 8 |
message_dicts = []
|
| 9 |
for user_msg, ai_msg in history:
|
| 10 |
message_dicts.append({"role": "user", "content": user_msg})
|
| 11 |
message_dicts.append({"role": "assistant", "content": ai_msg})
|
| 12 |
return message_dicts, history
|
| 13 |
|
|
|
|
| 14 |
my_chat_css = """
|
|
|
|
| 15 |
.gradio-container {
|
| 16 |
margin: auto;
|
| 17 |
}
|
|
|
|
|
|
|
| 18 |
.user .wrap {
|
| 19 |
text-align: right !important;
|
| 20 |
}
|
|
|
|
|
|
|
| 21 |
.assistant .wrap {
|
| 22 |
text-align: left !important;
|
| 23 |
}
|