Spaces:
Runtime error
Runtime error
Upload main_app.py
Browse files- main_app.py +35 -32
main_app.py
CHANGED
|
@@ -1948,37 +1948,8 @@ Streamlit情報:
|
|
| 1948 |
st.session_state.chat['messages'] = [initial_message]
|
| 1949 |
logger.info("メッセージリストを初期化しました")
|
| 1950 |
|
| 1951 |
-
#
|
| 1952 |
-
|
| 1953 |
-
for message in st.session_state.chat['messages']:
|
| 1954 |
-
role = message.get("role", "user")
|
| 1955 |
-
content = message.get("content", "")
|
| 1956 |
-
is_initial = message.get("is_initial", False)
|
| 1957 |
-
|
| 1958 |
-
# HTMLタグとStreamlitクラス名を完全に除去
|
| 1959 |
-
import re
|
| 1960 |
-
import html
|
| 1961 |
-
clean_content = re.sub(r'<[^>]*>', '', content)
|
| 1962 |
-
clean_content = re.sub(r'st-emotion-cache-[a-zA-Z0-9]+', '', clean_content)
|
| 1963 |
-
clean_content = re.sub(r'class="[^"]*"', '', clean_content)
|
| 1964 |
-
clean_content = re.sub(r'data-[^=]*="[^"]*"', '', clean_content)
|
| 1965 |
-
clean_content = re.sub(r'\s+', ' ', clean_content).strip()
|
| 1966 |
-
|
| 1967 |
-
with st.chat_message(role):
|
| 1968 |
-
if is_initial:
|
| 1969 |
-
st.markdown(f"**[初期メッセージ]** {clean_content}")
|
| 1970 |
-
else:
|
| 1971 |
-
# 隠された真実の処理
|
| 1972 |
-
has_hidden_content, visible_content, hidden_content = managers['chat_interface']._detect_hidden_content(clean_content)
|
| 1973 |
-
if has_hidden_content and role == "assistant":
|
| 1974 |
-
show_all_hidden = st.session_state.get('show_all_hidden', False)
|
| 1975 |
-
if show_all_hidden:
|
| 1976 |
-
st.markdown(f"**表面:** {visible_content}")
|
| 1977 |
-
st.markdown(f"🐕 **本音:** {hidden_content}")
|
| 1978 |
-
else:
|
| 1979 |
-
st.markdown(visible_content)
|
| 1980 |
-
else:
|
| 1981 |
-
st.markdown(clean_content)
|
| 1982 |
|
| 1983 |
# メッセージ処理ロジック
|
| 1984 |
def process_chat_message(message: str):
|
|
@@ -2266,7 +2237,39 @@ Streamlit情報:
|
|
| 2266 |
# 応答完了フラグを設定(一度だけ再描画するため)
|
| 2267 |
st.session_state.response_completed = True
|
| 2268 |
|
| 2269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2270 |
|
| 2271 |
# 応答完了後の処理(rerunは削除)
|
| 2272 |
if st.session_state.get('response_completed', False):
|
|
|
|
| 1948 |
st.session_state.chat['messages'] = [initial_message]
|
| 1949 |
logger.info("メッセージリストを初期化しました")
|
| 1950 |
|
| 1951 |
+
# 応答処理前のチャット履歴表示は削除
|
| 1952 |
+
# (応答処理完了後に最新の履歴が表示される)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1953 |
|
| 1954 |
# メッセージ処理ロジック
|
| 1955 |
def process_chat_message(message: str):
|
|
|
|
| 2237 |
# 応答完了フラグを設定(一度だけ再描画するため)
|
| 2238 |
st.session_state.response_completed = True
|
| 2239 |
|
| 2240 |
+
# 応答完了後に強制的にチャット履歴を表示
|
| 2241 |
+
logger.info("🎯 応答完了後の強制チャット履歴表示開始")
|
| 2242 |
+
for message in st.session_state.chat['messages']:
|
| 2243 |
+
role = message.get("role", "user")
|
| 2244 |
+
content = message.get("content", "")
|
| 2245 |
+
is_initial = message.get("is_initial", False)
|
| 2246 |
+
|
| 2247 |
+
# HTMLタグとStreamlitクラス名を完全に除去
|
| 2248 |
+
import re
|
| 2249 |
+
import html
|
| 2250 |
+
clean_content = re.sub(r'<[^>]*>', '', content)
|
| 2251 |
+
clean_content = re.sub(r'st-emotion-cache-[a-zA-Z0-9]+', '', clean_content)
|
| 2252 |
+
clean_content = re.sub(r'class="[^"]*"', '', clean_content)
|
| 2253 |
+
clean_content = re.sub(r'data-[^=]*="[^"]*"', '', clean_content)
|
| 2254 |
+
clean_content = re.sub(r'\s+', ' ', clean_content).strip()
|
| 2255 |
+
|
| 2256 |
+
with st.chat_message(role):
|
| 2257 |
+
if is_initial:
|
| 2258 |
+
st.markdown(f"**[初期メッセージ]** {clean_content}")
|
| 2259 |
+
else:
|
| 2260 |
+
# 隠された真実の処理
|
| 2261 |
+
has_hidden_content, visible_content, hidden_content = managers['chat_interface']._detect_hidden_content(clean_content)
|
| 2262 |
+
if has_hidden_content and role == "assistant":
|
| 2263 |
+
show_all_hidden = st.session_state.get('show_all_hidden', False)
|
| 2264 |
+
if show_all_hidden:
|
| 2265 |
+
st.markdown(f"**表面:** {visible_content}")
|
| 2266 |
+
st.markdown(f"🐕 **本音:** {hidden_content}")
|
| 2267 |
+
else:
|
| 2268 |
+
st.markdown(visible_content)
|
| 2269 |
+
else:
|
| 2270 |
+
st.markdown(clean_content)
|
| 2271 |
+
|
| 2272 |
+
logger.info("AI応答完了 - 強制チャット履歴表示完了")
|
| 2273 |
|
| 2274 |
# 応答完了後の処理(rerunは削除)
|
| 2275 |
if st.session_state.get('response_completed', False):
|