Spaces:
Runtime error
Runtime error
File size: 3,836 Bytes
44dcc41 b84a171 2a62aac 474110c b84a171 474110c 44dcc41 1db7faa ad08b7c 44dcc41 ad08b7c 55218eb 24ac80b 55218eb ad08b7c 55218eb ad08b7c 24ac80b 55218eb ad08b7c 55218eb 0e32995 55218eb d3de65a 24ac80b 55218eb 1fe047d 55218eb 24ac80b 55218eb 24ac80b 55218eb 44dcc41 56f5bf5 55218eb 56f5bf5 55218eb ad08b7c 55218eb 44dcc41 2c891dd 1fe047d 2c891dd 60ebd55 2c891dd 2a62aac 55218eb 44dcc41 b84a171 44dcc41 56f5bf5 44dcc41 60ebd55 44dcc41 60ebd55 b84a171 44dcc41 2a62aac 2c891dd 44dcc41 9afdec5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | import streamlit as st
from transformers import pipeline
import re
def replace_multiple_spaces(text):
return re.sub(r'\s+', ' ', text)
pipe = pipeline("summarization", model="gangyeolkim/kobart-korean-summarizer-v2")
assistant_icon_path = "https://huggingface.co/spaces/randmimc/aitom/resolve/main/chat_icon/assistant.ico"
user_icon_path = "https://huggingface.co/spaces/randmimc/aitom/resolve/main/chat_icon/user01.png"
# ์ธ์
์ํ์์ approval_state ๋ฐ messages ์ด๊ธฐํ
if "approval_state" not in st.session_state:
st.session_state.approval_state = "require"
if "messages" not in st.session_state:
st.session_state.messages = []
# Custom CSS to align messages and wrap text
st.markdown("""
<style>
.chat-container {
display: flex;
align-items: flex-start;
margin-bottom: 10px;
}
.user-container {
justify-content: flex-end;
}
.assistant-container {
justify-content: flex-start;
flex-direction: row; /* Avatar์ Bubble์ ์ํ ์ ๋ ฌ */
}
.chat-bubble {
padding: 10px;
border-radius: 10px;
max-width: 70%;
word-wrap: break-word;
white-space: pre-wrap;
}
.user-bubble {
background-color: #e5e5e5;
text-align: left;
}
.assistant-bubble {
font-size: 14px;
text-align: left; /* ์ผ์ชฝ ์ ๋ ฌ */
background-color: #f8d7da;
}
.avatar {
width: 30px;
height: 30px;
border-radius: 50%;
margin-right: 10px; /* Bubble๊ณผ ๊ฐ๊ฒฉ */
}
</style>
""", unsafe_allow_html=True)
# Display chat messages from history
for message in st.session_state.messages:
if message["role"] == "user":
st.markdown(
f"""
<div class="chat-container user-container">
<div class="chat-bubble user-bubble">{message["content"]}</div>
</div>
""", unsafe_allow_html=True)
else:
st.markdown(
f"""
<div class="chat-container assistant-container">
<img src="{assistant_icon_path}" class="avatar">
<div class="chat-bubble assistant-bubble">{message["content"]}</div>
</div>
""", unsafe_allow_html=True)
# Start with an assistant message
if not st.session_state.messages:
st.session_state.messages.append({
"role": "assistant",
"avatar": assistant_icon_path,
"content": """๋์์ด์ ์จ์ aitom์ ํ์ฌ ๊ณต์ฌ์ค์ ์์ต๋๋ค.
ํ์ง๋ง ! ๊ฐ๋จํ ํ์ฉํด ๋ณด์ค ์ ์๋ ์์ฝ ๋ชจ๋ธ์ ์ ๊ณตํ๊ณ ์์ต๋๋ค.
์งง์ ์ ๋ฌธ๊ธฐ์ฌ๋ฅผ ๋งํด ์ฃผ์๋ฉด ์์ฝ๋ฌธ์ ์ ๊ณตํฉ๋๋ค.
๊ณ์ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด "yes" ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.
"""})
st.rerun()
if prompt := st.chat_input():
st.session_state.messages.append({"role": "user", "avatar": user_icon_path, "content": prompt})
if st.session_state.approval_state == "require":
if prompt.lower() == "yes":
st.session_state.approval_state = "approved"
st.session_state.messages.append({"role": "assistant", "avatar": assistant_icon_path, "content": "์ด์ ๊ฐ๋จํ ์์ฝ ๋ชจ๋ธ์ ์ฌ์ฉํ์ค ์ ์์ต๋๋ค. ๊ฐ๋จํ ์ ๋ฌธ๊ธฐ์ฌ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์."})
else:
st.session_state.messages.append({"role": "assistant", "avatar": assistant_icon_path, "content": '์น์ธํ์ง ๋ชปํ์์ต๋๋ค. ์น์ธ์ ์ํด "yes"๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.'})
elif st.session_state.approval_state == "approved":
result = replace_multiple_spaces(prompt)
summarized = pipe(result)
st.session_state.messages.append({"role": "assistant", "avatar": assistant_icon_path, "content": summarized[0]["summary_text"]})
st.rerun()
|