sirochild commited on
Commit
037cd69
·
verified ·
1 Parent(s): 200a4dd

Upload main_app.py

Browse files
Files changed (1) hide show
  1. main_app.py +39 -37
main_app.py CHANGED
@@ -2025,6 +2025,42 @@ Streamlit情報:
2025
  st.session_state.chat['messages'] = [initial_message]
2026
  logger.info("メッセージリストを初期化しました")
2027
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2028
  # メッセージ処理ロジック
2029
  def process_chat_message(message: str):
2030
  response = None
@@ -2359,43 +2395,9 @@ Streamlit情報:
2359
  except Exception as e:
2360
  logger.error(f"ゲームデータ保存でエラーが発生: {e}")
2361
 
2362
- # 応答完了フラグを設定(一度だけ再描画するため)
2363
- st.session_state.response_completed = True
2364
-
2365
- # 応答完了後に強制的にチャット履歴を表示
2366
- logger.info("🎯 応答完了後の強制チャット履歴表示開始")
2367
-
2368
- # 実際の履歴表示処理を実行
2369
- for message in st.session_state.chat['messages']:
2370
- role = message.get("role", "user")
2371
- content = message.get("content", "")
2372
- is_initial = message.get("is_initial", False)
2373
-
2374
- # HTMLタグとStreamlitクラス名を完全に除去
2375
- import re
2376
- clean_content = re.sub(r'<[^>]*>', '', content)
2377
- clean_content = re.sub(r'st-emotion-cache-[a-zA-Z0-9]+', '', clean_content)
2378
- clean_content = re.sub(r'class="[^"]*"', '', clean_content)
2379
- clean_content = re.sub(r'data-[^=]*="[^"]*"', '', clean_content)
2380
- clean_content = re.sub(r'\s+', ' ', clean_content).strip()
2381
-
2382
- with st.chat_message(role):
2383
- if is_initial:
2384
- st.markdown(f"**[初期メッセージ]** {clean_content}")
2385
- else:
2386
- # 隠された真実の処理
2387
- has_hidden_content, visible_content, hidden_content = managers['chat_interface']._detect_hidden_content(clean_content)
2388
- if has_hidden_content and role == "assistant":
2389
- show_all_hidden = st.session_state.get('show_all_hidden', False)
2390
- if show_all_hidden:
2391
- st.markdown(f"**表面:** {visible_content}")
2392
- st.markdown(f"🐕 **本音:** {hidden_content}")
2393
- else:
2394
- st.markdown(visible_content)
2395
- else:
2396
- st.markdown(clean_content)
2397
-
2398
- logger.info("🎯 応答完了後の強制チャット履歴表示完了")
2399
 
2400
  except Exception as e:
2401
  # 応答処理全体でエラーが発生した場合の緊急処理
 
2025
  st.session_state.chat['messages'] = [initial_message]
2026
  logger.info("メッセージリストを初期化しました")
2027
 
2028
+ # チャット履歴を常に表示(応答処理中でない時)
2029
+ if not st.session_state.get('awaiting_response', False):
2030
+ logger.info(f"🎯 通常時のチャット履歴表示: {len(st.session_state.chat['messages'])}件のメッセージ")
2031
+ for message in st.session_state.chat['messages']:
2032
+ role = message.get("role", "user")
2033
+ content = message.get("content", "")
2034
+ is_initial = message.get("is_initial", False)
2035
+
2036
+ # HTMLタグとStreamlitクラス名を完全に除去
2037
+ import re
2038
+ import html
2039
+ clean_content = re.sub(r'<[^>]*>', '', content)
2040
+ clean_content = re.sub(r'st-emotion-cache-[a-zA-Z0-9]+', '', clean_content)
2041
+ clean_content = re.sub(r'class="[^"]*"', '', clean_content)
2042
+ clean_content = re.sub(r'data-[^=]*="[^"]*"', '', clean_content)
2043
+ clean_content = re.sub(r'\s+', ' ', clean_content).strip()
2044
+
2045
+ with st.chat_message(role):
2046
+ if is_initial:
2047
+ st.markdown(f"**[初期メッセージ]** {clean_content}")
2048
+ else:
2049
+ # 隠された真実の処理
2050
+ has_hidden_content, visible_content, hidden_content = managers['chat_interface']._detect_hidden_content(clean_content)
2051
+ if has_hidden_content and role == "assistant":
2052
+ show_all_hidden = st.session_state.get('show_all_hidden', False)
2053
+ if show_all_hidden:
2054
+ st.markdown(f"**表面:** {visible_content}")
2055
+ st.markdown(f"🐕 **本音:** {hidden_content}")
2056
+ else:
2057
+ st.markdown(visible_content)
2058
+ else:
2059
+ st.markdown(clean_content)
2060
+ logger.debug("通常時のチャット履歴表示完了")
2061
+ else:
2062
+ logger.debug("応答処理中のため通常時の履歴表示をスキップ")
2063
+
2064
  # メッセージ処理ロジック
2065
  def process_chat_message(message: str):
2066
  response = None
 
2395
  except Exception as e:
2396
  logger.error(f"ゲームデータ保存でエラーが発生: {e}")
2397
 
2398
+ # 応答完了 - 画面を更新して新しいメッセージを表示
2399
+ logger.info("🎯 応答完了 - 画面更新を実行")
2400
+ st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2401
 
2402
  except Exception as e:
2403
  # 応答処理全体でエラーが発生した場合の緊急処理