Jay1121 commited on
Commit
d0d918d
·
verified ·
1 Parent(s): e0fcf5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -92
app.py CHANGED
@@ -78,7 +78,7 @@ def chat_response(user_input, history_pairs):
78
  return r["choices"][0]["message"]["content"].strip()
79
 
80
  # ------------------------------------------------------------------
81
- # 4. CSS ( 감성 그대로 + 요청 사항 반영)
82
  # ------------------------------------------------------------------
83
  PC_COM_CSS = r"""
84
  @import url('https://cdn.jsdelivr.net/gh/neodgm/neodgm-webfont@latest/neodgm/neodgm.css');
@@ -87,7 +87,7 @@ PC_COM_CSS = r"""
87
  --pc-blue: #0000AA;
88
  --pc-white: #EFEFEF;
89
  --pc-yellow: #FFFF55;
90
- --pc-amber: #FFB000; /* 봇 메시지용 호박색 */
91
  --pc-cyan: #00AAAA;
92
  --pc-grey: #AAAAAA;
93
  }
@@ -98,6 +98,7 @@ body, .gradio-container {
98
  color: var(--pc-white) !important;
99
  }
100
 
 
101
  h1 {
102
  font-family: 'NeoDunggeunmo', monospace !important;
103
  color: var(--pc-yellow) !important;
@@ -109,77 +110,124 @@ h1 {
109
  font-size: 32px !important;
110
  letter-spacing: 2px;
111
  }
112
-
113
  h1::before { content: "☎ "; }
114
  h1::after { content: " ☎"; }
115
 
116
- .gradio-container p {
117
- color: var(--pc-cyan) !important;
118
- font-size: 18px !important;
119
- border-bottom: 1px dashed var(--pc-grey);
120
- padding-bottom: 5px;
121
- }
122
-
123
  .chatbot {
124
  background-color: var(--pc-blue) !important;
125
  border: 2px solid var(--pc-white) !important;
126
- border-radius: 0 !important;
127
  height: 60vh !important;
128
  overflow-y: scroll !important;
129
  }
130
 
131
- .message {
 
 
 
 
 
 
 
 
132
  background: transparent !important;
133
  border: none !important;
134
- padding: 5px 10px !important;
135
- font-size: 20px !important;
136
  box-shadow: none !important;
137
- line-height: 1.4 !important;
138
  }
139
 
140
- /* [수정] 유저 메시지: 우측 정렬 + 흰색 */
141
- .message.user-row, .user {
142
- justify-content: flex-end !important; /* 우측 정렬 */
143
- background: transparent !important;
144
- border-bottom: none !important; /* 선 제거 */
 
145
  }
146
 
147
- .message.user-row .message, .user .message {
148
- color: var(--pc-white) !important;
149
- text-align: right !important;
 
 
 
150
  }
151
 
152
- /* 유저 접두사 ("< 나") 뒤로 보내기 */
153
- .message.user-row .message::after, .user .message::after {
154
- content: " < 나";
155
- color: var(--pc-grey);
156
- margin-left: 5px;
157
  }
158
- /* 기존 접두사 제거 */
159
- .message.user-row .message::before, .user .message::before {
160
- content: "" !important;
 
 
 
 
161
  }
162
 
 
 
 
 
 
 
 
163
 
164
- /* [수정] 메시지: 좌측 정렬 + 호박색(가시성) */
165
- .message.bot-row, .bot {
166
- background: transparent !important;
167
- border-bottom: none !important; /* 선 제거 */
 
 
168
  }
169
 
170
- .message.bot-row .message, .bot .message {
171
- color: var(--pc-amber) !important; /* 호박색 적용 */
172
- text-align: left !important;
 
 
173
  }
174
 
175
- .message.bot-row .message::before, .bot .message::before {
176
- content: "똘배 > ";
177
- color: var(--pc-cyan);
178
- margin-right: 5px;
 
 
179
  }
180
 
 
181
  .avatar { display: none !important; }
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  .input-container {
184
  background-color: var(--pc-blue) !important;
185
  border-top: 2px double var(--pc-white) !important;
@@ -219,7 +267,6 @@ button.primary:hover { background: var(--pc-white) !important; }
219
  }
220
  #clear-btn:hover { color: var(--pc-white) !important; border-color: var(--pc-white) !important; }
221
 
222
- /* 수동 예시 버튼 스타일 */
223
  .example-btn {
224
  background: transparent !important;
225
  color: var(--pc-cyan) !important;
@@ -237,49 +284,16 @@ button.primary:hover { background: var(--pc-white) !important; }
237
  cursor: pointer !important;
238
  }
239
 
240
- /* [수정] 초시계(로딩) 스타일 커스텀 */
241
- /* 하얀 바탕 제거, 글씨만 남기기 */
242
- .generating {
243
- border: none !important;
244
- background: transparent !important;
245
- }
246
-
247
- .pending {
248
- opacity: 1 !important;
249
- background: transparent !important;
250
- }
251
-
252
- /* 로딩 텍스트 (초시계) */
253
- span.progress-text {
254
- color: var(--pc-white) !important; /* 파란 배경이라 흰색으로 해야 보임 */
255
- background: transparent !important;
256
- font-family: 'NeoDunggeunmo', monospace !important;
257
- font-size: 16px !important;
258
- position: absolute !important;
259
- right: 10px !important;
260
- top: 10px !important;
261
- }
262
-
263
- /* 로딩 바(애니메이션) 숨기기 - 심플하게 */
264
- .meta-text-container {
265
- background: transparent !important;
266
- border: none !important;
267
- }
268
- .load-wrap {
269
- display: none !important;
270
- }
271
-
272
  footer { display: none !important; }
273
  """
274
 
275
  # ------------------------------------------------------------------
276
- # 5. App (최종 수정: State 사용 + API 생성 차단 + 즉시 반응 패치)
277
  # ------------------------------------------------------------------
278
  with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as demo:
279
  gr.Markdown("# ≪ 십 리 안 ≫")
280
  gr.Markdown(">> 01410 접속 성공... [대화실]에 입장하셨습니다.")
281
 
282
- # [중요] 채팅 기록을 저장할 '기억 저장소' (화면엔 안 보임)
283
  history_state = gr.State([])
284
 
285
  chatbot = gr.Chatbot(show_label=False, elem_classes="chatbot")
@@ -293,7 +307,6 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
293
 
294
  clear = gr.Button("[ 화면 지우기 ]", elem_id="clear-btn")
295
 
296
- # 수동 예시 버튼
297
  gr.Markdown(">> 빠른 명령어 입력 (클릭)", elem_id="example-label")
298
  with gr.Row():
299
  btn1 = gr.Button("하이 방가방가", elem_classes="example-btn")
@@ -301,35 +314,24 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
301
  btn3 = gr.Button("오늘 기분 꿀꿀하네..", elem_classes="example-btn")
302
  btn4 = gr.Button("야 밥 뭐먹지 추천좀", elem_classes="example-btn")
303
 
304
- # [수정 1] 사용자 입력을 화면에 '즉시' 띄우는 함수
305
  def user(user_input, history):
306
  history = history or []
307
- # 봇 응답 자리에 None을 채워서 일단 화면에 표시 (즉시 반응)
308
  new_history = history + [[user_input, None]]
309
  return "", new_history, new_history
310
 
311
- # [수정 2] 봇의 응답을 생성해서 업데이트하는 함수
312
  def bot(history):
313
  if not history:
314
  return history, history
315
-
316
  user_input = history[-1][0]
317
-
318
- # LLM에 보낼 히스토리 정리
319
  hist_pairs = []
320
  for u, b in history[:-1]:
321
  if u is None or b is None: continue
322
  hist_pairs.append((u, b))
323
 
324
- # 답변 생성 (시간이 좀 걸림)
325
  bot_out = chat_response(user_input, hist_pairs)
326
-
327
- # 마지막 None 자리에 답변 채워넣기
328
  history[-1][1] = bot_out
329
  return history, history
330
 
331
- # [수정 3] 이벤트 연결 (user 실행 -> bot 실행 순서로 체이닝)
332
- # 이렇게 해야 엔터 치자마자 내 글이 먼저 뜨고, 똘배가 고민하는 게 보임
333
  msg.submit(
334
  user, [msg, history_state], [msg, history_state, chatbot], queue=False, api_name=False
335
  ).then(
@@ -342,19 +344,17 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
342
  bot, [history_state], [history_state, chatbot], queue=False, api_name=False
343
  )
344
 
345
- # 초기화
346
  clear.click(
347
  lambda: ([], []), None, [history_state, chatbot], queue=False, api_name=False
348
  )
349
 
350
- # 예시 버튼 연결 (버튼 클릭 -> 텍스트 입력 -> 유저 함수 -> 봇 함수)
351
  for btn, text in [
352
  (btn1, "하이 방가방가"),
353
  (btn2, "밸런스게임 ㄱㄱ"),
354
  (btn3, "오늘 기분 꿀꿀하네.."),
355
  (btn4, "야 밥 뭐먹지 추천좀")
356
  ]:
357
- btn.click(lambda: text, None, msg, queue=False, api_name=False).then(
358
  user, [msg, history_state], [msg, history_state, chatbot], queue=False, api_name=False
359
  ).then(
360
  bot, [history_state], [history_state, chatbot], queue=False, api_name=False
 
78
  return r["choices"][0]["message"]["content"].strip()
79
 
80
  # ------------------------------------------------------------------
81
+ # 4. CSS (강력한 선택자로 재작성)
82
  # ------------------------------------------------------------------
83
  PC_COM_CSS = r"""
84
  @import url('https://cdn.jsdelivr.net/gh/neodgm/neodgm-webfont@latest/neodgm/neodgm.css');
 
87
  --pc-blue: #0000AA;
88
  --pc-white: #EFEFEF;
89
  --pc-yellow: #FFFF55;
90
+ --pc-amber: #FFB000;
91
  --pc-cyan: #00AAAA;
92
  --pc-grey: #AAAAAA;
93
  }
 
