blackbingris commited on
Commit
a09c22e
·
1 Parent(s): 33c94a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+
5
+
6
+
7
+ os.system(
8
+ 'pip install --upgrade torch'
9
+ )
10
+ os.system(
11
+ 'pip install "modelscope" --upgrade -f https://pypi.org/project/modelscope/'
12
+ )
13
+
14
+ os.system('pip install transformers -U')
15
+
16
+ from modelscope.pipelines import pipeline
17
+ from modelscope.utils.constant import Tasks
18
+
19
+ pipe = pipeline(task=Tasks.chat, model='ZhipuAI/chatglm2-6b', model_revision='v1.0.2',device_map='auto')
20
+
21
+
22
+ def clear_session():
23
+ return '', None
24
+
25
+
26
+ def predict(input, history=None):
27
+ dictionary = {
28
+ 'prmpt': input
29
+ }
30
+ print(dictionary)
31
+ if history is None:
32
+ history = []
33
+ inputs = inputs = {'text': input, 'history': history}
34
+ result = pipe(inputs)
35
+ history = result['history']
36
+
37
+ return '', history, history
38
+
39
+
40
+ block = gr.Blocks()
41
+
42
+ with block as demo:
43
+ gr.Markdown("""<h1><center>ChatGLM-6B unofficial demo</center></h1>
44
+ <center><font size=3><a href='https://modelscope.cn/models/ZhipuAI/ChatGLM-6B/summary' target="_blank">ChatGLM-6B </a>是一个开源的、支持中英双语的对话语言模型,基于 General Language Model (GLM) 架构,具有 62 亿参数。</center></font>
45
+ """)
46
+ chatbot = gr.Chatbot(label='ChatGLM-6B')
47
+ message = gr.Textbox()
48
+ state = gr.State()
49
+ message.submit(predict,
50
+ inputs=[message, state],
51
+ outputs=[message, chatbot, state])
52
+ with gr.Row():
53
+ clear_history = gr.Button("🧹 清除历史对话")
54
+ send = gr.Button("🚀 发送")
55
+
56
+ send.click(predict,
57
+ inputs=[message, state],
58
+ outputs=[message, chatbot, state])
59
+ clear_history.click(fn=clear_session,
60
+ inputs=[],
61
+ outputs=[chatbot, state],
62
+ queue=False)
63
+
64
+ demo.queue().launch(height=800, share=False)