DrSong commited on
Commit
ad76258
1 Parent(s): b10acc6

Add app.py and requirements.txt

Browse files
Files changed (2) hide show
  1. app.py +30 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import psutil
2
+ import gradio as gr
3
+
4
+ from functools import partial
5
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
6
+
7
+ mem = psutil.virtual_memory()
8
+
9
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
10
+
11
+ model = AutoModelForSeq2SeqLM.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).bfloat16()
12
+
13
+ def chat(query, history=[]):
14
+ _, history = model.chat(tokenizer, query, history, max_length=32)
15
+ return history, history
16
+
17
+ description = "This is an unofficial chatbot application based on open source model ChatGLM-6B, running on cpu(hence max_length is limited to 32)."
18
+ title = "ChatGLM-6B Chatbot"
19
+ examples = [["Hello?"], ["你好。"], ["介绍清华"]]
20
+
21
+ chatbot_interface = gr.Interface(
22
+ fn=chat,
23
+ title=title,
24
+ description=description,
25
+ examples=examples,
26
+ inputs=["text", "state"],
27
+ outputs=["chatbot", "state"]
28
+ )
29
+
30
+ chatbot_interface.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ protobuf>=3.19.5,<3.20.1
4
+ transformers>=4.26.1
5
+ icetk
6
+ cpm_kernels
7
+ psutil