Spaces:
Sleeping
Sleeping
Update chat_a.py
Browse files
chat_a.py
CHANGED
|
@@ -10,18 +10,6 @@ from huggingface_hub import hf_hub_download
|
|
| 10 |
from sentence_transformers import SentenceTransformer, util
|
| 11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 12 |
from css import log_and_render
|
| 13 |
-
|
| 14 |
-
from css import log_and_render
|
| 15 |
-
import time # time λΌμ΄λΈλ¬λ¦¬λ₯Ό import ν©λλ€.
|
| 16 |
-
|
| 17 |
-
def stream_text_generator(text_to_stream: str):
|
| 18 |
-
"""
|
| 19 |
-
λ¬Έμμ΄μ λ¨μ΄ λ¨μλ‘ μͺΌκ°μ νλμ© νλ €λ³΄λ΄μ£Όλ μμ±κΈ°(generator) ν¨μ.
|
| 20 |
-
νμ΄ν ν¨κ³Όλ₯Ό μν΄ μ¬μ©λ©λλ€.
|
| 21 |
-
"""
|
| 22 |
-
for word in text_to_stream.split(" "):
|
| 23 |
-
yield word + " "
|
| 24 |
-
time.sleep(0.05) # κ° λ¨μ΄ μ¬μ΄μ 0.05μ΄μ λλ μ΄λ₯Ό μ€λλ€.
|
| 25 |
|
| 26 |
# ββββββββββββββββββββββββββββββββ μΊμ/λ°μ΄ν°μ
μ€μ ββββββββββββββββββββββββββββββββ
|
| 27 |
HOME = pathlib.Path.home()
|
|
@@ -1352,31 +1340,15 @@ def recommend_packages(
|
|
| 1352 |
)
|
| 1353 |
|
| 1354 |
# β
μΆλ ₯
|
| 1355 |
-
# if recommend_texts:
|
| 1356 |
-
# full_message = "π§³ μ΄λ° ν¨ν€μ§λ₯Ό μΆμ²λλ €μ:<br><br>" + "<br><br>".join(recommend_texts)
|
| 1357 |
-
# log_and_render(
|
| 1358 |
-
# full_message,
|
| 1359 |
-
# sender="bot",
|
| 1360 |
-
# chat_container = chat_container,
|
| 1361 |
-
# key="recommend_package_intro",
|
| 1362 |
-
# )
|
| 1363 |
if recommend_texts:
|
| 1364 |
-
|
| 1365 |
-
|
| 1366 |
-
|
| 1367 |
-
|
| 1368 |
-
|
| 1369 |
-
|
| 1370 |
-
|
| 1371 |
-
|
| 1372 |
-
# 2. ν¨ν€μ§ λͺ©λ‘μ νμ΄ν μμ΄ λ°λ‘ 보μ¬μ£Όλ κ²μ΄ λ κΉλν©λλ€.
|
| 1373 |
-
st.markdown(package_list_message) # st.markdownμ μ¬μ©ν΄ λ°λ‘ μΆλ ₯
|
| 1374 |
-
|
| 1375 |
-
# 3. λν κΈ°λ‘μλ μ 체 λ©μμ§λ₯Ό ν©μ³μ μ μ₯ν©λλ€.
|
| 1376 |
-
full_message = intro_message + package_list_message
|
| 1377 |
-
if "chat_log" not in st.session_state:
|
| 1378 |
-
st.session_state.chat_log = []
|
| 1379 |
-
st.session_state.chat_log.append(("bot", full_message))
|
| 1380 |
else:
|
| 1381 |
log_and_render(
|
| 1382 |
"β οΈ μΆμ² κ°λ₯ν ν¨ν€μ§κ° μμ΅λλ€.",
|
|
@@ -1407,20 +1379,6 @@ def handle_selected_place(selected_place, travel_df, external_score_df, festival
|
|
| 1407 |
message_lines.append(f"ν¨κ» κ°λ³΄λ©΄ μ’μ μ¬νμ§: {sample_names}")
|
| 1408 |
else:
|
| 1409 |
message_lines.append("β οΈ ν¨κ» κ°λ³Ό λ€λ₯Έ μ¬νμ§κ° μμ΄μ.")
|
| 1410 |
-
|
| 1411 |
-
##
|
| 1412 |
-
full_message = "".join(message_lines)
|
| 1413 |
-
|
| 1414 |
-
# Streamlitμ chat_message 컨ν
μ€νΈλ₯Ό μ¬μ©ν΄ λ§νμ μ μ§μ λ§λλλ€.
|
| 1415 |
-
with st.chat_message("assistant"): # 'assistant'λ λ΄ λ©μμ§λ₯Ό μλ―Έν©λλ€.
|
| 1416 |
-
# μ°λ¦¬κ° λ§λ μ λλ μ΄ν°μ st.write_streamμ μ°κ²°ν΄ νμ΄ν ν¨κ³Όλ₯Ό λ
λλ€.
|
| 1417 |
-
st.write_stream(stream_text_generator(full_message))
|
| 1418 |
-
|
| 1419 |
-
# λν κΈ°λ‘(log)μ λ¨κΈ°λ λ‘μ§μ νλ©΄ μΆλ ₯ λ€μ λ°λ‘ μ€νν©λλ€.
|
| 1420 |
-
if "chat_log" not in st.session_state:
|
| 1421 |
-
st.session_state.chat_log = []
|
| 1422 |
-
st.session_state.chat_log.append(("bot", full_message))
|
| 1423 |
-
##
|
| 1424 |
|
| 1425 |
# integrated_theme μΆλ‘ μΆκ°
|
| 1426 |
if selected_theme is None:
|
|
|
|
| 10 |
from sentence_transformers import SentenceTransformer, util
|
| 11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 12 |
from css import log_and_render
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# ββββββββββββββββββββββββββββββββ μΊμ/λ°μ΄ν°μ
μ€μ ββββββββββββββββββββββββββββββββ
|
| 15 |
HOME = pathlib.Path.home()
|
|
|
|
| 1340 |
)
|
| 1341 |
|
| 1342 |
# β
μΆλ ₯
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1343 |
if recommend_texts:
|
| 1344 |
+
full_message = "π§³ μ΄λ° ν¨ν€μ§λ₯Ό μΆμ²λλ €μ:<br><br>" + "<br><br>".join(recommend_texts)
|
| 1345 |
+
log_and_render(
|
| 1346 |
+
full_message,
|
| 1347 |
+
sender="bot",
|
| 1348 |
+
chat_container = chat_container,
|
| 1349 |
+
key="recommend_package_intro",
|
| 1350 |
+
)
|
| 1351 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1352 |
else:
|
| 1353 |
log_and_render(
|
| 1354 |
"β οΈ μΆμ² κ°λ₯ν ν¨ν€μ§κ° μμ΅λλ€.",
|
|
|
|
| 1379 |
message_lines.append(f"ν¨κ» κ°λ³΄λ©΄ μ’μ μ¬νμ§: {sample_names}")
|
| 1380 |
else:
|
| 1381 |
message_lines.append("β οΈ ν¨κ» κ°λ³Ό λ€λ₯Έ μ¬νμ§κ° μμ΄μ.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1382 |
|
| 1383 |
# integrated_theme μΆλ‘ μΆκ°
|
| 1384 |
if selected_theme is None:
|