Spaces:
Build error
Build error
Update app.py
Browse files1234567891011121314151617181920212223242518 unmodified lines4445464748495051525354555657582 unmodified lines6162636465666768697071import osimport sysimport subprocessif not os.path.exists("ChatGLM-6b-onnx-u8s8"):subprocess.run(["git", "lfs", "install"])subprocess.run(["git", "clone", "https://huggingface.co/K024/ChatGLM-6b-onnx-u8s8"])os.chdir("ChatGLM-6b-onnx-u8s8")subprocess.run(["pip", "install", "-r", "requirements.txt"])sys.path.append(os.getcwd())else:sys.path.append(os.path.join(os.getcwd(), "ChatGLM-6b-onnx-u8s8"))from model import ChatGLMModel#, chat_templatemodel = ChatGLMModel()# history = []max_tokens = 2048temperature = 0.7top_p = 0.7top_k = 50prompt = """現在有些文本,文本詳細且複雜。 它包含細節,可以縮減和綜合為關鍵要點。 你的任務是提取最重要的概念,重點關注主要思路,提供一個概述而不失去精髓。 你的總結應該:18 unmodified linesdef sum_chain_l1(text, p_bar):docs = []for i in p_bar(range(len(text)//2000+1)):t = text[i*2000:i*2000+2048]if len(t) > 0:for answer in model.generate_iterate(prompt+t,max_generated_tokens=max_tokens,top_k=top_k,top_p=top_p,temperature=temperature):yield f"{'='*8} {i+1}/{len(text)//2000+1} {'='*8}\n{answer}"docs.append(answer)yield docs2 unmodified linesi = 0for doc in p_bar(docs[1:]):i += 1for answer in model.generate_iterate(prompt+"\n"+hist+"\n"+doc,max_generated_tokens=max_tokens,top_k=top_k,top_p=top_p,temperature=temperature):yield f"{'='*8} {i}/{len(docs)} {'='*8}\n{answer}"hist = answeryield hist123456789101112131418 unmodified lines333435363738394041424344452 unmodified lines484950515253545556import osimport subprocessif not os.path.exists("chatglm4-ggml-int4.bin"):os.system("wget https://huggingface.co/npc0/chatglm-4-9b-int4/resolve/main/chatglm4-ggml-int4.bin")import chatglm_cpppipeline = chatglm_cpp.Pipeline("chatglm4-ggml-int4.bin")# pipeline.chat([chatglm_cpp.ChatMessage(role="user", content="你好")])# history = []prompt = """現在有些文本,文本詳細且複雜。 它包含細節,可以縮減和綜合為關鍵要點。 你的任務是提取最重要的概念,重點關注主要思路,提供一個概述而不失去精髓。 你的總結應該:18 unmodified linesdef sum_chain_l1(text, p_bar):docs = []for i in p_bar(range(len(text)//8000+1)):t = text[i*8000:i*8000+8196]if len(t) > 0:for answer in pipeline.stream_chat(chatglm_cpp.ChatMessage(role="user",content=prompt+t)):yield f"{'='*8} {i+1}/{len(text)//8000+1} {'='*8}\n{answer}"docs.append(answer)yield docs2 unmodified linesi = 0for doc in p_bar(docs[1:]):i += 1for answer in pipeline.stream_chat(chatglm_cpp.ChatMessage(role="user",content=prompt+"\n"+hist+"\n"+doc)):yield f"{'='*8} {i}/{len(docs)} {'='*8}\n{answer}"hist = answeryield hist
app.py+14-29