fantaxy commited on
Commit
7d211b2
ยท
verified ยท
1 Parent(s): 18a8957

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -14
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
- current_token = token.strip()
 
 
157
 
158
- if current_token.endswith(('.', '!', '?', '"', '"', ''', ''')):
159
- current_token += '\n'
 
 
 
160
 
161
- if current_token.startswith('"') or current_token.startswith('"'):
162
- current_token = '\n' + current_token
 
163
 
164
- current_response += current_token
165
 
166
- if current_token == '\n':
 
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: