JirasakJo commited on
Commit
9beef51
·
verified ·
1 Parent(s): 2f092fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -46
app.py CHANGED
@@ -356,10 +356,6 @@ def main():
356
  with chat_col:
357
  # Display chat history first
358
  for i, (role, content) in enumerate(st.session_state.chat_history):
359
- # Debug print
360
- st.write("Debug - Content type:", type(content))
361
- st.write("Debug - Content:", content)
362
-
363
  if role == "user":
364
  st.markdown(f"""
365
  <div class="chat-message user-message">
@@ -368,49 +364,29 @@ def main():
368
  </div>
369
  """, unsafe_allow_html=True)
370
  else:
371
- # Handle both string and dictionary responses
372
- if isinstance(content, dict):
373
- # Try different possible structures
374
- assistant_response = content.get('answer', content.get('response', ''))
375
- documents = content.get('documents', content.get('refs', content.get('sources', [])))
376
-
377
- st.markdown(f"""
378
- <div class="chat-message assistant-message">
379
- <strong>🤖 คำตอบ:</strong><br>
380
- {assistant_response}
381
- </div>
382
- """, unsafe_allow_html=True)
383
-
384
- # Debug print documents
385
- st.write("Debug - Documents:", documents)
386
-
387
- if documents:
388
- with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=True):
389
- for idx, doc in enumerate(documents, 1):
390
- st.write(f"Debug - Document {idx}:", doc)
391
-
392
- # Try different ways to get document content
393
- if isinstance(doc, dict):
394
- doc_content = doc.get('content', doc.get('text', str(doc)))
395
- else:
396
- doc_content = str(doc)
397
-
398
- st.markdown(f"""
399
- <div style="padding: 1rem; background-color: #F3F4F6; border-radius: 8px; margin: 0.5rem 0; border: 1px solid #E5E7EB;">
400
- <strong>เอกสารที่ {idx}:</strong><br>
401
- {doc_content}
402
- </div>
403
- """, unsafe_allow_html=True)
404
- else:
405
- # If content is a string
406
- st.markdown(f"""
407
- <div class="chat-message assistant-message">
408
- <strong>🤖 คำตอบ:</strong><br>
409
- {content}
410
- </div>
411
- """, unsafe_allow_html=True)
412
 
413
- # Create chat input using the implementation
 
 
 
 
 
 
 
 
 
 
414
  create_chat_input()
415
 
416
  # Sidebar info column
 
356
  with chat_col:
357
  # Display chat history first
358
  for i, (role, content) in enumerate(st.session_state.chat_history):
 
 
 
 
359
  if role == "user":
360
  st.markdown(f"""
361
  <div class="chat-message user-message">
 
364
  </div>
365
  """, unsafe_allow_html=True)
366
  else:
367
+ if isinstance(content, dict):
368
+ assistant_response = content.get('answer', '❌ ไม่มีข้อมูลคำตอบ')
369
+ else:
370
+ assistant_response = content
371
+
372
+ st.markdown(f"""
373
+ <div class="chat-message assistant-message">
374
+ <strong>🤖 คำตอบ:</strong><br>
375
+ {assistant_response}
376
+ </div>
377
+ """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
 
379
+ if isinstance(content, dict) and content.get('documents'):
380
+ with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=False):
381
+ for i, doc in enumerate(content['documents'], 1):
382
+ st.markdown(f"""
383
+ <div style="padding: 1rem; background-color: #000000; border-radius: 8px; margin: 0.5rem 0;">
384
+ <strong>เอกสารที่ {i}:</strong><br>
385
+ {doc.content}
386
+ </div>
387
+ """, unsafe_allow_html=True)
388
+
389
+ # Create chat input using the new implementation
390
  create_chat_input()
391
 
392
  # Sidebar info column