Keldos commited on
Commit
f42509c
·
1 Parent(s): a6ebff0

feat: 优化dalle3图片显示

Browse files
modules/models/DALLE3.py CHANGED
@@ -35,4 +35,4 @@ class OpenAI_DALLE3_Client(BaseLLMModel):
35
  msg = str(e)
36
  match = re.search(r"'message': '([^']*)'", msg)
37
  return match.group(1), 0
38
- return f'<img src="{response.data[0].url}"> {response.data[0].revised_prompt}', 0
 
35
  msg = str(e)
36
  match = re.search(r"'message': '([^']*)'", msg)
37
  return match.group(1), 0
38
+ return f'<!-- S O PREFIX --><a data-fancybox="gallery" target="_blank" href="{response.data[0].url}"><img src="{response.data[0].url}" /></a><!-- E O PREFIX -->{response.data[0].revised_prompt}', 0
modules/utils.py CHANGED
@@ -243,7 +243,7 @@ def clip_rawtext(chat_message, need_escape=True):
243
  message_clipped = chat_message[: hr_match.start()] if hr_match else chat_message
244
  # second, avoid agent-prefix being escaped
245
  agent_prefix_pattern = (
246
- r'(<!-- S O PREFIX --><p class="agent-prefix">.*?<\/p><!-- E O PREFIX -->)'
247
  )
248
  # agent_matches = re.findall(agent_prefix_pattern, message_clipped)
249
  agent_parts = re.split(agent_prefix_pattern, message_clipped, flags=re.DOTALL)
@@ -257,6 +257,7 @@ def clip_rawtext(chat_message, need_escape=True):
257
  else f'<pre class="fake-pre">{part}</pre>'
258
  )
259
  else:
 
260
  final_message += part
261
  return final_message
262
 
 
243
  message_clipped = chat_message[: hr_match.start()] if hr_match else chat_message
244
  # second, avoid agent-prefix being escaped
245
  agent_prefix_pattern = (
246
+ r'(<!-- S O PREFIX -->.*?<!-- E O PREFIX -->)'
247
  )
248
  # agent_matches = re.findall(agent_prefix_pattern, message_clipped)
249
  agent_parts = re.split(agent_prefix_pattern, message_clipped, flags=re.DOTALL)
 
257
  else f'<pre class="fake-pre">{part}</pre>'
258
  )
259
  else:
260
+ part = part.replace(' data-fancybox="gallery"', '')
261
  final_message += part
262
  return final_message
263
 
modules/webui.py CHANGED
@@ -55,6 +55,7 @@ def reload_javascript():
55
  js = javascript_html()
56
  js += '<script async type="module" src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>'
57
  js += '<script async type="module" src="http://spin.js.org/spin.umd.js"></script><link type="text/css" href="https://spin.js.org/spin.css" rel="stylesheet" />'
 
58
 
59
  meta = """
60
  <meta name="apple-mobile-web-app-title" content="川虎 Chat">
 
55
  js = javascript_html()
56
  js += '<script async type="module" src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>'
57
  js += '<script async type="module" src="http://spin.js.org/spin.umd.js"></script><link type="text/css" href="https://spin.js.org/spin.css" rel="stylesheet" />'
58
+ js += '<script async src="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/fancybox/fancybox.umd.js"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/fancybox/fancybox.css" />'
59
 
60
  meta = """
61
  <meta name="apple-mobile-web-app-title" content="川虎 Chat">
web_assets/javascript/ChuanhuChat.js CHANGED
@@ -349,6 +349,7 @@ function chatbotContentChanged(attempt = 1, force = false) {
349
  disableSendBtn();
350
  updateSlider();
351
  updateCheckboxes();
 
352
 
353
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
354
 
 
349
  disableSendBtn();
350
  updateSlider();
351
  updateCheckboxes();
352
+ bindFancyBox();
353
 
354
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
355
 
web_assets/javascript/utils.js CHANGED
@@ -71,6 +71,16 @@ function downloadFile(fileUrl, filename = "", format = "", retryTimeout = 200, m
71
  }
72
 
73
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  /* NOTE: These reload functions are not used in the current version of the code.
76
  * From stable-diffusion-webui
 
71
  }
72
 
73
 
74
+ function bindFancyBox() {
75
+ Fancybox.bind('[data-fancybox]', {
76
+ Carousel: {
77
+ Panzoom: {
78
+ decelFriction: 0.5
79
+ }
80
+ }
81
+ });
82
+ }
83
+
84
 
85
  /* NOTE: These reload functions are not used in the current version of the code.
86
  * From stable-diffusion-webui
web_assets/stylesheet/chatbot.css CHANGED
@@ -243,6 +243,14 @@ hr.append-display {
243
  border-radius: 8px !important;
244
  margin: 4px !important
245
  }
 
 
 
 
 
 
 
 
246
 
247
  /* custom buttons */
248
  .chuanhu-btn {
 
243
  border-radius: 8px !important;
244
  margin: 4px !important
245
  }
246
+ .message.bot img {
247
+ border-radius: 8px !important;
248
+ width: 512px;
249
+ max-height: unset !important;
250
+ max-width: 100% !important;
251
+ margin: unset !important;
252
+ margin-bottom: .8em !important;
253
+ }
254
 
255
  /* custom buttons */
256
  .chuanhu-btn {