Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,18 +57,15 @@ st.title("💬 AI Chat Assistant")
|
|
| 57 |
st.divider()
|
| 58 |
|
| 59 |
# Display chat history
|
| 60 |
-
for
|
| 61 |
role = "user" if message.type == "human" else "assistant"
|
| 62 |
avatar = user_avatar if role == "user" else ai_avatar # Assign appropriate avatar
|
| 63 |
|
| 64 |
with st.chat_message(role, avatar=f"data:image/jpeg;base64,{avatar}"):
|
| 65 |
-
st.markdown(message.content)
|
| 66 |
-
|
| 67 |
-
# Add copy button only for AI messages
|
| 68 |
if role == "assistant":
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
st.
|
| 72 |
|
| 73 |
# User input at the bottom
|
| 74 |
user_input = st.chat_input("Type your message here...")
|
|
@@ -89,12 +86,6 @@ if user_input:
|
|
| 89 |
|
| 90 |
memory_storage.add_ai_message(answer)
|
| 91 |
|
| 92 |
-
# Display AI response
|
| 93 |
with st.chat_message("assistant", avatar=f"data:image/jpeg;base64,{ai_avatar}"):
|
| 94 |
-
st.
|
| 95 |
-
|
| 96 |
-
# Copy button for AI response
|
| 97 |
-
st.code(answer.content, language="text")
|
| 98 |
-
if st.button("📋 Copy", key="copy_latest"):
|
| 99 |
-
st.session_state["copied_text"] = answer.content
|
| 100 |
-
st.success("✅ Copied to clipboard!")
|
|
|
|
| 57 |
st.divider()
|
| 58 |
|
| 59 |
# Display chat history
|
| 60 |
+
for message in memory_storage.messages:
|
| 61 |
role = "user" if message.type == "human" else "assistant"
|
| 62 |
avatar = user_avatar if role == "user" else ai_avatar # Assign appropriate avatar
|
| 63 |
|
| 64 |
with st.chat_message(role, avatar=f"data:image/jpeg;base64,{avatar}"):
|
|
|
|
|
|
|
|
|
|
| 65 |
if role == "assistant":
|
| 66 |
+
st.code(message.content, language="markdown") # Copiable markdown
|
| 67 |
+
else:
|
| 68 |
+
st.markdown(message.content)
|
| 69 |
|
| 70 |
# User input at the bottom
|
| 71 |
user_input = st.chat_input("Type your message here...")
|
|
|
|
| 86 |
|
| 87 |
memory_storage.add_ai_message(answer)
|
| 88 |
|
| 89 |
+
# Display AI response as a copiable markdown block
|
| 90 |
with st.chat_message("assistant", avatar=f"data:image/jpeg;base64,{ai_avatar}"):
|
| 91 |
+
st.code(answer.content, language="markdown")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|