Compare commits
11 Commits
chatpaper-
...
master-lat
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c0d34793e | |||
| 41c10f5688 | |||
| d7ac99f603 | |||
| 1616daae6a | |||
| a1092d8f92 | |||
| 34ca9f138f | |||
| df3f1aa3ca | |||
| bf805cf477 | |||
| ecb08e69be | |||
| 28c1e3f11b | |||
| 403667aec1 |
@ -56,6 +56,9 @@ LOCAL_MODEL_DEVICE = "cpu" # 可选 "cuda"
|
|||||||
# 设置gradio的并行线程数(不需要修改)
|
# 设置gradio的并行线程数(不需要修改)
|
||||||
CONCURRENT_COUNT = 100
|
CONCURRENT_COUNT = 100
|
||||||
|
|
||||||
|
# 是否在提交时自动清空输入框
|
||||||
|
AUTO_CLEAR_TXT = False
|
||||||
|
|
||||||
# 加一个live2d装饰
|
# 加一个live2d装饰
|
||||||
ADD_WAIFU = False
|
ADD_WAIFU = False
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,7 @@ def get_core_functions():
|
|||||||
"Prefix": r"我需要你找一张网络图片。使用Unsplash API(https://source.unsplash.com/960x640/?<英语关键词>)获取图片URL," +
|
"Prefix": r"我需要你找一张网络图片。使用Unsplash API(https://source.unsplash.com/960x640/?<英语关键词>)获取图片URL," +
|
||||||
r"然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送图片:" + "\n\n",
|
r"然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送图片:" + "\n\n",
|
||||||
"Suffix": r"",
|
"Suffix": r"",
|
||||||
|
"Visible": False,
|
||||||
},
|
},
|
||||||
"解释代码": {
|
"解释代码": {
|
||||||
"Prefix": r"请解释以下代码:" + "\n```\n",
|
"Prefix": r"请解释以下代码:" + "\n```\n",
|
||||||
@ -73,6 +74,5 @@ def get_core_functions():
|
|||||||
r"Note that, reference styles maybe more than one kind, you should transform each item correctly." +
|
r"Note that, reference styles maybe more than one kind, you should transform each item correctly." +
|
||||||
r"Items need to be transformed:",
|
r"Items need to be transformed:",
|
||||||
"Suffix": r"",
|
"Suffix": r"",
|
||||||
"Visible": False,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -195,7 +195,7 @@ def test_Latex():
|
|||||||
# txt = r"https://arxiv.org/abs/2303.08774"
|
# txt = r"https://arxiv.org/abs/2303.08774"
|
||||||
# txt = r"https://arxiv.org/abs/2303.12712"
|
# txt = r"https://arxiv.org/abs/2303.12712"
|
||||||
# txt = r"C:\Users\fuqingxu\arxiv_cache\2303.12712\workfolder"
|
# txt = r"C:\Users\fuqingxu\arxiv_cache\2303.12712\workfolder"
|
||||||
txt = r"C:\Users\fuqingxu\Desktop\9"
|
txt = r"2306.17157" # 这个paper有个input命令文件名大小写错误!
|
||||||
|
|
||||||
|
|
||||||
for cookies, cb, hist, msg in (Latex翻译中文并重新编译PDF)(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
|
for cookies, cb, hist, msg in (Latex翻译中文并重新编译PDF)(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
|
||||||
|
|||||||
@ -189,6 +189,18 @@ def rm_comments(main_file):
|
|||||||
main_file = re.sub(r'(?<!\\)%.*', '', main_file) # 使用正则表达式查找半行注释, 并替换为空字符串
|
main_file = re.sub(r'(?<!\\)%.*', '', main_file) # 使用正则表达式查找半行注释, 并替换为空字符串
|
||||||
return main_file
|
return main_file
|
||||||
|
|
||||||
|
def find_tex_file_ignore_case(fp):
|
||||||
|
dir_name = os.path.dirname(fp)
|
||||||
|
base_name = os.path.basename(fp)
|
||||||
|
if not base_name.endswith('.tex'): base_name+='.tex'
|
||||||
|
if os.path.exists(pj(dir_name, base_name)): return pj(dir_name, base_name)
|
||||||
|
# go case in-sensitive
|
||||||
|
import glob
|
||||||
|
for f in glob.glob(dir_name+'/*.tex'):
|
||||||
|
base_name_s = os.path.basename(fp)
|
||||||
|
if base_name_s.lower() == base_name.lower(): return f
|
||||||
|
return None
|
||||||
|
|
||||||
def merge_tex_files_(project_foler, main_file, mode):
|
def merge_tex_files_(project_foler, main_file, mode):
|
||||||
"""
|
"""
|
||||||
Merge Tex project recrusively
|
Merge Tex project recrusively
|
||||||
@ -197,14 +209,11 @@ def merge_tex_files_(project_foler, main_file, mode):
|
|||||||
for s in reversed([q for q in re.finditer(r"\\input\{(.*?)\}", main_file, re.M)]):
|
for s in reversed([q for q in re.finditer(r"\\input\{(.*?)\}", main_file, re.M)]):
|
||||||
f = s.group(1)
|
f = s.group(1)
|
||||||
fp = os.path.join(project_foler, f)
|
fp = os.path.join(project_foler, f)
|
||||||
if os.path.exists(fp):
|
fp = find_tex_file_ignore_case(fp)
|
||||||
# e.g., \input{srcs/07_appendix.tex}
|
if fp:
|
||||||
with open(fp, 'r', encoding='utf-8', errors='replace') as fx:
|
with open(fp, 'r', encoding='utf-8', errors='replace') as fx: c = fx.read()
|
||||||
c = fx.read()
|
else:
|
||||||
else:
|
raise RuntimeError(f'找不到{fp},Tex源文件缺失!')
|
||||||
# e.g., \input{srcs/07_appendix}
|
|
||||||
with open(fp+'.tex', 'r', encoding='utf-8', errors='replace') as fx:
|
|
||||||
c = fx.read()
|
|
||||||
c = merge_tex_files_(project_foler, c, mode)
|
c = merge_tex_files_(project_foler, c, mode)
|
||||||
main_file = main_file[:s.span()[0]] + c + main_file[s.span()[1]:]
|
main_file = main_file[:s.span()[0]] + c + main_file[s.span()[1]:]
|
||||||
return main_file
|
return main_file
|
||||||
|
|||||||
@ -27,8 +27,10 @@ def gen_image(llm_kwargs, prompt, resolution="256x256"):
|
|||||||
}
|
}
|
||||||
response = requests.post(url, headers=headers, json=data, proxies=proxies)
|
response = requests.post(url, headers=headers, json=data, proxies=proxies)
|
||||||
print(response.content)
|
print(response.content)
|
||||||
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
|
try:
|
||||||
|
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
|
||||||
|
except:
|
||||||
|
raise RuntimeError(response.content.decode())
|
||||||
# 文件保存到本地
|
# 文件保存到本地
|
||||||
r = requests.get(image_url, proxies=proxies)
|
r = requests.get(image_url, proxies=proxies)
|
||||||
file_path = 'gpt_log/image_gen/'
|
file_path = 'gpt_log/image_gen/'
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from toolbox import CatchException, report_execption, write_results_to_file
|
from toolbox import CatchException, report_execption, write_results_to_file
|
||||||
from toolbox import update_ui
|
from toolbox import update_ui, promote_file_to_downloadzone
|
||||||
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
|
||||||
from .crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
|
from .crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
|
||||||
from .crazy_utils import read_and_clean_pdf_text
|
from .crazy_utils import read_and_clean_pdf_text
|
||||||
@ -147,23 +147,14 @@ def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot,
|
|||||||
print('writing html result failed:', trimmed_format_exc())
|
print('writing html result failed:', trimmed_format_exc())
|
||||||
|
|
||||||
# 准备文件的下载
|
# 准备文件的下载
|
||||||
import shutil
|
|
||||||
for pdf_path in generated_conclusion_files:
|
for pdf_path in generated_conclusion_files:
|
||||||
# 重命名文件
|
# 重命名文件
|
||||||
rename_file = f'./gpt_log/翻译-{os.path.basename(pdf_path)}'
|
rename_file = f'翻译-{os.path.basename(pdf_path)}'
|
||||||
if os.path.exists(rename_file):
|
promote_file_to_downloadzone(pdf_path, rename_file=rename_file, chatbot=chatbot)
|
||||||
os.remove(rename_file)
|
|
||||||
shutil.copyfile(pdf_path, rename_file)
|
|
||||||
if os.path.exists(pdf_path):
|
|
||||||
os.remove(pdf_path)
|
|
||||||
for html_path in generated_html_files:
|
for html_path in generated_html_files:
|
||||||
# 重命名文件
|
# 重命名文件
|
||||||
rename_file = f'./gpt_log/翻译-{os.path.basename(html_path)}'
|
rename_file = f'翻译-{os.path.basename(html_path)}'
|
||||||
if os.path.exists(rename_file):
|
promote_file_to_downloadzone(html_path, rename_file=rename_file, chatbot=chatbot)
|
||||||
os.remove(rename_file)
|
|
||||||
shutil.copyfile(html_path, rename_file)
|
|
||||||
if os.path.exists(html_path):
|
|
||||||
os.remove(html_path)
|
|
||||||
chatbot.append(("给出输出文件清单", str(generated_conclusion_files + generated_html_files)))
|
chatbot.append(("给出输出文件清单", str(generated_conclusion_files + generated_html_files)))
|
||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
|
|
||||||
|
|||||||
11
main.py
11
main.py
@ -6,8 +6,8 @@ def main():
|
|||||||
from request_llm.bridge_all import predict
|
from request_llm.bridge_all import predict
|
||||||
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, DummyWith
|
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, DummyWith
|
||||||
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
||||||
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY, AVAIL_LLM_MODELS = \
|
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = \
|
||||||
get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'API_KEY', 'AVAIL_LLM_MODELS')
|
get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'API_KEY', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT')
|
||||||
|
|
||||||
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
||||||
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
||||||
@ -104,7 +104,7 @@ def main():
|
|||||||
system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt)
|
system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt)
|
||||||
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
||||||
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
||||||
max_length_sl = gr.Slider(minimum=256, maximum=4096, value=512, step=1, interactive=True, label="Local LLM MaxLength",)
|
max_length_sl = gr.Slider(minimum=256, maximum=8192, value=4096, step=1, interactive=True, label="Local LLM MaxLength",)
|
||||||
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
|
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
|
||||||
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
|
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
|
||||||
|
|
||||||
@ -144,6 +144,11 @@ def main():
|
|||||||
resetBtn2.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
resetBtn2.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
||||||
clearBtn.click(lambda: ("",""), None, [txt, txt2])
|
clearBtn.click(lambda: ("",""), None, [txt, txt2])
|
||||||
clearBtn2.click(lambda: ("",""), None, [txt, txt2])
|
clearBtn2.click(lambda: ("",""), None, [txt, txt2])
|
||||||
|
if AUTO_CLEAR_TXT:
|
||||||
|
submitBtn.click(lambda: ("",""), None, [txt, txt2])
|
||||||
|
submitBtn2.click(lambda: ("",""), None, [txt, txt2])
|
||||||
|
txt.submit(lambda: ("",""), None, [txt, txt2])
|
||||||
|
txt2.submit(lambda: ("",""), None, [txt, txt2])
|
||||||
# 基础功能区的回调函数注册
|
# 基础功能区的回调函数注册
|
||||||
for k in functional:
|
for k in functional:
|
||||||
if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue
|
if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue
|
||||||
|
|||||||
@ -152,7 +152,7 @@ model_info = {
|
|||||||
"token_cnt": get_token_num_gpt4,
|
"token_cnt": get_token_num_gpt4,
|
||||||
},
|
},
|
||||||
|
|
||||||
# chatglm
|
# 将 chatglm 直接对齐到 chatglm2
|
||||||
"chatglm": {
|
"chatglm": {
|
||||||
"fn_with_ui": chatglm_ui,
|
"fn_with_ui": chatglm_ui,
|
||||||
"fn_without_ui": chatglm_noui,
|
"fn_without_ui": chatglm_noui,
|
||||||
@ -161,6 +161,15 @@ model_info = {
|
|||||||
"tokenizer": tokenizer_gpt35,
|
"tokenizer": tokenizer_gpt35,
|
||||||
"token_cnt": get_token_num_gpt35,
|
"token_cnt": get_token_num_gpt35,
|
||||||
},
|
},
|
||||||
|
"chatglm2": {
|
||||||
|
"fn_with_ui": chatglm_ui,
|
||||||
|
"fn_without_ui": chatglm_noui,
|
||||||
|
"endpoint": None,
|
||||||
|
"max_token": 1024,
|
||||||
|
"tokenizer": tokenizer_gpt35,
|
||||||
|
"token_cnt": get_token_num_gpt35,
|
||||||
|
},
|
||||||
|
|
||||||
# newbing
|
# newbing
|
||||||
"newbing": {
|
"newbing": {
|
||||||
"fn_with_ui": newbing_ui,
|
"fn_with_ui": newbing_ui,
|
||||||
|
|||||||
@ -40,12 +40,12 @@ class GetGLMHandle(Process):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if self.chatglm_model is None:
|
if self.chatglm_model is None:
|
||||||
self.chatglm_tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
|
self.chatglm_tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True)
|
||||||
device, = get_conf('LOCAL_MODEL_DEVICE')
|
device, = get_conf('LOCAL_MODEL_DEVICE')
|
||||||
if device=='cpu':
|
if device=='cpu':
|
||||||
self.chatglm_model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).float()
|
self.chatglm_model = AutoModel.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True).float()
|
||||||
else:
|
else:
|
||||||
self.chatglm_model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
|
self.chatglm_model = AutoModel.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True).half().cuda()
|
||||||
self.chatglm_model = self.chatglm_model.eval()
|
self.chatglm_model = self.chatglm_model.eval()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user