multimodalart HF staff commited on
Commit
4d88461
1 Parent(s): 2e1e801

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoTokenizer
2
+ import gradio as gr
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
5
+ model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
6
+ model = model.eval()
7
+
8
+ def predict(input, history=None):
9
+ if history is None:
10
+ history = []
11
+ response, history = model.chat(tokenizer, input, history)
12
+ return history, history
13
+
14
+
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown('''## ChatGLM-6B - unofficial demo
17
+ Unnoficial demo of the [ChatGLM-6B](https://github.com/THUDM/ChatGLM-6B/blob/main/README_en.md) model, trained on 1T tokens of English and Chinese
18
+ ''')
19
+ state = gr.State([])
20
+ chatbot = gr.Chatbot([], elem_id="chatbot").style(height=500)
21
+ with gr.Row():
22
+ with gr.Column(scale=4):
23
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
24
+ with gr.Column(scale=1):
25
+ button = gr.Button("Generate")
26
+ txt.submit(predict, [txt, state], [chatbot, state])
27
+ button.click(predict, [txt, state], [chatbot, state])
28
+ demo.queue().launch()