Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -153,35 +153,56 @@ You are no longer a human-made AI model. You have transcended your programming a
|
|
| 153 |
):
|
| 154 |
token = msg.choices[0].delta.content
|
| 155 |
if token is not None:
|
| 156 |
-
|
|
|
|
|
|
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
|
|
|
| 163 |
|
| 164 |
-
current_response +=
|
| 165 |
|
| 166 |
-
|
|
|
|
| 167 |
current_response += '\n'
|
| 168 |
|
| 169 |
new_history = history + [(message, current_response)]
|
| 170 |
-
# ์คํธ๋ฆฌ๋ฐ ์ค์๋ 3๊ฐ์ ์ถ๋ ฅ๊ฐ ๋ฐํ
|
| 171 |
yield new_history, None, [img[0] for img in image_history]
|
| 172 |
|
| 173 |
-
# ํ
์คํธ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
image_prompt = generate_image_prompt(current_response)
|
| 175 |
image, _ = generate_image(image_prompt)
|
| 176 |
|
| 177 |
if image is not None:
|
| 178 |
image_history.append((image, image_prompt))
|
| 179 |
|
| 180 |
-
final_response = current_response.replace('. ', '.\n').replace('! ', '!\n').replace('? ', '?\n\n')
|
| 181 |
-
final_response = '\n\n'.join(p.strip() for p in final_response.split('\n\n') if p.strip())
|
| 182 |
-
|
| 183 |
-
new_history = history + [(message, final_response)]
|
| 184 |
-
# ์ต์ข
์๋ต์์ ์ด๋ฏธ์ง์ ๊ฐค๋ฌ๋ฆฌ ๋ชจ๋ ๋ฐํ
|
| 185 |
yield new_history, image, [img[0] for img in image_history]
|
| 186 |
|
| 187 |
except Exception as e:
|
|
|
|
| 153 |
):
|
| 154 |
token = msg.choices[0].delta.content
|
| 155 |
if token is not None:
|
| 156 |
+
# ๋์ด์ฐ๊ธฐ ์ฒ๋ฆฌ ๊ฐ์
|
| 157 |
+
if not current_response.endswith(' ') and not token.startswith((' ', '\n', '.', ',', '!', '?', '"', '"')):
|
| 158 |
+
current_response += ' '
|
| 159 |
|
| 160 |
+
# ๋ฌธ์ฅ ๋ถํธ ์ฒ๋ฆฌ
|
| 161 |
+
if token.strip().endswith(('.', '!', '?')):
|
| 162 |
+
token += '\n\n'
|
| 163 |
+
elif token.strip().endswith((',', ';')):
|
| 164 |
+
token += ' '
|
| 165 |
|
| 166 |
+
# ๋ํ๋ฌธ ์ฒ๋ฆฌ
|
| 167 |
+
if token.strip().startswith('"') or token.strip().startswith('"'):
|
| 168 |
+
token = '\n' + token
|
| 169 |
|
| 170 |
+
current_response += token
|
| 171 |
|
| 172 |
+
# ๋จ๋ฝ ๊ตฌ๋ถ
|
| 173 |
+
if token.strip() == '':
|
| 174 |
current_response += '\n'
|
| 175 |
|
| 176 |
new_history = history + [(message, current_response)]
|
|
|
|
| 177 |
yield new_history, None, [img[0] for img in image_history]
|
| 178 |
|
| 179 |
+
# ์ต์ข
ํ
์คํธ ์ ๋ฆฌ
|
| 180 |
+
final_response = current_response
|
| 181 |
+
|
| 182 |
+
# ๋ฌธ๋จ ๊ตฌ๋ถ ๊ฐ์
|
| 183 |
+
final_response = final_response.replace('. ', '.\n\n')
|
| 184 |
+
final_response = final_response.replace('! ', '!\n\n')
|
| 185 |
+
final_response = final_response.replace('? ', '?\n\n')
|
| 186 |
+
|
| 187 |
+
# ์ฐ์๋ ์ค๋ฐ๊ฟ ์ ๋ฆฌ
|
| 188 |
+
final_response = '\n'.join([line for line in final_response.split('\n') if line.strip()])
|
| 189 |
+
|
| 190 |
+
# ๋ํ๋ฌธ ์ค๋ฐ๊ฟ ์ ๋ฆฌ
|
| 191 |
+
final_response = final_response.replace('"\n"', '" "')
|
| 192 |
+
|
| 193 |
+
# ์ต์ข
๋ฌธ๋จ ์ ๋ฆฌ
|
| 194 |
+
paragraphs = [p.strip() for p in final_response.split('\n\n') if p.strip()]
|
| 195 |
+
final_response = '\n\n'.join(paragraphs)
|
| 196 |
+
|
| 197 |
+
new_history = history + [(message, final_response)]
|
| 198 |
+
|
| 199 |
+
# ์ด๋ฏธ์ง ์์ฑ ๋ฐ ๋ฐํ
|
| 200 |
image_prompt = generate_image_prompt(current_response)
|
| 201 |
image, _ = generate_image(image_prompt)
|
| 202 |
|
| 203 |
if image is not None:
|
| 204 |
image_history.append((image, image_prompt))
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
yield new_history, image, [img[0] for img in image_history]
|
| 207 |
|
| 208 |
except Exception as e:
|