Keldos commited on
Commit
8fab39f
1 Parent(s): 0a7115d

改进代码显示样式 (#73)

Browse files

同时增加了customCSS,可以更自由地修改网页样式。

修改代码框和行内代码样式

Files changed (1) hide show
  1. ChuanhuChatbot.py +29 -2
ChuanhuChatbot.py CHANGED
@@ -48,7 +48,7 @@ def parse_text(text):
48
  count += 1
49
  items = line.split('`')
50
  if count % 2 == 1:
51
- lines[i] = f'<pre><code class="{items[-1]}" style="display: block; white-space: pre; background-color: hsl(0, 0%, 32%); border-radius: 8px; padding: 0px 1em 1em; margin-top: 1em; font-size: initial;color: #FFF;">'
52
  firstline = True
53
  else:
54
  lines[i] = f'</code></pre>'
@@ -243,7 +243,34 @@ description = """<div align=center>
243
  此App使用 `gpt-3.5-turbo` 大语言模型
244
  </div>
245
  """
246
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  gr.HTML(title)
248
  keyTxt = gr.Textbox(show_label=True, placeholder=f"在这里输入你的OpenAI API-key...",
249
  value=my_api_key, label="API Key", type="password", visible=not HIDE_MY_KEY).style(container=True)
 
48
  count += 1
49
  items = line.split('`')
50
  if count % 2 == 1:
51
+ lines[i] = f'<pre><code class="{items[-1]}">'
52
  firstline = True
53
  else:
54
  lines[i] = f'</code></pre>'
 
243
  此App使用 `gpt-3.5-turbo` 大语言模型
244
  </div>
245
  """
246
+ customCSS = """
247
+ code {
248
+ display: inline;
249
+ white-space: break-spaces;
250
+ border-radius: 6px;
251
+ margin: 0 2px 0 2px;
252
+ padding: .2em .4em .1em .4em;
253
+ background-color: rgba(175,184,193,0.2);
254
+ }
255
+ pre {
256
+ display: block;
257
+ white-space: pre;
258
+ background-color: hsla(0, 0%, 0%, 72%);
259
+ border: solid 1.2px var(--color-border-primary) !important;
260
+ border-radius: 8px;
261
+ padding: 0 1.2rem 1.2rem;
262
+ margin-top: 1em !important;
263
+ color: #FFF;
264
+ box-shadow: inset 0px 8px 16px hsla(0, 0%, 0%, .2)
265
+ }
266
+ pre code, pre code code {
267
+ background-color: transparent !important;
268
+ margin: 0;
269
+ padding: 0;
270
+ }
271
+ """
272
+
273
+ with gr.Blocks(css=customCSS) as demo:
274
  gr.HTML(title)
275
  keyTxt = gr.Textbox(show_label=True, placeholder=f"在这里输入你的OpenAI API-key...",
276
  value=my_api_key, label="API Key", type="password", visible=not HIDE_MY_KEY).style(container=True)