Spaces:
Build error
Build error
Use int4
Browse files- app.py +9 -7
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,20 +1,22 @@
|
|
| 1 |
-
import
|
| 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 |
-
|
|
|
|
| 9 |
|
| 10 |
def chat(query, history=[]):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return chat_list, history
|
| 14 |
|
| 15 |
-
description = "This is an unofficial chatbot application based on open source model ChatGLM-6B, running on cpu(
|
| 16 |
title = "ChatGLM-6B Chatbot"
|
| 17 |
-
examples = [["Hello?"]]
|
| 18 |
|
| 19 |
chatbot_interface = gr.Interface(
|
| 20 |
fn=chat,
|
|
|
|
| 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", revison="int4", trust_remote_code=True).cpu().float()
|
| 12 |
|
| 13 |
def chat(query, history=[]):
|
| 14 |
+
_, history = model.chat(tokenizer, query, history, max_length=512)
|
| 15 |
+
return history, history
|
|
|
|
| 16 |
|
| 17 |
+
description = "This is an unofficial chatbot application based on open source model ChatGLM-6B(https://github.com/THUDM/ChatGLM-6B), running on cpu(therefore max_length is limited to 512). \nIf you want to use this chat bot in your space, 'Duplicate this space' by click the button close to 'Linked Models'. \n"
|
| 18 |
title = "ChatGLM-6B Chatbot"
|
| 19 |
+
examples = [["Hello?"], ["你好。"], ["介绍清华"]]
|
| 20 |
|
| 21 |
chatbot_interface = gr.Interface(
|
| 22 |
fn=chat,
|
requirements.txt
CHANGED
|
@@ -4,3 +4,4 @@ protobuf>=3.19.5,<3.20.1
|
|
| 4 |
transformers>=4.26.1
|
| 5 |
icetk
|
| 6 |
cpm_kernels
|
|
|
|
|
|
| 4 |
transformers>=4.26.1
|
| 5 |
icetk
|
| 6 |
cpm_kernels
|
| 7 |
+
psutil
|