daydayup1225 commited on
Commit
7f27993
·
1 Parent(s): 7b32810

Upload 19 files

Browse files
app.py ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding:utf-8 -*-
2
+ import os
3
+ import logging
4
+ import sys
5
+ import gradio as gr
6
+ import torch
7
+ import gc
8
+ from app_modules.utils import *
9
+ from app_modules.presets import *
10
+ from app_modules.overwrites import *
11
+
12
+ import os
13
+ os.environ["CUDA_VISIBLE_DEVICES"] = "0"
14
+
15
+
16
+ logging.basicConfig(
17
+ level=logging.DEBUG,
18
+ format="%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(message)s",
19
+ )
20
+
21
+ # base_model = "decapoda-research/llama-7b-hf"
22
+ # adapter_model = "project-baize/baize-lora-7B"
23
+
24
+ base_model = "facebook/opt-1.3b"
25
+ # adapter_model = "msuhail97/opt-1.3b-lora"
26
+ # tokenizer, model, device = load_tokenizer_and_model(base_model, adapter_model)
27
+
28
+ # finetune_model_path = "/home2/xqchang/Chat-web/ft_models/ft-opt-1.3b"
29
+ tokenizer, model, device = load_finetune_tokenizer_and_model(base_model)
30
+
31
+
32
+ total_count = 0
33
+ def predict(text,
34
+ chatbot,
35
+ history,
36
+ top_p,
37
+ temperature,
38
+ max_length_tokens,
39
+ max_context_length_tokens,):
40
+ if text=="":
41
+ yield chatbot,history,"Empty context."
42
+ return
43
+ try:
44
+ model
45
+ except:
46
+ yield [[text,"No Model Found"]],[],"No Model Found"
47
+ return
48
+
49
+ inputs = generate_prompt_with_history(text,history,tokenizer,max_length=max_context_length_tokens)
50
+ if inputs is None:
51
+ yield chatbot,history,"Input too long."
52
+ return
53
+ else:
54
+ prompt,inputs=inputs
55
+ begin_length = len(prompt)
56
+ input_ids = inputs["input_ids"][:,-max_context_length_tokens:].to(device)
57
+ torch.cuda.empty_cache()
58
+ global total_count
59
+ total_count += 1
60
+ print(total_count)
61
+ if total_count % 50 == 0 :
62
+ os.system("nvidia-smi")
63
+ with torch.no_grad():
64
+ for x in greedy_search(input_ids,model,tokenizer,stop_words=["[|Human|]", "[|AI|]"],max_length=max_length_tokens,temperature=temperature,top_p=top_p):
65
+ if is_stop_word_or_prefix(x,["[|Human|]", "[|AI|]"]) is False:
66
+ if "[|Human|]" in x:
67
+ x = x[:x.index("[|Human|]")].strip()
68
+ if "[|AI|]" in x:
69
+ x = x[:x.index("[|AI|]")].strip()
70
+ x = x.strip()
71
+ a, b= [[y[0],convert_to_markdown(y[1])] for y in history]+[[text, convert_to_markdown(x)]],history + [[text,x]]
72
+ yield a, b, "Generating..."
73
+ if shared_state.interrupted:
74
+ shared_state.recover()
75
+ try:
76
+ yield a, b, "Stop: Success"
77
+ return
78
+ except:
79
+ pass
80
+ del input_ids
81
+ gc.collect()
82
+ torch.cuda.empty_cache()
83
+ #print(text)
84
+ #print(x)
85
+ #print("="*80)
86
+ try:
87
+ yield a,b,"Generate: Success"
88
+ except:
89
+ pass
90
+
91
+ def retry(
92
+ text,
93
+ chatbot,
94
+ history,
95
+ top_p,
96
+ temperature,
97
+ max_length_tokens,
98
+ max_context_length_tokens,
99
+ ):
100
+ logging.info("Retry...")
101
+ if len(history) == 0:
102
+ yield chatbot, history, f"Empty context"
103
+ return
104
+ chatbot.pop()
105
+ inputs = history.pop()[0]
106
+ for x in predict(inputs,chatbot,history,top_p,temperature,max_length_tokens,max_context_length_tokens):
107
+ yield x
108
+
109
+
110
+ gr.Chatbot.postprocess = postprocess
111
+
112
+ with open("assets/custom.css", "r", encoding="utf-8") as f:
113
+ customCSS = f.read()
114
+
115
+ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
116
+ history = gr.State([])
117
+ user_question = gr.State("")
118
+ with gr.Row():
119
+ gr.HTML(title)
120
+ status_display = gr.Markdown("Success", elem_id="status_display")
121
+ gr.Markdown(description_top)
122
+ with gr.Row(scale=1).style(equal_height=True):
123
+ with gr.Column(scale=5):
124
+ with gr.Row(scale=1):
125
+ chatbot = gr.Chatbot(elem_id="chuanhu_chatbot").style(height="100%")
126
+ with gr.Row(scale=1):
127
+ with gr.Column(scale=12):
128
+ user_input = gr.Textbox(
129
+ show_label=False, placeholder="Enter text"
130
+ ).style(container=False)
131
+ with gr.Column(min_width=70, scale=1):
132
+ submitBtn = gr.Button("Send")
133
+ with gr.Column(min_width=70, scale=1):
134
+ cancelBtn = gr.Button("Stop")
135
+ with gr.Row(scale=1):
136
+ emptyBtn = gr.Button(
137
+ "🧹 New Conversation",
138
+ )
139
+ retryBtn = gr.Button("🔄 Regenerate")
140
+ delLastBtn = gr.Button("🗑️ Remove Last Turn")
141
+ with gr.Column():
142
+ with gr.Column(min_width=50, scale=1):
143
+ with gr.Tab(label="Parameter Setting"):
144
+ gr.Markdown("# Parameters")
145
+ top_p = gr.Slider(
146
+ minimum=-0,
147
+ maximum=1.0,
148
+ value=0.95,
149
+ step=0.05,
150
+ interactive=True,
151
+ label="Top-p",
152
+ )
153
+ temperature = gr.Slider(
154
+ minimum=0.1,
155
+ maximum=2.0,
156
+ value=1,
157
+ step=0.1,
158
+ interactive=True,
159
+ label="Temperature",
160
+ )
161
+ max_length_tokens = gr.Slider(
162
+ minimum=0,
163
+ maximum=512,
164
+ value=256,
165
+ step=8,
166
+ interactive=True,
167
+ label="Max Generation Tokens",
168
+ )
169
+ max_context_length_tokens = gr.Slider(
170
+ minimum=0,
171
+ maximum=4096,
172
+ value=2048,
173
+ step=128,
174
+ interactive=True,
175
+ label="Max History Tokens",
176
+ )
177
+ # gr.Markdown(description)
178
+
179
+ predict_args = dict(
180
+ fn=predict,
181
+ inputs=[
182
+ user_question,
183
+ chatbot,
184
+ history,
185
+ top_p,
186
+ temperature,
187
+ max_length_tokens,
188
+ max_context_length_tokens,
189
+ ],
190
+ outputs=[chatbot, history, status_display],
191
+ show_progress=True,
192
+ )
193
+ retry_args = dict(
194
+ fn=retry,
195
+ inputs=[
196
+ user_input,
197
+ chatbot,
198
+ history,
199
+ top_p,
200
+ temperature,
201
+ max_length_tokens,
202
+ max_context_length_tokens,
203
+ ],
204
+ outputs=[chatbot, history, status_display],
205
+ show_progress=True,
206
+ )
207
+
208
+ reset_args = dict(
209
+ fn=reset_textbox, inputs=[], outputs=[user_input, status_display]
210
+ )
211
+
212
+ # Chatbot
213
+ transfer_input_args = dict(
214
+ fn=transfer_input, inputs=[user_input], outputs=[user_question, user_input, submitBtn], show_progress=True
215
+ )
216
+
217
+ predict_event1 = user_input.submit(**transfer_input_args).then(**predict_args)
218
+
219
+ predict_event2 = submitBtn.click(**transfer_input_args).then(**predict_args)
220
+
221
+ emptyBtn.click(
222
+ reset_state,
223
+ outputs=[chatbot, history, status_display],
224
+ show_progress=True,
225
+ )
226
+ emptyBtn.click(**reset_args)
227
+
228
+ predict_event3 = retryBtn.click(**retry_args)
229
+
230
+ delLastBtn.click(
231
+ delete_last_conversation,
232
+ [chatbot, history],
233
+ [chatbot, history, status_display],
234
+ show_progress=True,
235
+ )
236
+ cancelBtn.click(
237
+ cancel_outputing, [], [status_display],
238
+ cancels=[
239
+ predict_event1,predict_event2,predict_event3
240
+ ]
241
+ )
242
+ # demo.title = "Baize"
243
+
244
+ demo.queue(concurrency_count=1).launch(server_name="127.0.0.1", server_port=7860, share=True)
app_modules/__pycache__/chat_func.cpython-38.pyc ADDED
Binary file (605 Bytes). View file
 
