Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -207,12 +207,16 @@ footer { display: none !important; }
|
|
| 207 |
"""
|
| 208 |
|
| 209 |
# ------------------------------------------------------------------
|
| 210 |
-
# 5. App (
|
| 211 |
# ------------------------------------------------------------------
|
| 212 |
with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as demo:
|
| 213 |
-
gr.Markdown("# ≪
|
| 214 |
gr.Markdown(">> 01410 접속 성공... [대화실]에 입장하셨습니다.")
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
chatbot = gr.Chatbot(show_label=False, elem_classes="chatbot")
|
| 217 |
|
| 218 |
with gr.Row(elem_classes="input-container"):
|
|
@@ -224,9 +228,7 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
|
|
| 224 |
|
| 225 |
clear = gr.Button("[ 화면 지우기 ]", elem_id="clear-btn")
|
| 226 |
|
| 227 |
-
#
|
| 228 |
-
# [수정] gr.Examples 대신 수동 버튼 사용 (버그 회피)
|
| 229 |
-
# ------------------------------------------------------
|
| 230 |
gr.Markdown(">> 빠른 명령어 입력 (클릭)", elem_id="example-label")
|
| 231 |
with gr.Row():
|
| 232 |
btn1 = gr.Button("하이 방가방가", elem_classes="example-btn")
|
|
@@ -234,6 +236,7 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
|
|
| 234 |
btn3 = gr.Button("오늘 기분 꿀꿀하네..", elem_classes="example-btn")
|
| 235 |
btn4 = gr.Button("야 밥 뭐먹지 추천좀", elem_classes="example-btn")
|
| 236 |
|
|
|
|
| 237 |
def predict(user_input, history):
|
| 238 |
history = history or []
|
| 239 |
hist_pairs = []
|
|
@@ -243,25 +246,53 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
|
|
| 243 |
hist_pairs.append((u, b))
|
| 244 |
|
| 245 |
bot_out = chat_response(user_input, hist_pairs)
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
|
| 254 |
-
# 예시 버튼
|
| 255 |
for btn, text in [
|
| 256 |
(btn1, "하이 방가방가"),
|
| 257 |
(btn2, "밸런스게임 ㄱㄱ"),
|
| 258 |
(btn3, "오늘 기분 꿀꿀하네.."),
|
| 259 |
(btn4, "야 밥 뭐먹지 추천좀")
|
| 260 |
]:
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
)
|
| 264 |
|
| 265 |
if __name__ == "__main__":
|
| 266 |
-
# queue() 메서드 삭제 및 HTTP 모드 실행
|
| 267 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 207 |
"""
|
| 208 |
|
| 209 |
# ------------------------------------------------------------------
|
| 210 |
+
# 5. App (최종 수정: State 사용 + API 생성 차단)
|
| 211 |
# ------------------------------------------------------------------
|
| 212 |
with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as demo:
|
| 213 |
+
gr.Markdown("# ≪ 하 이 루 ≫")
|
| 214 |
gr.Markdown(">> 01410 접속 성공... [대화실]에 입장하셨습니다.")
|
| 215 |
|
| 216 |
+
# [중요] 채팅 기록을 저장할 '기억 저장소' (화면엔 안 보임)
|
| 217 |
+
# Chatbot 컴포넌트를 직접 입력으로 쓰지 않기 위해 사용
|
| 218 |
+
history_state = gr.State([])
|
| 219 |
+
|
| 220 |
chatbot = gr.Chatbot(show_label=False, elem_classes="chatbot")
|
| 221 |
|
| 222 |
with gr.Row(elem_classes="input-container"):
|
|
|
|
| 228 |
|
| 229 |
clear = gr.Button("[ 화면 지우기 ]", elem_id="clear-btn")
|
| 230 |
|
| 231 |
+
# 수동 예시 버튼
|
|
|
|
|
|
|
| 232 |
gr.Markdown(">> 빠른 명령어 입력 (클릭)", elem_id="example-label")
|
| 233 |
with gr.Row():
|
| 234 |
btn1 = gr.Button("하이 방가방가", elem_classes="example-btn")
|
|
|
|
| 236 |
btn3 = gr.Button("오늘 기분 꿀꿀하네..", elem_classes="example-btn")
|
| 237 |
btn4 = gr.Button("야 밥 뭐먹지 추천좀", elem_classes="example-btn")
|
| 238 |
|
| 239 |
+
# [핵심 수정] 채팅창(chatbot)을 입력으로 쓰지 않고, state를 입력으로 사용
|
| 240 |
def predict(user_input, history):
|
| 241 |
history = history or []
|
| 242 |
hist_pairs = []
|
|
|
|
| 246 |
hist_pairs.append((u, b))
|
| 247 |
|
| 248 |
bot_out = chat_response(user_input, hist_pairs)
|
| 249 |
+
|
| 250 |
+
# 새 히스토리
|
| 251 |
+
new_history = list(history) + [[user_input, bot_out]]
|
| 252 |
+
|
| 253 |
+
# 리턴: 입력창 비우기, State 업데이트, Chatbot 업데이트
|
| 254 |
+
return "", new_history, new_history
|
| 255 |
+
|
| 256 |
+
# [핵심 수정] api_name=False로 설정하여 스키마 생성 에러 원천 차단
|
| 257 |
+
msg.submit(
|
| 258 |
+
predict,
|
| 259 |
+
[msg, history_state],
|
| 260 |
+
[msg, history_state, chatbot],
|
| 261 |
+
queue=False,
|
| 262 |
+
api_name=False
|
| 263 |
+
)
|
| 264 |
+
submit_btn.click(
|
| 265 |
+
predict,
|
| 266 |
+
[msg, history_state],
|
| 267 |
+
[msg, history_state, chatbot],
|
| 268 |
+
queue=False,
|
| 269 |
+
api_name=False
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
# 초기화: State와 Chatbot 둘 다 비움
|
| 273 |
+
clear.click(
|
| 274 |
+
lambda: ([], []),
|
| 275 |
+
None,
|
| 276 |
+
[history_state, chatbot],
|
| 277 |
+
queue=False,
|
| 278 |
+
api_name=False
|
| 279 |
+
)
|
| 280 |
|
| 281 |
+
# 예시 버튼 연결
|
| 282 |
for btn, text in [
|
| 283 |
(btn1, "하이 방가방가"),
|
| 284 |
(btn2, "밸런스게임 ㄱㄱ"),
|
| 285 |
(btn3, "오늘 기분 꿀꿀하네.."),
|
| 286 |
(btn4, "야 밥 뭐먹지 추천좀")
|
| 287 |
]:
|
| 288 |
+
# 버튼 클릭 시 텍스트 박스에 채우고 -> 바로 전송
|
| 289 |
+
btn.click(lambda: text, None, msg, queue=False, api_name=False).then(
|
| 290 |
+
predict,
|
| 291 |
+
[msg, history_state],
|
| 292 |
+
[msg, history_state, chatbot],
|
| 293 |
+
queue=False,
|
| 294 |
+
api_name=False
|
| 295 |
)
|
| 296 |
|
| 297 |
if __name__ == "__main__":
|
|
|
|
| 298 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|