98
  color: var(--pc-white) !important;
99
  }
100
 
101
+ /* 타이틀바 */
102
  h1 {
103
  font-family: 'NeoDunggeunmo', monospace !important;
104
  color: var(--pc-yellow) !important;
 
110
  font-size: 32px !important;
111
  letter-spacing: 2px;
112
  }
 
113
  h1::before { content: "☎ "; }
114
  h1::after { content: " ☎"; }
115
 
116
+ /* 챗봇 컨테이너 */
 
 
 
 
 
 
117
  .chatbot {
118
  background-color: var(--pc-blue) !important;
119
  border: 2px solid var(--pc-white) !important;
 
120
  height: 60vh !important;
121
  overflow-y: scroll !important;
122
  }
123
 
124
+ /* =================================================================
125
+ [강제 스타일 적용 구간]
126
+ Gradio 기본 테마를 뚫고 들어가기 위해 선택자를 깊게 씀
127
+ ================================================================= */
128
+
129
+ /* 1. 모든 메시지 박스 초기화 (배경, 테두리, 그림자 제거) */
130
+ .chatbot .message-wrap .message,
131
+ .chatbot .message,
132
+ .chatbot td {
133
  background: transparent !important;
134
  border: none !important;
 
 
135
  box-shadow: none !important;
136
+ padding: 5px 10px !important;
137
  }
