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()