songxxzp commited on
Commit
c502ed1
·
1 Parent(s): b10acc6
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+
4
+ from functools import partial
5
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
8
+ model = AutoModelForSeq2SeqLM.from_pretrained("THUDM/chatglm-6b", revision="int4", trust_remote_code=True).cpu().float()
9
+
10
+ def chat(query, history=[]):
11
+ response = model.chat(tokenizer, query, history, max_length=32)
12
+ chat_list = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
13
+ return chat_list, history
14
+
15
+ description = "This is an unofficial chatbot application based on open source model ChatGLM-6B, running on cpu(hence max_length is limited to 32)."
16
+ title = "ChatGLM-6B Chatbot"
17
+ examples = [["Hello?"]]
18
+
19
+ chatbot_interface = gr.Interface(
20
+ fn=chat,
21
+ title=title,
22
+ description=description,
23
+ examples=examples,
24
+ inputs=["text", "state"],
25
+ outputs=["chatbot", "state"]
26
+ )
27
+
28
+ chatbot_interface.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ protobuf>=3.19.5,<3.20.1
4
+ transformers>=4.26.1
5
+ icetk
6
+ cpm_kernels