randmimc commited on
Commit
9f6daea
Β·
verified Β·
1 Parent(s): 236cd6c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +0 -104
src/streamlit_app.py CHANGED
@@ -56,110 +56,6 @@ st.markdown("""
56
  </style>
57
  """, unsafe_allow_html=True)
58
 
59
- def user_message_style(question):
60
- return f"""<div class="chat-container user-container">
61
- <div class="chat-bubble user-bubble">{question}</div>
62
- </div>"""
63
-
64
- def assistant_message_style(assistant_icon_path, answer):
65
- return f"""<div class="chat-container assistant-container">
66
- <img src="{assistant_icon_path}" class="avatar">
67
- <div class="chat-bubble assistant-bubble">{answer}</div>
68
- </div>"""
69
-
70
- for message in st.session_state.messages:
71
- if message["role"] == "user":
72
- st.markdown(user_message_style(message["content"]), unsafe_allow_html=True)
73
- else:
74
- st.markdown(assistant_message_style(assistant_icon_path, message["content"]), unsafe_allow_html=True)
75
-
76
- if not st.session_state.messages:
77
- greeting = '신문기사 μš”μ•½ λͺ¨λΈ μž…λ‹ˆλ‹€. μ‚¬μš©μ„ μœ„ν•΄μ„œλŠ” "yes"λ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš”'
78
- st.session_state.messages.append({"role": "assistant", "content": greeting})
79
- st.markdown(assistant_message_style(assistant_icon_path, greeting), unsafe_allow_html=True)
80
-
81
- if prompt := st.chat_input():
82
- # μ‚¬μš©μž 질문 μ„Έμ…˜μ— μ €μž₯
83
- st.session_state.messages.append({"role": "user", "content": prompt})
84
-
85
- # μ‚¬μš©μž 질문 화면에 ν‘œμ‹œ
86
- st.markdown(user_message_style(prompt), unsafe_allow_html=True)
87
-
88
- # 인증
89
- if st.session_state.approval_state == "require":
90
- if prompt.lower() == "yes":
91
- st.session_state.approval_state = "approved"
92
- response = "이제 μ‚¬μš©μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€. 단, λͺ¨λΈ 크기가 μž‘μ€ λͺ¨λΈμ΄μ—¬μ„œ μ„±λŠ₯이 κΈ°λŒ€μ— λͺ»λ―ΈμΉ  수 μžˆμŠ΅λ‹ˆλ‹€."
93
- else:
94
- response = "인증에 μ‹€νŒ¨ν•˜μ˜€μŠ΅λ‹ˆλ‹€. λ‹€μ‹œ yesλ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš”"
95
- # 응닡 생성
96
- else:
97
- result = re.sub(r'\s+', ' ', prompt)
98
- summarized = pipe(result)
99
- response = summarized[0]["summary_text"]
100
-
101
- # μ–΄μ‹œμŠ€ν„΄μŠ€μ˜ λ©”μ„Έμ§€λ₯Ό μ„Έμ…˜μ— μ €μž₯
102
- st.session_state.messages.append({"role": "assistant", "content": response})
103
- # μ–΄μ‹œμŠ€ν„΄μŠ€μ˜ λ©”μ„Έμ§€λ₯Ό 화면에 ν‘œμ‹œ
104
- st.markdown(assistant_message_style(assistant_icon_path, response), unsafe_allow_html=True)
105
- # νŒ¨ν‚€μ§€ 뢈러였기
106
- import re
107
- import streamlit as st
108
- from transformers import pipeline
109
-
110
- # κΈ€λ‘œλ²Œ λ³€μˆ˜ μ„ μ–Έ
111
- ## λ³Έ μ½”λ“œμ—μ„œ μ‚¬μš©λœ 신문기사 μš”μ•½μš© λͺ¨λΈ(https://huggingface.co/gangyeolkim/kobart-korean-summarizer-v2)은 ν…ŒμŠ€νŠΈμš© μž…λ‹ˆλ‹€.
112
- pipe = pipeline("summarization", model="gangyeolkim/kobart-korean-summarizer-v2")
113
-
114
- ## assitant 아바타 이미지 경둜
115
- assistant_icon_path = "https://huggingface.co/spaces/randmimc/aitom/resolve/main/chat_icon/assistant.ico"
116
-
117
- ## μ„Έμ…˜ μƒνƒœμ—μ„œ approval_state 및 messages μ΄ˆκΈ°ν™”
118
- if "approval_state" not in st.session_state:
119
- st.session_state.approval_state = "require"
120
- if "messages" not in st.session_state:
121
- st.session_state.messages = []
122
-
123
- st.markdown("""
124
- <style>
125
- .chat-container { /* μ±„νŒ… λ©”μ‹œμ§€λ₯Ό κ°μ‹ΈλŠ” μ»¨ν…Œμ΄λ„ˆλ₯Ό μ„€λͺ…ν•©λ‹ˆλ‹€. */
126
- display: flex; /* μ±„νŒ… μš”μ†Œ(아바타, 말풍선 λ“±)을 κ°€λ‘œ λ°©ν–₯으둜 μ •λ ¬ν•©λ‹ˆλ‹€. */
127
- margin-bottom: 10px; /*λ©”μ„Έμ§€κ°„ 간격을 10px둜 ν•©λ‹ˆλ‹€. */
128
- }
129
- .user-container {
130
- justify-content: flex-end; /* μ‚¬μš©μžμ˜ λ©”μ‹œμ§€λ₯Ό μš°μΈ‘μ •λ ¬ν•©λ‹ˆλ‹€.*/
131
- }
132
- .assistant-container {
133
- justify-content: flex-start; /* μ–΄μ‹œμŠ€ν„΄μŠ€ λ©”μ‹œμ§€λ₯Ό 쒌츑 μ •λ ¬ν•©λ‹ˆλ‹€.*/
134
- flex-direction: row; /* Avatar와 Bubble을 μˆ˜ν‰μœΌλ‘œ μ •λ ¬ν•©λ‹ˆλ‹€. */
135
- }
136
- .chat-bubble { /* 말풍선 μŠ€νƒ€μΌμ„ μ •μ˜ν•©λ‹ˆλ‹€. */
137
- padding: 10px; /* 말풍선 μ•ˆμ— λ©”μ‹œμ§€κ°„ 간격을 10px둜 ν•©λ‹ˆλ‹€. */
138
- border-radius: 10px; /*λ§ν’μ„ μ˜ λͺ¨μ„œλ¦¬λ₯Ό λ™κΈ€κ²Œ λ§Œλ“­λ‹ˆλ‹€.*/
139
- max-width: 70%; /* ν•œμ€„μ΄ λ„ˆλ¬΄ κΈΈμ§€ μ•Šκ²Œ μ œν•œν•©λ‹ˆλ‹€. */
140
- word-wrap: break-word; /* ν…μŠ€νŠΈλ₯Ό 단어 λ‹¨μœ„λ‘œ μ€„λ‚΄λ¦Όν•©λ‹ˆλ‹€. */
141
- white-space: pre-wrap; /* ν…μŠ€νŠΈλ₯Ό 단어 λ‹¨μœ„λ‘œ μ€„λ‚΄λ¦Όν•©λ‹ˆλ‹€. */
142
- }
143
- .user-bubble { /* μ‚¬μš©μž λ©”μ‹œμ§€ μŠ€νƒ€μΌμ„ μ •μ˜ν•©λ‹ˆλ‹€. */
144
- font-size: 14px; /* 폰트 μ‚¬μ΄μ¦ˆλ₯Ό μ§€μ •ν•©λ‹ˆλ‹€. */
145
- color: #333; /* 폰트 색상을 μ§€μ •ν•©λ‹ˆλ‹€. */
146
- background-color: #e5e5e5; /* 말풍선 배경색을 μ§€μ •ν•©λ‹ˆλ‹€. */
147
- }
148
- .assistant-bubble {
149
- font-size: 14px; /* 폰트 μ‚¬μ΄μ¦ˆλ₯Ό μ§€μ •ν•©λ‹ˆλ‹€. */
150
- color: #333; /* 폰트 색상을 μ§€μ •ν•©λ‹ˆλ‹€. */
151
- text-align: left; /* λ©”μ„Έμ§€λ₯Ό μ™Όμͺ½ μ •λ ¬ ν•©λ‹ˆλ‹€. */
152
- background-color: #feeddf; /* 말풍선 배경색을 μ§€μ •ν•©λ‹ˆλ‹€. */
153
- }
154
- .avatar { /* ν”„λ‘œν•„ 이미지(아바타) μŠ€νƒ€μΌμ„ μ§€μ •ν•©λ‹ˆλ‹€. */
155
- width: 30px; /* 아바타 폭을 μ§€μ •ν•©λ‹ˆλ‹€. */
156
- height: 30px; /* 아바타 λ„ˆμ„ μ§€μ •ν•©λ‹ˆλ‹€. */
157
- border-radius: 50%; /* 아바타λ₯Ό μ›κ²½μœΌλ‘œ λ§Œλ“­λ‹ˆλ‹€. */
158
- margin-right: 10px; /*λ©”μ„Έμ§€κ°„ 간격을 10px둜 ν•©λ‹ˆλ‹€. */
159
- }
160
- </style>
161
- """, unsafe_allow_html=True)
162
-
163
  def user_message_style(question):
164
  return f"""<div class="chat-container user-container">
165
  <div class="chat-bubble user-bubble">{question}</div>
 
56
  </style>
57
  """, unsafe_allow_html=True)
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  def user_message_style(question):
60
  return f"""<div class="chat-container user-container">
61
  <div class="chat-bubble user-bubble">{question}</div>