moazzamdev commited on
Commit
0de21f6
Β·
1 Parent(s): 21ba419

Update page1.py

Browse files
Files changed (1) hide show
  1. page1.py +19 -34
page1.py CHANGED
@@ -8,40 +8,25 @@ from langchain.memory.chat_message_histories import StreamlitChatMessageHistory
8
  from streamlit_chat import message
9
  import time
10
  def text():
11
- st.markdown("""
12
- <style>
13
- .anim-typewriter {
14
- animation: typewriter 3s steps(40) 1s 1 normal both, blinkTextCursor 800ms steps(40) infinite normal;
15
- overflow: hidden;
16
- white-space: nowrap;
17
- border-right: 3px solid;
18
- font-family: serif;
19
- font-size: 0.9em;
20
- }
21
- @keyframes typewriter {
22
- from {
23
- width: 0;
24
- }
25
- to {
26
- width: 100%;
27
- height: 100%
28
- }
29
- }
30
- @keyframes blinkTextCursor {
31
- from {
32
- border-right-color: rgba(255, 255, 255, 0.75);
33
- }
34
- to {
35
- border-right-color: transparent;
36
- }
37
- }
38
- </style>
39
- """, unsafe_allow_html=True)
40
- text ="Hello πŸ‘‹, how may I assist you today?"
41
- animated_output = f'<div class="line-1 anim-typewriter">{text}</div>'
42
-
43
- with st.chat_message("assistant").markdown(animated_output,unsafe_allow_html=True ):
44
- st.markdown(animated_output,unsafe_allow_html=True)
45
  apiKey = "AIzaSyAXkkcrrUBjPEgj93tZ9azy7zcS1wI1jUA"
46
  msgs = StreamlitChatMessageHistory(key="special_app_key")
47
 
 
8
  from streamlit_chat import message
9
  import time
10
  def text():
11
+ with st.chat_message("assistant"):
12
+ message_placeholder = st.empty()
13
+ full_response = ""
14
+ assistant_response = random.choice(
15
+ [
16
+ "Hello there! How can I assist you today?",
17
+ "Hi, human! Is there anything I can help you with?",
18
+ "Do you need help?"
19
+ ]
20
+ )
21
+ # Simulate stream of response with milliseconds delay
22
+ for chunk in assistant_response.split():
23
+ full_response += chunk + " "
24
+ time.sleep(0.05)
25
+ # Add a blinking cursor to simulate typing
26
+ message_placeholder.markdown(full_response + "β–Œ")
27
+ message_placeholder.markdown(full_response)
28
+ # Add assistant response to chat history
29
+ st.session_state.messages.append({"role": "assistant", "content": full_response})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  apiKey = "AIzaSyAXkkcrrUBjPEgj93tZ9azy7zcS1wI1jUA"
31
  msgs = StreamlitChatMessageHistory(key="special_app_key")
32