Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -174,6 +174,7 @@ h1::after { content: " ☎"; }
|
|
| 174 |
margin-top: 10px !important;
|
| 175 |
background: transparent !important;
|
| 176 |
border: none !important;
|
|
|
|
| 177 |
}
|
| 178 |
|
| 179 |
/* 입력창 디자인 */
|
|
@@ -252,7 +253,7 @@ footer { display: none !important; }
|
|
| 252 |
# 5. App 실행 (Blocks로 레이아웃 직접 구성)
|
| 253 |
# ------------------------------------------------------------------
|
| 254 |
with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as demo:
|
| 255 |
-
gr.Markdown("
|
| 256 |
gr.Markdown(">> 01410 접속 성공... [대화실]에 입장하셨습니다.")
|
| 257 |
|
| 258 |
# ChatInterface 대신 Blocks로 수동 구성하여 레이아웃 제어
|
|
@@ -263,7 +264,7 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
|
|
| 263 |
)
|
| 264 |
|
| 265 |
# 입력창과 전송 버튼을 나란히
|
| 266 |
-
with gr.Row():
|
| 267 |
msg = gr.Textbox(
|
| 268 |
scale=8,
|
| 269 |
show_label=False,
|
|
@@ -291,9 +292,15 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
|
|
| 291 |
|
| 292 |
# 이벤트 연결
|
| 293 |
def user(user_message, history):
|
|
|
|
|
|
|
| 294 |
return "", history + [[user_message, None]]
|
| 295 |
|
| 296 |
def bot(history):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
user_message = history[-1][0]
|
| 298 |
# 이전 대화 기록 포맷팅
|
| 299 |
chat_history = []
|
|
@@ -304,13 +311,17 @@ with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as d
|
|
| 304 |
history[-1][1] = bot_message
|
| 305 |
return history
|
| 306 |
|
|
|
|
| 307 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 308 |
bot, chatbot, chatbot
|
| 309 |
)
|
|
|
|
| 310 |
submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 311 |
bot, chatbot, chatbot
|
| 312 |
)
|
|
|
|
| 313 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 314 |
|
| 315 |
if __name__ == "__main__":
|
| 316 |
-
|
|
|
|
|
|
| 174 |
margin-top: 10px !important;
|
| 175 |
background: transparent !important;
|
| 176 |
border: none !important;
|
| 177 |
+
gap: 10px !important; /* 입력창과 전송버튼 사이 간격 */
|
| 178 |
}
|
| 179 |
|
| 180 |
/* 입력창 디자인 */
|
|
|
|
| 253 |
# 5. App 실행 (Blocks로 레이아웃 직접 구성)
|
| 254 |
# ------------------------------------------------------------------
|
| 255 |
with gr.Blocks(theme=gr.themes.Base(), css=PC_COM_CSS, title="CHOLLIAN 98") as demo:
|
| 256 |
+
gr.Markdown("19금 채팅방")
|
| 257 |
gr.Markdown(">> 01410 접속 성공... [대화실]에 입장하셨습니다.")
|
| 258 |
|
| 259 |
# ChatInterface 대신 Blocks로 수동 구성하여 레이아웃 제어
|
|
|
|
| 264 |
)
|
| 265 |
|
| 266 |
# 입력창과 전송 버튼을 나란히
|
| 267 |
+
with gr.Row(elem_classes="input-container"):
|
| 268 |
msg = gr.Textbox(
|
| 269 |
scale=8,
|
| 270 |
show_label=False,
|
|
|
|
| 292 |
|
| 293 |
# 이벤트 연결
|
| 294 |
def user(user_message, history):
|
| 295 |
+
# history가 None일 경우 빈 리스트로 초기화 (에러 방지)
|
| 296 |
+
history = history or []
|
| 297 |
return "", history + [[user_message, None]]
|
| 298 |
|
| 299 |
def bot(history):
|
| 300 |
+
# history가 비어있거나 None일 경우 방어 로직
|
| 301 |
+
if not history:
|
| 302 |
+
return history
|
| 303 |
+
|
| 304 |
user_message = history[-1][0]
|
| 305 |
# 이전 대화 기록 포맷팅
|
| 306 |
chat_history = []
|
|
|
|
| 311 |
history[-1][1] = bot_message
|
| 312 |
return history
|
| 313 |
|
| 314 |
+
# 엔터키 입력 시
|
| 315 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 316 |
bot, chatbot, chatbot
|
| 317 |
)
|
| 318 |
+
# 전송 버튼 클릭 시
|
| 319 |
submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 320 |
bot, chatbot, chatbot
|
| 321 |
)
|
| 322 |
+
# 지우기 버튼
|
| 323 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 324 |
|
| 325 |
if __name__ == "__main__":
|
| 326 |
+
# queue()를 활성화하여 요청 대기열 처리 (No API 에러 방지)
|
| 327 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860)
|