138
 
139
+ /* 2. 유저 메시지 (오른쪽 정렬 + 흰색) */
140
+ .chatbot .user-row {
141
+ display: flex !important;
142
+ justify-content: flex-end !important; /* 플렉스 우측 정렬 */
143
+ width: 100% !important;
144
+ border-bottom: none !important; /* 가로선 제거 */
145
  }
146
 
147
+ /* 유저 말풍선 내부 */
148
+ .chatbot .user-row .message {
149
+ background: transparent !important;
150
+ text-align: right !important;
151
+ margin-left: auto !important; /* 블록 우측 정렬 */
152
+ border: none !important;
153
  }
154
 
155
+ /* 유저 텍스트 색상 강제 (흰색) */
156
+ .chatbot .user-row .message,
157
+ .chatbot .user-row .message *,
158
+ .chatbot .user-row .message p {
159
+ color: #FFFFFF !important;
160
  }
161
+
162
+ /* 유저 접두사 처리 */
163
+ .chatbot .user-row .message::after {
164
+ content: " < 나";
165
+ color: var(--pc-grey);
166
+ margin-left: 5px;
167
+ font-size: 16px;
168
  }
169
 
170
+ /* 3. 봇 메시지 (왼쪽 정렬 + 호박색) */
171
+ .chatbot .bot-row {
172
+ display: flex !important;
173
+ justify-content: flex-start !important;
174
+ width: 100% !important;
175
+ border-bottom: none !important; /* 가로선 제거 */
176
+ }
177
 
178
+ /* 봇 말풍선 내부 */
179
+ .chatbot .bot-row .message {
180
+ background: transparent !important;
181
+ text-align: left !important;
182
+ margin-right: auto !important;
183
+ border: none !important;
184
  }
185
 
186
+ /* 텍스트 색상 강제 (호박색) */
187
+ .chatbot .bot-row .message,
188
+ .chatbot .bot-row .message *,
189
+ .chatbot .bot-row .message p {
190
+ color: var(--pc-amber) !important;
191
  }