app_modules/__pycache__/llama_func.cpython-38.pyc ADDED
Binary file (4.62 kB). View file
 
app_modules/__pycache__/openai_func.cpython-38.pyc ADDED
Binary file (1.8 kB). View file
 
app_modules/__pycache__/overwrites.cpython-38.pyc ADDED
Binary file (2.6 kB). View file
 
app_modules/__pycache__/overwrites.cpython-39.pyc ADDED
Binary file (2.61 kB). View file
 
app_modules/__pycache__/presets.cpython-38.pyc ADDED
Binary file (2.26 kB). View file
 
app_modules/__pycache__/presets.cpython-39.pyc ADDED
Binary file (1.73 kB). View file
 
app_modules/__pycache__/shared.cpython-38.pyc ADDED
Binary file (1.08 kB). View file
 
app_modules/__pycache__/utils.cpython-38.pyc ADDED
Binary file (10.1 kB). View file
 
app_modules/__pycache__/utils.cpython-39.pyc ADDED
Binary file (10.5 kB). View file
 
app_modules/overwrites.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ import logging
3
+
4
+ from llama_index import Prompt
5
+ from typing import List, Tuple
6
+ import mdtex2html
7
+
8
+ from app_modules.presets import *
9
+ from app_modules.utils import *
10
+
11
+ def compact_text_chunks(self, prompt: Prompt, text_chunks: List[str]) -> List[str]:
12
+ logging.debug("Compacting text chunks...🚀🚀🚀")
13
+ combined_str = [c.strip() for c in text_chunks if c.strip()]
14
+ combined_str = [f"[{index+1}] {c}" for index, c in enumerate(combined_str)]
15
+ combined_str = "\n\n".join(combined_str)
16
+ # resplit based on self.max_chunk_overlap
17
+ text_splitter = self.get_text_splitter_given_prompt(prompt, 1, padding=1)
18
+ return text_splitter.split_text(combined_str)
19
+
20
+
21
+ def postprocess(
22
+ self, y: List[Tuple[str | None, str | None]]
23
+ ) -> List[Tuple[str | None, str | None]]:
24
+ """
25
+ Parameters:
26
+ y: List of tuples representing the message and response pairs. Each message and response should be a string, which may be in Markdown format.
27
+ Returns:
28
+ List of tuples representing the message and response. Each message and response will be a string of HTML.
29
+ """
30
+ if y is None or y == []:
31
+ return []
32
+ temp = []
33
+ for x in y:
34
+ user, bot = x
35
+ if not detect_converted_mark(user):
36
+ user = convert_asis(user)
37
+ if not detect_converted_mark(bot):
38
+ bot = convert_mdtext(bot)
39
+ temp.append((user, bot))
40
+ return temp
41
+
42
+ with open("./assets/custom.js", "r", encoding="utf-8") as f, open("./assets/Kelpy-Codos.js", "r", encoding="utf-8") as f2:
43
+ customJS = f.read()
44
+ kelpyCodos = f2.read()
45
+
46
+ def reload_javascript():
47
+ print("Reloading javascript...")
48
+ js = f'<script>{customJS}</script><script>{kelpyCodos}</script>'
49
+ def template_response(*args, **kwargs):
50
+ res = GradioTemplateResponseOriginal(*args, **kwargs)
51
+ res.body = res.body.replace(b'</html>', f'{js}</html>'.encode("utf8"))
52
+ res.init_headers()
53
+ return res
54
+
55
+ gr.routes.templates.TemplateResponse = template_response
56
+
57
+ GradioTemplateResponseOriginal = gr.routes.templates.TemplateResponse
app_modules/presets.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding:utf-8 -*-
2
+ import gradio as gr
3
+
4
+
5
+ title = """<h1 align="left" style="min-width:200px; margin-top:0;"> OPT </h1>"""
6
+ description_top = """\
7
+ <div align="left">
8
+ <p>
9
+ Disclaimer: The OPT model is a third-party version available on Hugging Face model hub.
10
+ </p >
11
+ </div>
12
+ """
13
+
14
+ CONCURRENT_COUNT = 100
15
+
16
+
17
+ ALREADY_CONVERTED_MARK = "<!-- ALREADY CONVERTED BY PARSER. -->"
18
+
19
+ small_and_beautiful_theme = gr.themes.Soft(
20
+ primary_hue=gr.themes.Color(
21
+ c50="#02C160",
22
+ c100="rgba(2, 193, 96, 0.2)",
23
+ c200="#02C160",
24
+ c300="rgba(2, 193, 96, 0.32)",
25
+ c400="rgba(2, 193, 96, 0.32)",
26
+ c500="rgba(2, 193, 96, 1.0)",
27
+ c600="rgba(2, 193, 96, 1.0)",
28
+ c700="rgba(2, 193, 96, 0.32)",
29
+ c800="rgba(2, 193, 96, 0.32)",
30
+ c900="#02C160",
31
+ c950="#02C160",
32
+ ),
33
+ secondary_hue=gr.themes.Color(
34
+ c50="#576b95",
35
+ c100="#576b95",
36
+ c200="#576b95",
37
+ c300="#576b95",
38
+ c400="#576b95",
39
+ c500="#576b95",
40
+ c600="#576b95",
41
+ c700="#576b95",
42
+ c800="#576b95",
43
+ c900="#576b95",
44
+ c950="#576b95",
45
+ ),
46
+ neutral_hue=gr.themes.Color(
47
+ name="gray",
48
+ c50="#f9fafb",
49
+ c100="#f3f4f6",
50
+ c200="#e5e7eb",
51
+ c300="#d1d5db",
52
+ c400="#B2B2B2",
53
+ c500="#808080",
54
+ c600="#636363",
55
+ c700="#515151",
56
+ c800="#393939",
57
+ c900="#272727",
58
+ c950="#171717",
59
+ ),
60
+ radius_size=gr.themes.sizes.radius_sm,
61
+ ).set(
62
+ button_primary_background_fill="#06AE56",
63
+ button_primary_background_fill_dark="#06AE56",
64
+ button_primary_background_fill_hover="#07C863",
65
+ button_primary_border_color="#06AE56",
66
+ button_primary_border_color_dark="#06AE56",
67
+ button_primary_text_color="#FFFFFF",
68
+ button_primary_text_color_dark="#FFFFFF",
69
+ button_secondary_background_fill="#F2F2F2",
70
+ button_secondary_background_fill_dark="#2B2B2B",
71
+ button_secondary_text_color="#393939",
72
+ button_secondary_text_color_dark="#FFFFFF",
73
+ # background_fill_primary="#F7F7F7",
74
+ # background_fill_primary_dark="#1F1F1F",
75
+ block_title_text_color="*primary_500",
76
+ block_title_background_fill="*primary_100",
77
+ input_background_fill="#F6F6F6",
78
+ )
app_modules/utils.py ADDED
@@ -0,0 +1,454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding:utf-8 -*-
2
+ from __future__ import annotations
3
+ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Tuple, Type
4
+ import logging
5
+ import json
6
+ import os
7
+ import datetime
8
+ import hashlib
9
+ import csv
10
+ import requests
11
+ import re
12
+ import html
13
+ import markdown2
14
+ import torch
15
+ import sys
16
+ import gc
17
+ from pygments.lexers import guess_lexer, ClassNotFound
18
+
19
+ import gradio as gr
20
+ from pypinyin import lazy_pinyin
21
+ import tiktoken
22
+ import mdtex2html
23
+ from markdown import markdown
24
+ from pygments import highlight
25
+ from pygments.lexers import guess_lexer,get_lexer_by_name
26
+ from pygments.formatters import HtmlFormatter
27
+ import transformers
28
+ from peft import PeftModel
29
+ from transformers import LlamaForCausalLM, LlamaTokenizer
30
+
31
+ from transformers import (
32
+ AutoTokenizer,
33
+ AutoModelForCausalLM,
34
+ )
35
+
36
+ from app_modules.presets import *
37
+
38
+ logging.basicConfig(
39
+ level=logging.INFO,
40
+ format="%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(message)s",
41
+ )
42
+
43
+
44
+ def markdown_to_html_with_syntax_highlight(md_str):
45
+ def replacer(match):
46
+ lang = match.group(1) or "text"
47
+ code = match.group(2)
48
+ lang = lang.strip()
49
+ #print(1,lang)
50
+ if lang=="text":
51
+ lexer = guess_lexer(code)
52
+ lang = lexer.name
53
+ #print(2,lang)
54
+ try:
55
+ lexer = get_lexer_by_name(lang, stripall=True)
56
+ except ValueError:
57
+ lexer = get_lexer_by_name("python", stripall=True)
58
+ formatter = HtmlFormatter()
59
+ #print(3,lexer.name)
60
+ highlighted_code = highlight(code, lexer, formatter)
61
+
62
+ return f'<pre><code class="{lang}">{highlighted_code}</code></pre>'
63
+
64
+ code_block_pattern = r"```(\w+)?\n([\s\S]+?)\n```"
65
+ md_str = re.sub(code_block_pattern, replacer, md_str, flags=re.MULTILINE)
66
+
67
+ html_str = markdown(md_str)
68
+ return html_str
69
+
70
+
71
+ def normalize_markdown(md_text: str) -> str:
72
+ lines = md_text.split("\n")
73
+ normalized_lines = []
74
+ inside_list = False
75
+
76
+ for i, line in enumerate(lines):
77
+ if re.match(r"^(\d+\.|-|\*|\+)\s", line.strip()):
78
+ if not inside_list and i > 0 and lines[i - 1].strip() != "":
79
+ normalized_lines.append("")
80
+ inside_list = True
81
+ normalized_lines.append(line)
82
+ elif inside_list and line.strip() == "":
83
+ if i < len(lines) - 1 and not re.match(
84
+ r"^(\d+\.|-|\*|\+)\s", lines[i + 1].strip()
85
+ ):
86
+ normalized_lines.append(line)
87
+ continue
88
+ else:
89
+ inside_list = False
90
+ normalized_lines.append(line)
91
+
92
+ return "\n".join(normalized_lines)
93
+
94
+
95
+ def convert_mdtext(md_text):
96
+ code_block_pattern = re.compile(r"```(.*?)(?:```|$)", re.DOTALL)
97
+ inline_code_pattern = re.compile(r"`(.*?)`", re.DOTALL)
98
+ code_blocks = code_block_pattern.findall(md_text)
99
+ non_code_parts = code_block_pattern.split(md_text)[::2]
100
+
101
+ result = []
102
+ for non_code, code in zip(non_code_parts, code_blocks + [""]):
103
+ if non_code.strip():
104
+ non_code = normalize_markdown(non_code)
105
+ if inline_code_pattern.search(non_code):
106
+ result.append(markdown(non_code, extensions=["tables"]))
107
+ else:
108
+ result.append(mdtex2html.convert(non_code, extensions=["tables"]))
109
+ if code.strip():
110
+ # _, code = detect_language(code) # 暂时去除代码高亮功能,因为在大段代码的情况下会出现问题
111
+ # code = code.replace("\n\n", "\n") # 暂时去除代码中的空行,因为在大段代码的情况下会出现问题
112
+ code = f"\n```{code}\n\n```"
113
+ code = markdown_to_html_with_syntax_highlight(code)
114
+ result.append(code)
115
+ result = "".join(result)
116
+ result += ALREADY_CONVERTED_MARK
117
+ return result
118
+
119
+ def convert_asis(userinput):
120
+ return f"<p style=\"white-space:pre-wrap;\">{html.escape(userinput)}</p>"+ALREADY_CONVERTED_MARK
121
+
122
+ def detect_converted_mark(userinput):
123
+ if userinput.endswith(ALREADY_CONVERTED_MARK):
124
+ return True
125
+ else:
126
+ return False
127
+
128
+
129
+
130
+ def detect_language(code):
131
+ if code.startswith("\n"):
132
+ first_line = ""
133
+ else:
134
+ first_line = code.strip().split("\n", 1)[0]
135
+ language = first_line.lower() if first_line else ""
136
+ code_without_language = code[len(first_line) :].lstrip() if first_line else code
137
+ return language, code_without_language
138
+
139
+ def convert_to_markdown(text):
140
+ text = text.replace("$","&#36;")
141
+ def replace_leading_tabs_and_spaces(line):
142
+ new_line = []
143
+
144
+ for char in line:
145
+ if char == "\t":
146
+ new_line.append("&#9;")
147
+ elif char == " ":
148
+ new_line.append("&nbsp;")
149
+ else:
150
+ break
151
+ return "".join(new_line) + line[len(new_line):]
152
+
153
+ markdown_text = ""
154
+ lines = text.split("\n")
155
+ in_code_block = False
156
+
157
+ for line in lines:
158
+ if in_code_block is False and line.startswith("```"):
159
+ in_code_block = True
160
+ markdown_text += "```\n"
161
+ elif in_code_block is True and line.startswith("```"):
162
+ in_code_block = False
163
+ markdown_text += "```\n"
164
+ elif in_code_block:
165
+ markdown_text += f"{line}\n"
166
+ else:
167
+ line = replace_leading_tabs_and_spaces(line)
168
+ line = re.sub(r"^(#)", r"\\\1", line)
169
+ markdown_text += f"{line} \n"
170
+
171
+ return markdown_text
172
+
173
+ def add_language_tag(text):
174
+ def detect_language(code_block):
175
+ try:
176
+ lexer = guess_lexer(code_block)
177
+ return lexer.name.lower()
178
+ except ClassNotFound:
179
+ return ""
180
+
181
+ code_block_pattern = re.compile(r"(```)(\w*\n[^`]+```)", re.MULTILINE)
182
+
183
+ def replacement(match):
184
+ code_block = match.group(2)
185
+ if match.group(2).startswith("\n"):
186
+ language = detect_language(code_block)
187
+ if language:
188
+ return f"```{language}{code_block}```"
189
+ else:
190
+ return f"```\n{code_block}```"
191
+ else:
192
+ return match.group(1) + code_block + "```"
193
+
194
+ text2 = code_block_pattern.sub(replacement, text)
195
+ return text2
196
+
197
+ def delete_last_conversation(chatbot, history):
198
+ if len(chatbot) > 0:
199
+ chatbot.pop()
200
+
201
+ if len(history) > 0:
202
+ history.pop()
203
+
204
+ return (
205
+ chatbot,
206
+ history,
207
+ "Delete Done",
208
+ )
209
+
210
+ def reset_state():
211
+ return [], [], "Reset Done"
212
+
213
+ def reset_textbox():
214
+ return gr.update(value=""),""
215
+
216
+ def cancel_outputing():
217
+ return "Stop Done"
218
+
219
+ def transfer_input(inputs):
220
+ # 一次性返回,降低延迟
221
+ textbox = reset_textbox()
222
+ return (
223
+ inputs,
224
+ gr.update(value=""),
225
+ gr.Button.update(visible=True),
226
+ )
227
+
228
+
229
+ class State:
230
+ interrupted = False
231
+
232
+ def interrupt(self):
233
+ self.interrupted = True
234
+
235
+ def recover(self):
236
+ self.interrupted = False
237
+ shared_state = State()
238
+
239
+
240
+
241
+
242
+
243
+ # Greedy Search
244
+ def greedy_search(input_ids: torch.Tensor,
245
+ model: torch.nn.Module,
246
+ tokenizer: transformers.PreTrainedTokenizer,
247
+ stop_words: list,
248
+ max_length: int,
249
+ temperature: float = 1.0,
250
+ top_p: float = 1.0,
251
+ top_k: int = 25) -> Iterator[str]:
252
+ generated_tokens = []
253
+ past_key_values = None
254
+ current_length = 1
255
+ for i in range(max_length):
256
+ with torch.no_grad():
257
+ if past_key_values is None:
258
+ outputs = model(input_ids)
259
+ else:
260
+ outputs = model(input_ids[:, -1:], past_key_values=past_key_values)
261
+ logits = outputs.logits[:, -1, :]
262
+ past_key_values = outputs.past_key_values
263
+
264
+ # apply temperature
265
+ logits /= temperature
266
+
267
+ probs = torch.softmax(logits, dim=-1)
268
+ # apply top_p
269
+ probs_sort, probs_idx = torch.sort(probs, dim=-1, descending=True)
270
+ probs_sum = torch.cumsum(probs_sort, dim=-1)
271
+ mask = probs_sum - probs_sort > top_p
272
+ probs_sort[mask] = 0.0
273
+
274
+ # apply top_k
275
+ # if top_k is not None:
276
+ # probs_sort1, _ = torch.topk(probs_sort, top_k)
277
+ # min_top_probs_sort = torch.min(probs_sort1, dim=-1, keepdim=True).values
278
+ # probs_sort = torch.where(probs_sort < min_top_probs_sort, torch.full_like(probs_sort, float(0.0)), probs_sort)
279
+
280
+ probs_sort.div_(probs_sort.sum(dim=-1, keepdim=True))
281
+ next_token = torch.multinomial(probs_sort, num_samples=1)
282
+ next_token = torch.gather(probs_idx, -1, next_token)
283
+
284
+ input_ids = torch.cat((input_ids, next_token), dim=-1)
285
+
286
+ generated_tokens.append(next_token[0].item())
287
+ text = tokenizer.decode(generated_tokens)
288
+
289
+ yield text
290
+ if any([x in text for x in stop_words]):
291
+ del past_key_values
292
+ del logits
293
+ del probs
294
+ del probs_sort
295
+ del probs_idx
296
+ del probs_sum
297
+ gc.collect()
298
+ return
299
+
300
+ def generate_prompt_with_history(text,history,tokenizer,max_length=2048):
301
+ prompt = "The following is a conversation between a human and an AI assistant. The human and the AI assistant take turns chatting. Human statements start with [|Human|] and AI assistant statements start with [|AI|]. The AI assistant always provides responses in as much detail as possible, and in Markdown format. The AI assistant always declines to engage with topics, questions and instructions related to unethical, controversial, or sensitive issues. Complete the transcript in exactly that format.\n[|Human|]Hello!\n[|AI|]Hi!"
302
+ history = ["\n[|Human|]{}\n[|AI|]{}".format(x[0],x[1]) for x in history]
303
+ history.append("\n[|Human|]{}\n[|AI|]".format(text))
304
+ history_text = ""
305
+ flag = False
306
+ for x in history[::-1]:
307
+ if tokenizer(prompt+history_text+x, return_tensors="pt")['input_ids'].size(-1) <= max_length:
308
+ history_text = x + history_text
309
+ flag = True
310
+ else:
311
+ break
312
+ if flag:
313
+ return prompt+history_text,tokenizer(prompt+history_text, return_tensors="pt")
314
+ else:
315
+ return None
316
+
317
+
318
+ def is_stop_word_or_prefix(s: str, stop_words: list) -> bool:
319
+ for stop_word in stop_words:
320
+ if s.endswith(stop_word):
321
+ return True
322
+ for i in range(1, len(stop_word)):
323
+ if s.endswith(stop_word[:i]):
324
+ return True
325
+ return False
326
+
327
+
328
+
329
+ def load_tokenizer_and_model(base_model, adapter_model, load_8bit=False): #base_model, adapter_model, load_8bit=False
330
+ if torch.cuda.is_available():
331
+ device = "cuda"
332
+ else:
333
+ device = "cpu"
334
+
335
+ try:
336
+ if torch.backends.mps.is_available():
337
+ device = "mps"
338
+ except: # noqa: E722
339
+ pass
340
+ # tokenizer = LlamaTokenizer.from_pretrained(base_model)
341
+ # if device == "cuda":
342
+ # model = LlamaForCausalLM.from_pretrained(
343
+ # base_model,
344
+ # load_in_8bit=load_8bit,
345
+ # torch_dtype=torch.float16,
346
+ # device_map="auto",
347
+ # )
348
+ # model = PeftModel.from_pretrained(
349
+ # model,
350
+ # adapter_model,
351
+ # torch_dtype=torch.float16,
352
+ # )
353
+ # elif device == "mps":
354
+ # model = LlamaForCausalLM.from_pretrained(
355
+ # base_model,
356
+ # device_map={"": device},
357
+ # torch_dtype=torch.float16,
358
+ # )
359
+ # model = PeftModel.from_pretrained(
360
+ # model,
361
+ # adapter_model,
362
+ # device_map={"": device},
363
+ # torch_dtype=torch.float16,
364
+ # )
365
+ # else:
366
+ # model = LlamaForCausalLM.from_pretrained(
367
+ # base_model, device_map={"": device}, low_cpu_mem_usage=True
368
+ # )
369
+ # model = PeftModel.from_pretrained(
370
+ # model,
371
+ # adapter_model,
372
+ # device_map={"": device},
373
+ # )
374
+
375
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
376
+ if device == "cuda":
377
+ model = AutoModelForCausalLM.from_pretrained(
378
+ base_model,
379
+ load_in_8bit=load_8bit,
380
+ torch_dtype=torch.float16,
381
+ device_map="auto",
382
+ )
383
+ model = PeftModel.from_pretrained(
384
+ model,
385
+ adapter_model,
386
+ torch_dtype=torch.float16,
387
+ )
388
+ elif device == "mps":
389
+ model = AutoModelForCausalLM.from_pretrained(
390
+ base_model,
391
+ device_map={"": device},
392
+ torch_dtype=torch.float16,
393
+ )
394
+ model = PeftModel.from_pretrained(
395
+ model,
396
+ adapter_model,
397
+ device_map={"": device},
398
+ torch_dtype=torch.float16,
399
+ )
400
+ else:
401
+ model = AutoModelForCausalLM.from_pretrained(
402
+ base_model, device_map={"": device}, low_cpu_mem_usage=True
403
+ )
404
+ model = PeftModel.from_pretrained(
405
+ model,
406
+ adapter_model,
407
+ device_map={"": device},
408
+ )
409
+
410
+ if not load_8bit:
411
+ model.half() # seems to fix bugs for some users.
412
+
413
+ model.eval()
414
+ return tokenizer, model, device
415
+
416
+
417
+
418
+ def load_finetune_tokenizer_and_model(base_model_name_or_path, load_8bit=False):
419
+ if torch.cuda.is_available():
420
+ device = "cuda"
421
+ else:
422
+ device = "cpu"
423
+
424
+ try:
425
+ if torch.backends.mps.is_available():
426
+ device = "mps"
427
+ except: # noqa: E722
428
+ pass
429
+
430
+ tokenizer = AutoTokenizer.from_pretrained(base_model_name_or_path)
431
+ if device == "cuda":
432
+ model = AutoModelForCausalLM.from_pretrained(
433
+ base_model_name_or_path,
434
+ load_in_8bit=load_8bit,
435
+ torch_dtype=torch.float16,
436
+ device_map="auto",
437
+ )
438
+ elif device == "mps":
439
+ model = AutoModelForCausalLM.from_pretrained(
440
+ base_model_name_or_path,
441
+ device_map={"": device},
442
+ torch_dtype=torch.float16,
443
+ )
444
+ else:
445
+ model = AutoModelForCausalLM.from_pretrained(
446
+ base_model_name_or_path, device_map={"": device}, low_cpu_mem_usage=True
447
+ )
448
+
449
+ if not load_8bit:
450
+ model.half() # seems to fix bugs for some users.
451
+
452
+ model.eval()
453
+ return tokenizer, model, device
454
+
assets/Kelpy-Codos.js ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ==UserScript==
2
+ // @name Kelpy Codos
3
+ // @namespace https://github.com/Keldos-Li/Kelpy-Codos
4
+ // @version 1.0.5
5
+ // @author Keldos; https://keldos.me/
6
+ // @description Add copy button to PRE tags before CODE tag, for Chuanhu ChatGPT especially.
7
+ // Based on Chuanhu ChatGPT version: ac04408 (2023-3-22)
8
+ // @license GPL-3.0
9
+ // @grant none
10
+ // ==/UserScript==
11
+
12
+ (function () {
13
+ 'use strict';
14
+
15
+ function addCopyButton(pre) {
16
+ var code = pre.querySelector('code');
17
+ if (!code) {
18
+ return; // 如果没有找到 <code> 元素,则不添加按钮
19
+ }
20
+ var firstChild = code.firstChild;
21
+ if (!firstChild) {
22
+ return; // 如果 <code> 元素没有子节点,则不添加按钮
23
+ }
24
+ var button = document.createElement('button');
25
+ button.textContent = '\uD83D\uDCCE'; // 使用 📎 符号作为“复制”按钮的文本
26
+ button.style.position = 'relative';
27
+ button.style.float = 'right';
28
+ button.style.fontSize = '1em'; // 可选:调整按钮大小
29
+ button.style.background = 'none'; // 可选:去掉背景颜色
30
+ button.style.border = 'none'; // 可选:去掉边框
31
+ button.style.cursor = 'pointer'; // 可选:显示指针样式
32
+ button.addEventListener('click', function () {
33
+ var range = document.createRange();
34
+ range.selectNodeContents(code);
35
+ range.setStartBefore(firstChild); // 将范围设置为第一个子节点之前
36
+ var selection = window.getSelection();
37
+ selection.removeAllRanges();
38
+ selection.addRange(range);
39
+
40
+ try {
41
+ var success = document.execCommand('copy');
42
+ if (success) {
43
+ button.textContent = '\u2714';
44
+ setTimeout(function () {
45
+ button.textContent = '\uD83D\uDCCE'; // 恢复按钮为“复制”
46
+ }, 2000);
47
+ } else {
48
+ button.textContent = '\u2716';
49
+ }
50
+ } catch (e) {
51
+ console.error(e);
52
+ button.textContent = '\u2716';
53
+ }
54
+
55
+ selection.removeAllRanges();
56
+ });
57
+ code.insertBefore(button, firstChild); // 将按钮插入到第一个子元素之前
58
+ }
59
+
60
+ function handleNewElements(mutationsList, observer) {
61
+ for (var mutation of mutationsList) {
62
+ if (mutation.type === 'childList') {
63
+ for (var node of mutation.addedNodes) {
64
+ if (node.nodeName === 'PRE') {
65
+ addCopyButton(node);
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ var observer = new MutationObserver(handleNewElements);
73
+ observer.observe(document.documentElement, { childList: true, subtree: true });
74
+
75
+ document.querySelectorAll('pre').forEach(addCopyButton);
76
+ })();
assets/custom.css ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :root {
2
+ --chatbot-color-light: #F3F3F3;
3
+ --chatbot-color-dark: #121111;
4
+ }
5
+
6
+ /* status_display */
7
+ #status_display {
8
+ display: flex;
9
+ min-height: 2.5em;
10
+ align-items: flex-end;
11
+ justify-content: flex-end;
12
+ }
13
+ #status_display p {
14
+ font-size: .85em;
15
+ font-family: monospace;
16
+ color: var(--body-text-color-subdued);
17
+ }
18
+
19
+
20
+
21
+ /* usage_display */
22
+ #usage_display {
23
+ height: 1em;
24
+ }
25
+ #usage_display p{
26
+ padding: 0 1em;
27
+ font-size: .85em;
28
+ font-family: monospace;
29
+ color: var(--body-text-color-subdued);
30
+ }
31
+ /* list */
32
+ ol:not(.options), ul:not(.options) {
33
+ padding-inline-start: 2em !important;
34
+ }
35
+
36
+ /* Thank @Keldos-Li for fixing it */
37
+ /* Light mode (default) */
38
+ #chuanhu_chatbot {
39
+ background-color: var(--chatbot-color-light) !important;
40
+ color: #000000 !important;
41
+ }
42
+ [data-testid = "bot"] {
43
+ background-color: #FFFFFF !important;
44
+ }
45
+ [data-testid = "user"] {
46
+ background-color: #95EC69 !important;
47
+ }
48
+
49
+ /* Dark mode */
50
+ .dark #chuanhu_chatbot {
51
+ background-color: var(--chatbot-color-dark) !important;
52
+ color: #FFFFFF !important;
53
+ }
54
+ .dark [data-testid = "bot"] {
55
+ background-color: #2C2C2C !important;
56
+ }
57
+ .dark [data-testid = "user"] {
58
+ background-color: #26B561 !important;
59
+ }
60
+
61
+ #chuanhu_chatbot {
62
+ height: 100%;
63
+ min-height: 400px;
64
+ }
65
+
66
+ [class *= "message"] {
67
+ border-radius: var(--radius-xl) !important;
68
+ border: none;
69
+ padding: var(--spacing-xl) !important;
70
+ font-size: var(--text-md) !important;
71
+ line-height: var(--line-md) !important;
72
+ min-height: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl));
73
+ min-width: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl));
74
+ }
75
+ [data-testid = "bot"] {
76
+ max-width: 85%;
77
+ border-bottom-left-radius: 0 !important;
78
+ }
79
+ [data-testid = "user"] {
80
+ max-width: 85%;
81
+ width: auto !important;
82
+ border-bottom-right-radius: 0 !important;
83
+ }
84
+ /* Table */
85
+ table {
86
+ margin: 1em 0;
87
+ border-collapse: collapse;
88
+ empty-cells: show;
89
+ }
90
+ td,th {
91
+ border: 1.2px solid var(--border-color-primary) !important;
92
+ padding: 0.2em;
93
+ }
94
+ thead {
95
+ background-color: rgba(175,184,193,0.2);
96
+ }
97
+ thead th {
98
+ padding: .5em .2em;
99
+ }
100
+ /* Inline code */
101
+ code {
102
+ display: inline;
103
+ white-space: break-spaces;
104
+ border-radius: 6px;
105
+ margin: 0 2px 0 2px;
106
+ padding: .2em .4em .1em .4em;
107
+ background-color: rgba(175,184,193,0.2);
108
+ }
109
+ /* Code block */
110
+ pre code {
111
+ display: block;
112
+ overflow: auto;
113
+ white-space: pre;
114
+ background-color: hsla(0, 0%, 0%, 80%)!important;
115
+ border-radius: 10px;
116
+ padding: 1.4em 1.2em 0em 1.4em;
117
+ margin: 1.2em 2em 1.2em 0.5em;
118
+ color: #FFF;
119
+ box-shadow: 6px 6px 16px hsla(0, 0%, 0%, 0.2);
120
+ }
121
+ /* Hightlight */
122
+ .highlight .hll { background-color: #49483e }
123
+ .highlight .c { color: #75715e } /* Comment */
124
+ .highlight .err { color: #960050; background-color: #1e0010 } /* Error */
125
+ .highlight .k { color: #66d9ef } /* Keyword */
126
+ .highlight .l { color: #ae81ff } /* Literal */
127
+ .highlight .n { color: #f8f8f2 } /* Name */
128
+ .highlight .o { color: #f92672 } /* Operator */
129
+ .highlight .p { color: #f8f8f2 } /* Punctuation */
130
+ .highlight .ch { color: #75715e } /* Comment.Hashbang */
131
+ .highlight .cm { color: #75715e } /* Comment.Multiline */
132
+ .highlight .cp { color: #75715e } /* Comment.Preproc */
133
+ .highlight .cpf { color: #75715e } /* Comment.PreprocFile */
134
+ .highlight .c1 { color: #75715e } /* Comment.Single */
135
+ .highlight .cs { color: #75715e } /* Comment.Special */
136
+ .highlight .gd { color: #f92672 } /* Generic.Deleted */
137
+ .highlight .ge { font-style: italic } /* Generic.Emph */
138
+ .highlight .gi { color: #a6e22e } /* Generic.Inserted */
139
+ .highlight .gs { font-weight: bold } /* Generic.Strong */
140
+ .highlight .gu { color: #75715e } /* Generic.Subheading */
141
+ .highlight .kc { color: #66d9ef } /* Keyword.Constant */
142
+ .highlight .kd { color: #66d9ef } /* Keyword.Declaration */
143
+ .highlight .kn { color: #f92672 } /* Keyword.Namespace */
144
+ .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
145
+ .highlight .kr { color: #66d9ef } /* Keyword.Reserved */
146
+ .highlight .kt { color: #66d9ef } /* Keyword.Type */
147
+ .highlight .ld { color: #e6db74 } /* Literal.Date */
148
+ .highlight .m { color: #ae81ff } /* Literal.Number */
149
+ .highlight .s { color: #e6db74 } /* Literal.String */
150
+ .highlight .na { color: #a6e22e } /* Name.Attribute */
151
+ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */
152
+ .highlight .nc { color: #a6e22e } /* Name.Class */
153
+ .highlight .no { color: #66d9ef } /* Name.Constant */
154
+ .highlight .nd { color: #a6e22e } /* Name.Decorator */
155
+ .highlight .ni { color: #f8f8f2 } /* Name.Entity */
156
+ .highlight .ne { color: #a6e22e } /* Name.Exception */
157
+ .highlight .nf { color: #a6e22e } /* Name.Function */
158
+ .highlight .nl { color: #f8f8f2 } /* Name.Label */
159
+ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */
160
+ .highlight .nx { color: #a6e22e } /* Name.Other */
161
+ .highlight .py { color: #f8f8f2 } /* Name.Property */
162
+ .highlight .nt { color: #f92672 } /* Name.Tag */
163
+ .highlight .nv { color: #f8f8f2 } /* Name.Variable */
164
+ .highlight .ow { color: #f92672 } /* Operator.Word */
165
+ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */
166
+ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
167
+ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */
168
+ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
169
+ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
170
+ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
171
+ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */
172
+ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
173
+ .highlight .sc { color: #e6db74 } /* Literal.String.Char */
174
+ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
175
+ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */
176
+ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */
177
+ .highlight .se { color: #ae81ff } /* Literal.String.Escape */
178
+ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
179
+ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */
180
+ .highlight .sx { color: #e6db74 } /* Literal.String.Other */
181
+ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */
182
+ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */
183
+ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
184
+ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
185
+ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */
186
+ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
187
+ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
188
+ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
189
+ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
190
+ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
assets/custom.js ADDED
@@ -0,0 +1 @@
 
 
1
+ // custom javascript here
assets/favicon.ico ADDED
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradio @ https://gradio-builds.s3.amazonaws.com/reset-iterator/attempt-01/gradio-3.24.1-py3-none-any.whl
2
+ mdtex2html
3
+ pypinyin
4
+ tiktoken
5
+ socksio
6
+ tqdm
7
+ colorama
8
+ duckduckgo_search
9
+ Pygments
10
+ llama_index
11
+ langchain
12
+ markdown
13
+ markdown2
14
+ torch
15
+ git+https://github.com/huggingface/peft.git
16
+ git+https://github.com/huggingface/transformers.git
17
+ SentencePiece