npc0 commited on
Commit
b88f9cf
·
verified ·
1 Parent(s): 8580815

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -29
app.py CHANGED
@@ -1,25 +1,14 @@
1
  import os
2
- import sys
3
  import subprocess
4
 
5
- if not os.path.exists("ChatGLM-6b-onnx-u8s8"):
6
- subprocess.run(["git", "lfs", "install"])
7
- subprocess.run(["git", "clone", "https://huggingface.co/K024/ChatGLM-6b-onnx-u8s8"])
8
- os.chdir("ChatGLM-6b-onnx-u8s8")
9
- subprocess.run(["pip", "install", "-r", "requirements.txt"])
10
- sys.path.append(os.getcwd())
11
- else:
12
- sys.path.append(os.path.join(os.getcwd(), "ChatGLM-6b-onnx-u8s8"))
13
 
14
- from model import ChatGLMModel#, chat_template
15
-
16
- model = ChatGLMModel()
17
  # history = []
18
 
19
- max_tokens = 2048
20
- temperature = 0.7
21
- top_p = 0.7
22
- top_k = 50
23
  prompt = """
24
  現在有些文本,文本詳細且複雜。 它包含細節,可以縮減和綜合為關鍵要點。 你的任務是提取最重要的概念,重點關注主要思路,提供一個概述而不失去精髓。 你的總結應該:
25
 
@@ -44,15 +33,13 @@ prompt = """
44
 
45
  def sum_chain_l1(text, p_bar):
46
  docs = []
47
- for i in p_bar(range(len(text)//2000+1)):
48
- t = text[i*2000:i*2000+2048]
49
  if len(t) > 0:
50
- for answer in model.generate_iterate(prompt+t,
51
- max_generated_tokens=max_tokens,
52
- top_k=top_k,
53
- top_p=top_p,
54
- temperature=temperature):
55
- yield f"{'='*8} {i+1}/{len(text)//2000+1} {'='*8}\n{answer}"
56
  docs.append(answer)
57
  yield docs
58
 
@@ -61,11 +48,9 @@ def sum_chain_l2_deprecated(docs, p_bar):
61
  i = 0
62
  for doc in p_bar(docs[1:]):
63
  i += 1
64
- for answer in model.generate_iterate(prompt+"\n"+hist+"\n"+doc,
65
- max_generated_tokens=max_tokens,
66
- top_k=top_k,
67
- top_p=top_p,
68
- temperature=temperature):
69
  yield f"{'='*8} {i}/{len(docs)} {'='*8}\n{answer}"
70
  hist = answer
71
  yield hist
 
1
  import os
 
2
  import subprocess
3
 
4
+ if not os.path.exists("chatglm4-ggml-int4.bin"):
5
+ os.system("wget https://huggingface.co/npc0/chatglm-4-9b-int4/resolve/main/chatglm4-ggml-int4.bin")
 
 
 
 
 
 
6
 
7
+ import chatglm_cpp
8
+ pipeline = chatglm_cpp.Pipeline("chatglm4-ggml-int4.bin")
9
+ # pipeline.chat([chatglm_cpp.ChatMessage(role="user", content="你好")])
10
  # history = []
11
 
 
 
 
 
12
  prompt = """
13
  現在有些文本,文本詳細且複雜。 它包含細節,可以縮減和綜合為關鍵要點。 你的任務是提取最重要的概念,重點關注主要思路,提供一個概述而不失去精髓。 你的總結應該:
14
 
 
33
 
34
  def sum_chain_l1(text, p_bar):
35
  docs = []
36
+ for i in p_bar(range(len(text)//8000+1)):
37
+ t = text[i*8000:i*8000+8196]
38
  if len(t) > 0:
39
+ for answer in pipeline.stream_chat(
40
+ chatglm_cpp.ChatMessage(role="user",
41
+ content=prompt+t)):
42
+ yield f"{'='*8} {i+1}/{len(text)//8000+1} {'='*8}\n{answer}"
 
 
43
  docs.append(answer)
44
  yield docs
45
 
 
48
  i = 0
49
  for doc in p_bar(docs[1:]):
50
  i += 1
51
+ for answer in pipeline.stream_chat(
52
+ chatglm_cpp.ChatMessage(role="user",
53
+ content=prompt+"\n"+hist+"\n"+doc)):
 
 
54
  yield f"{'='*8} {i}/{len(docs)} {'='*8}\n{answer}"
55
  hist = answer
56
  yield hist