netist commited on
Commit
d9bdbf3
·
1 Parent(s): c794577

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -1,13 +1,30 @@
 
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModel
 
 
3
  tokenizer = AutoTokenizer.from_pretrained("silver/chatglm-6b-slim", trust_remote_code=True)
4
  model = AutoModel.from_pretrained("silver/chatglm-6b-slim", trust_remote_code=True).half().cuda()
5
 
6
- def greet(name):
7
- response, history = model.chat(tokenizer, "你好", history=[])
8
- #return "Hello " + name + "!!"
9
- return response
10
-
11
 
12
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
13
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  tokenizer = AutoTokenizer.from_pretrained("silver/chatglm-6b-slim", trust_remote_code=True)
7
  model = AutoModel.from_pretrained("silver/chatglm-6b-slim", trust_remote_code=True).half().cuda()
8
 
 
 
 
 
 
9
 
10
+ model = model.eval()
11
+
12
+ def predict(input, history=None):
13
+ if history is None:
14
+ history = []
15
+ response, history = model.chat(tokenizer, input, history)
16
+ return history, history
17
+
18
+
19
+ with gr.Blocks() as demo:
20
+
21
+ state = gr.State([])
22
+ chatbot = gr.Chatbot([], elem_id="chatbot").style(height=400)
23
+ with gr.Row():
24
+ with gr.Column(scale=4):
25
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
26
+ with gr.Column(scale=1):
27
+ button = gr.Button("Generate")
28
+ txt.submit(predict, [txt, state], [chatbot, state])
29
+ button.click(predict, [txt, state], [chatbot, state])
30
+ demo.queue().launch()