Spaces:
Runtime error
Runtime error
YanshekWoo
commited on
Commit
·
d2ed16f
1
Parent(s):
7b122f8
Initial app.py
Browse files
app.py
CHANGED
@@ -21,5 +21,36 @@
|
|
21 |
|
22 |
|
23 |
import gradio as gr
|
|
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
|
23 |
import gradio as gr
|
24 |
+
from transformers import BertTokenizer, BartForConditionalGeneration
|
25 |
|
26 |
+
|
27 |
+
title = "标题"
|
28 |
+
description = "描述"
|
29 |
+
|
30 |
+
|
31 |
+
tokenizer = BertTokenizer.from_pretrained("HIT-TMG/dialogue-bart-large-chinese")
|
32 |
+
model = BartForConditionalGeneration.from_pretrained("HIT-TMG/dialogue-bart-large-chinese")
|
33 |
+
|
34 |
+
|
35 |
+
def chat(history):
|
36 |
+
history_prefix = "对话历史:"
|
37 |
+
history = history_prefix + history
|
38 |
+
|
39 |
+
input_ids = tokenizer(history, return_tensors='pt').input_ids
|
40 |
+
output_ids = model.generate(input_ids)[0]
|
41 |
+
|
42 |
+
return tokenizer.decode(output_ids, skip_special_tokens=True)
|
43 |
+
|
44 |
+
|
45 |
+
chatbot = gr.Chatbot().style(color_map=("green", "pink"))
|
46 |
+
demo = gr.Interface(
|
47 |
+
chat,
|
48 |
+
inputs=gr.Textbox(lines=2, placeholder="输入你的对话历史"),
|
49 |
+
title=title,
|
50 |
+
description=description,
|
51 |
+
outputs =["text"]
|
52 |
+
)
|
53 |
+
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
demo.launch()
|