cryogenic22 commited on
Commit
c5d3be7
·
verified ·
1 Parent(s): 2b4e9ce

Update components/chat.py

Browse files
Files changed (1) hide show
  1. components/chat.py +75 -18
components/chat.py CHANGED
@@ -5,51 +5,108 @@ from utils.database import verify_vector_store
5
 
6
 
7
  def display_chat_interface():
8
- """Display chat interface component"""
9
- st.markdown("### 💬 RFP Analysis Chat")
10
 
11
- # Initialize chat history if not exists
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  if 'messages' not in st.session_state:
13
  st.session_state.messages = []
14
 
15
  # Display chat history
16
  for message in st.session_state.messages:
17
  if isinstance(message, HumanMessage):
18
- st.markdown(f"🧑‍💼 **You**: {message.content}")
 
 
 
 
19
  elif isinstance(message, AIMessage):
20
- st.markdown(f"🤖 **Assistant**: {message.content}")
 
 
 
 
 
 
 
 
 
 
21
 
22
- # Chat input
23
- if prompt := st.chat_input("Ask about the RFPs..."):
24
  try:
25
- with st.spinner("Analyzing documents..."):
26
  # Create message objects
27
  human_message = HumanMessage(content=prompt)
28
-
29
- # Add to chat history
30
  st.session_state.messages.append(human_message)
31
 
32
- # Get response from QA system
33
  response = st.session_state.qa_system.invoke({
34
  "input": prompt,
35
  "chat_history": st.session_state.messages
36
  })
37
 
38
  if response:
39
- # Create AI message
40
  ai_message = AIMessage(content=str(response))
41
-
42
- # Add to chat history
43
  st.session_state.messages.append(ai_message)
44
-
45
- # Force refresh to show new messages
46
  st.rerun()
47
  else:
48
  st.error("No valid response received")
49
-
50
  except Exception as e:
51
  st.error(f"Error: {e}")
52
- st.error(f"Error type: {type(e)}")
53
  import traceback
54
  st.error(traceback.format_exc())
55
 
 
5
 
6
 
7
  def display_chat_interface():
8
+ """Display modern chat interface with clean formatting."""
 
9
 
10
+ # Add custom CSS for modern chat styling
11
+ st.markdown("""
12
+ <style>
13
+ /* Clean, modern chat container */
14
+ .chat-container {
15
+ max-width: 800px;
16
+ margin: auto;
17
+ }
18
+
19
+ /* Message styling */
20
+ .user-message {
21
+ background-color: #f0f2f6;
22
+ padding: 1rem;
23
+ border-radius: 10px;
24
+ margin: 1rem 0;
25
+ }
26
+
27
+ .assistant-message {
28
+ background-color: #ffffff;
29
+ border: 1px solid #e0e0e0;
30
+ padding: 1.5rem;
31
+ border-radius: 10px;
32
+ margin: 1rem 0;
33
+ }
34
+
35
+ /* Section styling */
36
+ .section-header {
37
+ font-weight: bold;
38
+ color: #0f52ba;
39
+ margin-top: 1rem;
40
+ }
41
+
42
+ .source-info {
43
+ background-color: #f8f9fa;
44
+ padding: 0.5rem;
45
+ border-left: 3px solid #0f52ba;
46
+ margin-top: 1rem;
47
+ font-size: 0.9rem;
48
+ }
49
+
50
+ /* Headers and content */
51
+ .content-section {
52
+ margin: 0.5rem 0;
53
+ }
54
+
55
+ /* Clean bullets */
56
+ .clean-bullet {
57
+ margin: 0.3rem 0;
58
+ }
59
+ </style>
60
+ """, unsafe_allow_html=True)
61
+
62
+ # Initialize chat history
63
  if 'messages' not in st.session_state:
64
  st.session_state.messages = []
65
 
66
  # Display chat history
67
  for message in st.session_state.messages:
68
  if isinstance(message, HumanMessage):
69
+ st.markdown(f"""
70
+ <div class="user-message">
71
+ 🧑‍💼 <strong>You:</strong><br>{message.content}
72
+ </div>
73
+ """, unsafe_allow_html=True)
74
  elif isinstance(message, AIMessage):
75
+ # Clean and structure the response
76
+ response_content = message.content
77
+ if hasattr(message, 'additional_kwargs'):
78
+ response_content = response_content.replace('additional_kwargs={}', '').replace('response_metadata={}', '')
79
+
80
+ st.markdown(f"""
81
+ <div class="assistant-message">
82
+ 🤖 <strong>Assistant:</strong><br>
83
+ {response_content}
84
+ </div>
85
+ """, unsafe_allow_html=True)
86
 
87
+ # Chat input at the bottom
88
+ if prompt := st.chat_input("Ask about your documents..."):
89
  try:
90
+ with st.spinner("Analyzing..."):
91
  # Create message objects
92
  human_message = HumanMessage(content=prompt)
 
 
93
  st.session_state.messages.append(human_message)
94
 
95
+ # Get response
96
  response = st.session_state.qa_system.invoke({
97
  "input": prompt,
98
  "chat_history": st.session_state.messages
99
  })
100
 
101
  if response:
 
102
  ai_message = AIMessage(content=str(response))
 
 
103
  st.session_state.messages.append(ai_message)
 
 
104
  st.rerun()
105
  else:
106
  st.error("No valid response received")
107
+
108
  except Exception as e:
109
  st.error(f"Error: {e}")
 
110
  import traceback
111
  st.error(traceback.format_exc())
112