NEXAS commited on
Commit
6c61960
Β·
verified Β·
1 Parent(s): e15d896

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -15
app.py CHANGED
@@ -57,18 +57,15 @@ st.title("πŸ’¬ AI Chat Assistant")
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...")
@@ -89,12 +86,6 @@ if user_input:
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!")
 
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")