duxb justest commited on
Commit
90670b4
0 Parent(s):

Duplicate from justest/chatglm-6b

Browse files

Co-authored-by: lw <justest@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +52 -0
  4. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Chatglm 6b
3
+ emoji: 🌖
4
+ colorFrom: blue
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.24.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: justest/chatglm-6b
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoTokenizer
2
+ import gradio as gr
3
+ import json
4
+ model_path = 'THUDM/chatglm-6b-int4-qe'
5
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
6
+ model = AutoModel.from_pretrained(model_path, trust_remote_code=True).half().float()
7
+ model = model.eval()
8
+
9
+ MAX_TURNS = 20
10
+ MAX_BOXES = MAX_TURNS * 2
11
+
12
+
13
+ def predict(input, max_length, top_p, temperature, history=None, state=None):
14
+ if state is None:
15
+ state = []
16
+ if history is None or history == "":
17
+ history = state
18
+ else:
19
+ history = json.loads(history)
20
+
21
+ for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p,
22
+ temperature=temperature):
23
+ updates = []
24
+ for query, response in history:
25
+ updates.append(gr.update(visible=True, value=query))
26
+ updates.append(gr.update(visible=True, value=response))
27
+ if len(updates) < MAX_BOXES:
28
+ updates = updates + [gr.Textbox.update(visible=False)] * (MAX_BOXES - len(updates))
29
+ yield [history] + updates
30
+
31
+
32
+ with gr.Blocks() as demo:
33
+ state = gr.State([])
34
+ text_boxes = []
35
+ for i in range(MAX_BOXES):
36
+ if i % 2 == 0:
37
+ text_boxes.append(gr.Text(visible=False, label="提问:"))
38
+ else:
39
+ text_boxes.append(gr.Text(visible=False, label="回复:"))
40
+
41
+ with gr.Row():
42
+ with gr.Column(scale=4):
43
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter", lines=11).style(
44
+ container=False)
45
+ with gr.Column(scale=1):
46
+ max_length = gr.Slider(0, 4096, value=2048, step=1.0, label="Maximum length", interactive=True)
47
+ top_p = gr.Slider(0, 1, value=0.7, step=0.01, label="Top P", interactive=True)
48
+ temperature = gr.Slider(0, 1, value=0.95, step=0.01, label="Temperature", interactive=True)
49
+ history = gr.TextArea(visible=False)
50
+ button = gr.Button("Generate")
51
+ button.click(predict, [txt, max_length, top_p, temperature, history, state], [state] + text_boxes, queue=True)
52
+ demo.queue(concurrency_count=10).launch(enable_queue=True, max_threads=2)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ transformers>=4.26.1
3
+ cpm_kernels
4
+ icetk