Update app.py
Browse files
app.py
CHANGED
|
@@ -20,20 +20,13 @@ def add_file(history, file):
|
|
| 20 |
return history
|
| 21 |
|
| 22 |
|
|
|
|
| 23 |
def bot(input_text):
|
| 24 |
-
# 将输入文本编码成token id
|
| 25 |
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
| 26 |
-
# 调用gpt-2模型生成输出token id,设置一些参数,如最大长度,温度,top_k等
|
| 27 |
output_ids = model.generate(input_ids, max_length=50, temperature=0.9, top_k=50)
|
| 28 |
-
# 将输出token id解码成文本
|
| 29 |
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 30 |
-
# 返回输出文本
|
| 31 |
response = output_text
|
| 32 |
-
|
| 33 |
-
for character in response:
|
| 34 |
-
input_text[-1][1] += character
|
| 35 |
-
time.sleep(0.05)
|
| 36 |
-
yield input_text
|
| 37 |
|
| 38 |
|
| 39 |
with gr.Blocks() as demo:
|
|
|
|
| 20 |
return history
|
| 21 |
|
| 22 |
|
| 23 |
+
|
| 24 |
def bot(input_text):
|
|
|
|
| 25 |
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
|
|
|
| 26 |
output_ids = model.generate(input_ids, max_length=50, temperature=0.9, top_k=50)
|
|
|
|
| 27 |
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
|
|
|
| 28 |
response = output_text
|
| 29 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
with gr.Blocks() as demo:
|