Spaces:
Runtime error
Runtime error
add application files
Browse files- app.py +24 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModel, AutoTokenizer
|
2 |
+
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True)
|
3 |
+
model = AutoModel.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True).half().cuda()
|
4 |
+
model = model.eval()
|
5 |
+
|
6 |
+
def beginchat(input, history=None):
|
7 |
+
if history is None:
|
8 |
+
history = []
|
9 |
+
response, history = model.chat(tokenizer, input, history)
|
10 |
+
return history, history
|
11 |
+
|
12 |
+
|
13 |
+
with gr.Blocks() as chatglm2bot:
|
14 |
+
gr.Markdown('''## ChatGLM2-6B - chatbot demo''')
|
15 |
+
state = gr.State([])
|
16 |
+
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=400)
|
17 |
+
with gr.Row():
|
18 |
+
with gr.Column(scale=4):
|
19 |
+
txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
|
20 |
+
with gr.Column(scale=1):
|
21 |
+
button = gr.Button("Generate")
|
22 |
+
txt.submit(beginchat, [txt, state], [chatbot, state])
|
23 |
+
button.click(beginchat, [txt, state], [chatbot, state])
|
24 |
+
chatglm2bot.queue().launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers>=4.26.1
|
3 |
+
cpm_kernels
|
4 |
+
icetk
|