CoolFace
Apppublic

suchun/chatGPT_acdemic

sourceHugging Faceupdated 3y agoView on Hugging Face
4likes
theme.py232 linesDownload Raw Back to root
1import gradio as gr2from toolbox import get_conf3CODE_HIGHLIGHT, = get_conf('CODE_HIGHLIGHT')4# gradio可用颜色列表5# gr.themes.utils.colors.slate (石板色)6# gr.themes.utils.colors.gray (灰色)7# gr.themes.utils.colors.zinc (锌色)8# gr.themes.utils.colors.neutral (中性色)9# gr.themes.utils.colors.stone (石头色)10# gr.themes.utils.colors.red (红色)11# gr.themes.utils.colors.orange (橙色)12# gr.themes.utils.colors.amber (琥珀色)13# gr.themes.utils.colors.yellow (黄色)14# gr.themes.utils.colors.lime (酸橙色)15# gr.themes.utils.colors.green (绿色)16# gr.themes.utils.colors.emerald (祖母绿)17# gr.themes.utils.colors.teal (青蓝色)18# gr.themes.utils.colors.cyan (青色)19# gr.themes.utils.colors.sky (天蓝色)20# gr.themes.utils.colors.blue (蓝色)21# gr.themes.utils.colors.indigo (靛蓝色)22# gr.themes.utils.colors.violet (紫罗兰色)23# gr.themes.utils.colors.purple (紫色)24# gr.themes.utils.colors.fuchsia (洋红色)25# gr.themes.utils.colors.pink (粉红色)26# gr.themes.utils.colors.rose (玫瑰色)27 28 29def adjust_theme():30    try:31        color_er = gr.themes.utils.colors.fuchsia32        set_theme = gr.themes.Default(33            primary_hue=gr.themes.utils.colors.orange,34            neutral_hue=gr.themes.utils.colors.gray,35            font=["sans-serif", "Microsoft YaHei", "ui-sans-serif", "system-ui",36                  "sans-serif", gr.themes.utils.fonts.GoogleFont("Source Sans Pro")],37            font_mono=["ui-monospace", "Consolas", "monospace", gr.themes.utils.fonts.GoogleFont("IBM Plex Mono")])38        set_theme.set(39            # Colors40            input_background_fill_dark="*neutral_800",41            # Transition42            button_transition="none",43            # Shadows44            button_shadow="*shadow_drop",45            button_shadow_hover="*shadow_drop_lg",46            button_shadow_active="*shadow_inset",47            input_shadow="0 0 0 *shadow_spread transparent, *shadow_inset",48            input_shadow_focus="0 0 0 *shadow_spread *secondary_50, *shadow_inset",49            input_shadow_focus_dark="0 0 0 *shadow_spread *neutral_700, *shadow_inset",50            checkbox_label_shadow="*shadow_drop",51            block_shadow="*shadow_drop",52            form_gap_width="1px",53            # Button borders54            input_border_width="1px",55            input_background_fill="white",56            # Gradients57            stat_background_fill="linear-gradient(to right, *primary_400, *primary_200)",58            stat_background_fill_dark="linear-gradient(to right, *primary_400, *primary_600)",59            error_background_fill=f"linear-gradient(to right, {color_er.c100}, *background_fill_secondary)",60            error_background_fill_dark="*background_fill_primary",61            checkbox_label_background_fill="linear-gradient(to top, *neutral_50, white)",62            checkbox_label_background_fill_dark="linear-gradient(to top, *neutral_900, *neutral_800)",63            checkbox_label_background_fill_hover="linear-gradient(to top, *neutral_100, white)",64            checkbox_label_background_fill_hover_dark="linear-gradient(to top, *neutral_900, *neutral_800)",65            button_primary_background_fill="linear-gradient(to bottom right, *primary_100, *primary_300)",66            button_primary_background_fill_dark="linear-gradient(to bottom right, *primary_500, *primary_600)",67            button_primary_background_fill_hover="linear-gradient(to bottom right, *primary_100, *primary_200)",68            button_primary_background_fill_hover_dark="linear-gradient(to bottom right, *primary_500, *primary_500)",69            button_primary_border_color_dark="*primary_500",70            button_secondary_background_fill="linear-gradient(to bottom right, *neutral_100, *neutral_200)",71            button_secondary_background_fill_dark="linear-gradient(to bottom right, *neutral_600, *neutral_700)",72            button_secondary_background_fill_hover="linear-gradient(to bottom right, *neutral_100, *neutral_100)",73            button_secondary_background_fill_hover_dark="linear-gradient(to bottom right, *neutral_600, *neutral_600)",74            button_cancel_background_fill=f"linear-gradient(to bottom right, {color_er.c100}, {color_er.c200})",75            button_cancel_background_fill_dark=f"linear-gradient(to bottom right, {color_er.c600}, {color_er.c700})",76            button_cancel_background_fill_hover=f"linear-gradient(to bottom right, {color_er.c100}, {color_er.c100})",77            button_cancel_background_fill_hover_dark=f"linear-gradient(to bottom right, {color_er.c600}, {color_er.c600})",78            button_cancel_border_color=color_er.c200,79            button_cancel_border_color_dark=color_er.c600,80            button_cancel_text_color=color_er.c600,81            button_cancel_text_color_dark="white",82        )83    except:84        set_theme = None85        print('gradio版本较旧, 不能自定义字体和颜色')86    return set_theme87 88 89advanced_css = """90/* 设置表格的外边距为1em,内部单元格之间边框合并,空单元格显示. */91.markdown-body table {92    margin: 1em 0;93    border-collapse: collapse;94    empty-cells: show;95}96 97/* 设置表格单元格的内边距为5px,边框粗细为1.2px,颜色为--border-color-primary. */98.markdown-body th, .markdown-body td {99    border: 1.2px solid var(--border-color-primary);100    padding: 5px;101}102 103/* 设置表头背景颜色为rgba(175,184,193,0.2),透明度为0.2. */104.markdown-body thead {105    background-color: rgba(175,184,193,0.2);106}107 108/* 设置表头单元格的内边距为0.5em和0.2em. */109.markdown-body thead th {110    padding: .5em .2em;111}112 113/* 去掉列表前缀的默认间距,使其与文本线对齐. */114.markdown-body ol, .markdown-body ul {115    padding-inline-start: 2em !important;116}117 118/* 设定聊天气泡的样式,包括圆角、最大宽度和阴影等. */119[class *= "message"] {120    border-radius: var(--radius-xl) !important;121    /* padding: var(--spacing-xl) !important; */122    /* font-size: var(--text-md) !important; */123    /* line-height: var(--line-md) !important; */124    /* min-height: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl)); */125    /* min-width: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl)); */126}127[data-testid = "bot"] {128    max-width: 95%;129    /* width: auto !important; */130    border-bottom-left-radius: 0 !important;131}132[data-testid = "user"] {133    max-width: 100%;134    /* width: auto !important; */135    border-bottom-right-radius: 0 !important;136}137 138/* 行内代码的背景设为淡灰色,设定圆角和间距. */139.markdown-body code {140    display: inline;141    white-space: break-spaces;142    border-radius: 6px;143    margin: 0 2px 0 2px;144    padding: .2em .4em .1em .4em;145    background-color: rgba(175,184,193,0.2);146}147/* 设定代码块的样式,包括背景颜色、内、外边距、圆角。 */148.markdown-body pre code {149    display: block;150    overflow: auto;151    white-space: pre;152    background-color: rgba(175,184,193,0.2);153    border-radius: 10px;154    padding: 1em;155    margin: 1em 2em 1em 0.5em;156}157 158"""159 160if CODE_HIGHLIGHT:161    advanced_css += """162 163.hll { background-color: #ffffcc }164.c { color: #3D7B7B; font-style: italic } /* Comment */165.err { border: 1px solid #FF0000 } /* Error */166.k { color: hsl(197, 94%, 51%); font-weight: bold } /* Keyword */167.o { color: #666666 } /* Operator */168.ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */169.cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */170.cp { color: #9C6500 } /* Comment.Preproc */171.cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */172.c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */173.cs { color: #3D7B7B; font-style: italic } /* Comment.Special */174.gd { color: #A00000 } /* Generic.Deleted */175.ge { font-style: italic } /* Generic.Emph */176.gr { color: #E40000 } /* Generic.Error */177.gh { color: #000080; font-weight: bold } /* Generic.Heading */178.gi { color: #008400 } /* Generic.Inserted */179.go { color: #717171 } /* Generic.Output */180.gp { color: #000080; font-weight: bold } /* Generic.Prompt */181.gs { font-weight: bold } /* Generic.Strong */182.gu { color: #800080; font-weight: bold } /* Generic.Subheading */183.gt { color: #a9dd00 } /* Generic.Traceback */184.kc { color: #008000; font-weight: bold } /* Keyword.Constant */185.kd { color: #008000; font-weight: bold } /* Keyword.Declaration */186.kn { color: #008000; font-weight: bold } /* Keyword.Namespace */187.kp { color: #008000 } /* Keyword.Pseudo */188.kr { color: #008000; font-weight: bold } /* Keyword.Reserved */189.kt { color: #B00040 } /* Keyword.Type */190.m { color: #666666 } /* Literal.Number */191.s { color: #BA2121 } /* Literal.String */192.na { color: #687822 } /* Name.Attribute */193.nb { color: #e5f8c3 } /* Name.Builtin */194.nc { color: #ffad65; font-weight: bold } /* Name.Class */195.no { color: #880000 } /* Name.Constant */196.nd { color: #AA22FF } /* Name.Decorator */197.ni { color: #717171; font-weight: bold } /* Name.Entity */198.ne { color: #CB3F38; font-weight: bold } /* Name.Exception */199.nf { color: #f9f978 } /* Name.Function */200.nl { color: #767600 } /* Name.Label */201.nn { color: #0000FF; font-weight: bold } /* Name.Namespace */202.nt { color: #008000; font-weight: bold } /* Name.Tag */203.nv { color: #19177C } /* Name.Variable */204.ow { color: #AA22FF; font-weight: bold } /* Operator.Word */205.w { color: #bbbbbb } /* Text.Whitespace */206.mb { color: #666666 } /* Literal.Number.Bin */207.mf { color: #666666 } /* Literal.Number.Float */208.mh { color: #666666 } /* Literal.Number.Hex */209.mi { color: #666666 } /* Literal.Number.Integer */210.mo { color: #666666 } /* Literal.Number.Oct */211.sa { color: #BA2121 } /* Literal.String.Affix */212.sb { color: #BA2121 } /* Literal.String.Backtick */213.sc { color: #BA2121 } /* Literal.String.Char */214.dl { color: #BA2121 } /* Literal.String.Delimiter */215.sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */216.s2 { color: #2bf840 } /* Literal.String.Double */217.se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */218.sh { color: #BA2121 } /* Literal.String.Heredoc */219.si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */220.sx { color: #008000 } /* Literal.String.Other */221.sr { color: #A45A77 } /* Literal.String.Regex */222.s1 { color: #BA2121 } /* Literal.String.Single */223.ss { color: #19177C } /* Literal.String.Symbol */224.bp { color: #008000 } /* Name.Builtin.Pseudo */225.fm { color: #0000FF } /* Name.Function.Magic */226.vc { color: #19177C } /* Name.Variable.Class */227.vg { color: #19177C } /* Name.Variable.Global */228.vi { color: #19177C } /* Name.Variable.Instance */229.vm { color: #19177C } /* Name.Variable.Magic */230.il { color: #666666 } /* Literal.Number.Integer.Long */231"""232