Improved instruct style (with syntax highlighting & LaTeX rendering) (#5936)

This commit is contained in:
oobabooga 2024-04-26 10:13:11 -03:00 committed by GitHub
parent 9c04365f54
commit 6761b5e7c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
74 changed files with 1358 additions and 51 deletions

View file

@ -45,6 +45,15 @@ def my_open(*args, **kwargs):
file_contents = file_contents.replace(b'\t\t<script\n\t\t\tsrc="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.9/iframeResizer.contentWindow.min.js"\n\t\t\tasync\n\t\t></script>', b'')
file_contents = file_contents.replace(b'cdnjs.cloudflare.com', b'127.0.0.1')
file_contents = file_contents.replace(
b'</head>',
b'\n <script src="file/js/katex/katex.min.js"></script>'
b'\n <script src="file/js/katex/auto-render.min.js"></script>'
b'\n <script src="file/js/highlightjs/highlight.min.js"></script>'
b'\n <script src="file/js/highlightjs/highlightjs-copy.min.js"></script>'
b'\n <script>hljs.addPlugin(new CopyButtonPlugin());</script>'
b'\n </head>'
)
return io.BytesIO(file_contents)
else:

View file

@ -57,6 +57,14 @@ def convert_to_markdown(string):
# Code
string = string.replace('\\begin{code}', '```')
string = string.replace('\\end{code}', '```')
string = string.replace('\\begin{align*}', '$$')
string = string.replace('\\end{align*}', '$$')
string = string.replace('\\begin{align}', '$$')
string = string.replace('\\end{align}', '$$')
string = string.replace('\\begin{equation}', '$$')
string = string.replace('\\end{equation}', '$$')
string = string.replace('\\begin{equation*}', '$$')
string = string.replace('\\end{equation*}', '$$')
string = re.sub(r"(.)```", r"\1\n```", string)
result = ''

View file

@ -3,7 +3,6 @@ import copy
import html
import pprint
import random
import re
import time
import traceback
@ -196,20 +195,6 @@ def formatted_outputs(reply, model_name):
return html.unescape(reply), generate_basic_html(reply)
def fix_galactica(s):
"""
Fix the LaTeX equations in GALACTICA
"""
s = s.replace(r'\[', r'$')
s = s.replace(r'\]', r'$')
s = s.replace(r'\(', r'$')
s = s.replace(r'\)', r'$')
s = s.replace(r'$$', r'$')
s = re.sub(r'\n', r'\n\n', s)
s = re.sub(r"\n{3,}", "\n\n", s)
return s
def set_manual_seed(seed):
seed = int(seed)
if seed == -1:

View file

@ -13,6 +13,12 @@ with open(Path(__file__).resolve().parent / '../css/NotoSans/stylesheet.css', 'r
css = f.read()
with open(Path(__file__).resolve().parent / '../css/main.css', 'r') as f:
css += f.read()
with open(Path(__file__).resolve().parent / '../css/katex/katex.min.css', 'r') as f:
css += f.read()
with open(Path(__file__).resolve().parent / '../css/highlightjs/github-dark.min.css', 'r') as f:
css += f.read()
with open(Path(__file__).resolve().parent / '../css/highlightjs/highlightjs-copy.min.css', 'r') as f:
css += f.read()
with open(Path(__file__).resolve().parent / '../js/main.js', 'r') as f:
js = f.read()
with open(Path(__file__).resolve().parent / '../js/save_files.js', 'r') as f:
@ -36,7 +42,7 @@ theme = gr.themes.Default(
button_large_padding='6px 12px',
body_text_color_subdued='#484848',
background_fill_secondary='#eaeaea',
background_fill_primary='#fafafa',
background_fill_primary='var(--neutral-50)',
)
if Path("notification.mp3").exists():