Phaneendrabayi commited on
Commit
89ef4cf
·
verified ·
1 Parent(s): c00ba83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -82,25 +82,41 @@ with col1:
82
 
83
  parsed_response = output_parser.parse(response)
84
  save_chat(st.session_state.user_id, user_input, parsed_response)
85
- chat_history.append((HumanMessage(content=user_input), AIMessage(content=parsed_response)))
 
86
 
87
  # Display Chat History in WhatsApp-style Chat Format
88
  st.subheader("Chat")
89
  chat_container = st.container()
90
- for message, response in chat_history:
 
 
 
 
 
 
 
 
 
 
91
  with chat_container:
92
- st.markdown(f"""
93
- <div style='display: flex; justify-content: flex-end; margin: 5px;'>
94
- <div style='border-radius: 15px; padding: 10px; background-color: #DCF8C6; max-width: 70%;'>
95
- <b>You:</b> {message.content}
 
 
96
  </div>
97
- </div>
98
- <div style='display: flex; justify-content: flex-start; margin: 5px;'>
99
- <div style='border-radius: 15px; padding: 10px; background-color: #EAEAEA; max-width: 70%;'>
100
- <b>AI:</b> {response.content}
 
 
 
 
101
  </div>
102
- </div>
103
- """, unsafe_allow_html=True)
104
 
105
  with col2:
106
  # Clear Chat History Option
 
82
 
83
  parsed_response = output_parser.parse(response)
84
  save_chat(st.session_state.user_id, user_input, parsed_response)
85
+ chat_history.append(HumanMessage(content=user_input))
86
+ chat_history.append(AIMessage(content=parsed_response))
87
 
88
  # Display Chat History in WhatsApp-style Chat Format
89
  st.subheader("Chat")
90
  chat_container = st.container()
91
+
92
+ for msg in chat_history:
93
+ if isinstance(msg, HumanMessage):
94
+ message = msg.content
95
+ response = ""
96
+ elif isinstance(msg, AIMessage):
97
+ response = msg.content
98
+ message = ""
99
+ else:
100
+ continue
101
+
102
  with chat_container:
103
+ if message:
104
+ st.markdown(f"""
105
+ <div style='display: flex; justify-content: flex-end; margin: 5px;'>
106
+ <div style='border-radius: 15px; padding: 10px; background-color: #DCF8C6; max-width: 70%;'>
107
+ <b>You:</b> {message}
108
+ </div>
109
  </div>
110
+ """, unsafe_allow_html=True)
111
+
112
+ if response:
113
+ st.markdown(f"""
114
+ <div style='display: flex; justify-content: flex-start; margin: 5px;'>
115
+ <div style='border-radius: 15px; padding: 10px; background-color: #EAEAEA; max-width: 70%;'>
116
+ <b>AI:</b> {response}
117
+ </div>
118
  </div>
119
+ """, unsafe_allow_html=True)
 
120
 
121
  with col2:
122
  # Clear Chat History Option