duxb commited on
Commit
8c6510a
1 Parent(s): b1d56c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
app.py CHANGED
@@ -10,23 +10,18 @@ MAX_TURNS = 20
10
  MAX_BOXES = MAX_TURNS * 2
11
 
12
 
13
- def predict(input, max_length, top_p, temperature, history=None, state=None):
14
- if state is None:
15
- state = []
16
- if history is None or history == "":
17
- history = state
18
- else:
19
- history = json.loads(history)
20
-
21
- for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p,
22
- temperature=temperature):
23
- updates = []
24
- for query, response in history:
25
- updates.append(gr.update(visible=True, value=query))
26
- updates.append(gr.update(visible=True, value=response))
27
- if len(updates) < MAX_BOXES:
28
- updates = updates + [gr.Textbox.update(visible=False)] * (MAX_BOXES - len(updates))
29
- yield [history] + updates
30
 
31
 
32
  with gr.Blocks() as demo:
 
10
  MAX_BOXES = MAX_TURNS * 2
11
 
12
 
13
+ def predict(input, max_length, top_p, temperature, history=None):
14
+ if history is None:
15
+ history = []
16
+ response, history = model.chat(tokenizer, input, history, max_length=max_length, top_p=top_p,
17
+ temperature=temperature)
18
+ updates = []
19
+ for query, response in history:
20
+ updates.append(gr.update(visible=True, value="用户:" + query))
21
+ updates.append(gr.update(visible=True, value="ChatGLM-6B:" + response))
22
+ if len(updates) < MAX_BOXES:
23
+ updates = updates + [gr.Textbox.update(visible=False)] * (MAX_BOXES - len(updates))
24
+ return [history] + updates
 
 
 
 
 
25
 
26
 
27
  with gr.Blocks() as demo: