Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -57,13 +57,19 @@ st.title("π¬ AI Chat Assistant")
|
|
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 |
st.markdown(message.content)
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
# User input at the bottom
|
68 |
user_input = st.chat_input("Type your message here...")
|
69 |
|
@@ -83,6 +89,12 @@ if user_input:
|
|
83 |
|
84 |
memory_storage.add_ai_message(answer)
|
85 |
|
86 |
-
# Display AI response
|
87 |
with st.chat_message("assistant", avatar=f"data:image/jpeg;base64,{ai_avatar}"):
|
88 |
st.markdown(answer.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
st.divider()
|
58 |
|
59 |
# Display chat history
|
60 |
+
for idx, message in enumerate(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 |
st.markdown(message.content)
|
66 |
|
67 |
+
# Add copy button only for AI messages
|
68 |
+
if role == "assistant":
|
69 |
+
copy_key = f"copy_btn_{idx}" # Unique key for each copy button
|
70 |
+
st.code(message.content, language="text") # Display code block with text formatting
|
71 |
+
st.button("π Copy", key=copy_key, on_click=lambda text=message.content: st.session_state.update({"copied_text": text}))
|
72 |
+
|
73 |
# User input at the bottom
|
74 |
user_input = st.chat_input("Type your message here...")
|
75 |
|
|
|
89 |
|
90 |
memory_storage.add_ai_message(answer)
|
91 |
|
92 |
+
# Display AI response with copy button
|
93 |
with st.chat_message("assistant", avatar=f"data:image/jpeg;base64,{ai_avatar}"):
|
94 |
st.markdown(answer.content)
|
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!")
|