192
 
193
+ /* 접두사 처리 */
194
+ .chatbot .bot-row .message::before {
195
+ content: "똘배 > ";
196
+ color: var(--pc-cyan);
197
+ margin-right: 5px;
198
+ font-size: 16px;
199
  }
200
 
201
+ /* 4. 아바타 숨김 */
202
  .avatar { display: none !important; }
203
 
204
+
205
+ /* 5. 로딩(초시계) 스타일 수정 */
206
+ /* 로딩 컨테이너 배경 날리기 */
207
+ .chatbot .pending,
208
+ .chatbot .generating {
209
+ background: transparent !important;
210
+ border: none !important;
211
+ box-shadow: none !important;
212
+ }
213
+
214
+ /* 로딩 텍스트(초) 하얗게 */
215
+ .chatbot .pending span,
216
+ .chatbot .generating span,
217
+ span.progress-text {
218
+ color: #FFFFFF !important;
219
+ background: transparent !important;
220
+ font-family: 'NeoDunggeunmo', monospace !important;
221
+ }
222
+
223
+ /* 로딩 애니메이션 바 숨기기 */
224
+ .chatbot .load-wrap,
225
+ .chatbot .loading-indicator {
226
+ display: none !important;
227
+ }
228
+
229
+ /* ================================================================= */
230
+
231
  .input-container {
232
  background-color: var(--pc-blue) !important;
233
  border-top: 2px double var(--pc-white) !important;
 
267
  }
268
  #clear-btn:hover { color: var(--pc-white) !important; border-color: var(--pc-white) !important; }
269
 
 
270
  .example-btn {
271
  background: transparent !important;
272
  color: var(--pc-cyan) !important;
 
284
  cursor: pointer !important;
285
  }
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  footer { display: none !important; }
288
  """
289
 
290
  # ------------------------------------------------------------------
291
+ # 5. App (로직 동일)
292
  # ------------------------------------------------------------------
293
  with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as demo:
294
  gr.Markdown("# ≪ 십 리 안 ≫")
295
  gr.Markdown(">> 01410 접속 성공... [대화실]에 입장하셨습니다.")
296
 
 
297
  history_state = gr.State([])
298
 
299
  chatbot = gr.Chatbot(show_label=False, elem_classes="chatbot")
 
307
 
308
  clear = gr.Button("[ 화면 지우기 ]", elem_id="clear-btn")
309
 
 
310
  gr.Markdown(">> 빠른 명령어 입력 (클릭)", elem_id="example-label")
311
  with gr.Row():
312
  btn1 = gr.Button("하이 방가방가", elem_classes="example-btn")
 
314
  btn3 = gr.Button("오늘 기분 꿀꿀하네..", elem_classes="example-btn")
315
  btn4 = gr.Button("야 밥 뭐먹지 추천좀", elem_classes="example-btn")
316
 
 
317
  def user(user_input, history):
318
  history = history or []
 
319
  new_history = history + [[user_input, None]]
320
  return "", new_history, new_history
321
 
 
322
  def bot(history):
323
  if not history:
324
  return history, history
 
325
  user_input = history[-1][0]
 
 
326
  hist_pairs = []
327
  for u, b in history[:-1]:
328
  if u is None or b is None: continue
329
  hist_pairs.append((u, b))
330
 
 
331
  bot_out = chat_response(user_input, hist_pairs)
 
 
332
  history[-1][1] = bot_out
333
  return history, history
334
 
 
 
335
  msg.submit(
336
  user, [msg, history_state], [msg, history_state, chatbot], queue=False, api_name=False
337
  ).then(
 
344
  bot, [history_state], [history_state, chatbot], queue=False, api_name=False
345
  )
346
 
 
347
  clear.click(
348
  lambda: ([], []), None, [history_state, chatbot], queue=False, api_name=False
349
  )
350
 
 
351
  for btn, text in [
352
  (btn1, "하이 방가방가"),
353
  (btn2, "밸런스게임 ㄱㄱ"),
354
  (btn3, "오늘 기분 꿀꿀하네.."),
355
  (btn4, "야 밥 뭐먹지 추천좀")
356
  ]:
357
+ btn.click(lambda t=text: t, None, msg, queue=False, api_name=False).then(
358
  user, [msg, history_state], [msg, history_state, chatbot], queue=False, api_name=False
359
  ).then(
360
  bot, [history_state], [history_state, chatbot], queue=False, api_name=False