Update app.py
Browse files
app.py
CHANGED
|
@@ -46,15 +46,25 @@ start_new_chat_session()
|
|
| 46 |
def respond(user_input, history):
|
| 47 |
global chat_session
|
| 48 |
history.append((user_input, ""))
|
| 49 |
-
yield "", history
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
def clear_chat():
|
|
|
|
| 46 |
def respond(user_input, history):
|
| 47 |
global chat_session
|
| 48 |
history.append((user_input, ""))
|
| 49 |
+
yield "", history # 초기 빈 텍스트 출력
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
response = chat_session.send_message(user_input)
|
| 53 |
+
full_text = ""
|
| 54 |
+
for chunk in response.text.split("."): # 마침표를 기준으로 문장 분리
|
| 55 |
+
chunk = chunk.strip() + ". " # 문장 끝에 마침표와 공백 추가
|
| 56 |
+
|
| 57 |
+
# 숫자 또는 * 로 시작하는 경우 줄 바꿈 추가
|
| 58 |
+
if re.match(r"^\d+\.", chunk) or chunk.startswith("* "):
|
| 59 |
+
full_text += "\n" + chunk
|
| 60 |
+
else:
|
| 61 |
+
full_text += chunk
|
| 62 |
+
|
| 63 |
+
history[-1] = (user_input, full_text)
|
| 64 |
+
yield "", history
|
| 65 |
+
time.sleep(0.05)
|
| 66 |
+
except Exception as e:
|
| 67 |
+
yield f"에러 발생: {str(e)}"
|
| 68 |
|
| 69 |
|
| 70 |
def clear_chat():
|