tomato commited on
Commit
e91f2c0
1 Parent(s): 17409ce

transfer from [csebuetnlp/mT5_multilingual_XLSum] to [silver/chatglm-6b-int4-slim]

Browse files
Files changed (2) hide show
  1. app.py +21 -20
  2. requirements.txt +5 -1
app.py CHANGED
@@ -1,34 +1,35 @@
1
  import gradio as gr
2
  import re
3
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
 
5
- MODEL_NAME = "csebuetnlp/mT5_multilingual_XLSum"
6
 
7
- WHITESPACE_HANDLER = lambda k: re.sub('\s+', ' ', re.sub('\n+', ' ', k.strip()))
 
8
 
9
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
10
- model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
11
-
12
- def summarize(text):
13
- text = WHITESPACE_HANDLER(text)
14
 
15
- inputs = tokenizer(text,
16
- max_length=1024,
17
- truncation=True,
18
- return_tensors="pt")
 
 
19
 
20
- summary_ids = model.generate(inputs["input_ids"])
21
- summary = tokenizer.batch_decode(summary_ids,
22
- skip_special_tokens=True,
23
- clean_up_tokenization_spaces=False)
24
- return summary
25
 
26
 
27
  demo = gr.Interface(fn = summarize,
28
  inputs = [gr.inputs.Textbox(lines=10,
29
- placeholder="Inpuy something...",
30
- label='Text here !!')],
31
- outputs = [gr.outputs.Textbox(
 
 
 
 
 
32
  label="Summary")],
33
 
34
  title = "🎈 Summarizer 🎈",
 
1
  import gradio as gr
2
  import re
3
+ from transformers import AutoTokenizer, AutoModel
4
 
5
+ MODEL_NAME = "silver/chatglm-6b-int4-slim"
6
 
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
8
+ model = AutoModel.from_pretrained(MODEL_NAME, trust_remote_code=True).half().cuda()
9
 
10
+ def summarize(transcript, sentence_count):
11
+ history = []
 
 
 
12
 
13
+ prompt = f"""
14
+ 视频脚本:{transcript}
15
+ 我希望你作为一名专业的视频内容编辑,帮我用中文总结视频脚本的内容精华。请先用一句简短的话总结视频梗概。然后再请你将视频字幕文本进行总结(字幕中可能有错别字,如果你发现了错别字请改正)。请你以无序列表的方式返回,请注意不要超过{sentence_count}条哦,确保所有的句子都足够精简,清晰完整,祝你好运!
16
+ """
17
+
18
+ response, history = model.chat(tokenizer, prompt, history=history)
19
 
20
+ return response
 
 
 
 
21
 
22
 
23
  demo = gr.Interface(fn = summarize,
24
  inputs = [gr.inputs.Textbox(lines=10,
25
+ placeholder="Input something...",
26
+ label='Text here !!'),
27
+ gr.inputs.Slider(minimum=1,
28
+ maximum=10,
29
+ value=5,
30
+ step=1,
31
+ label='Sentence Count')],
32
+ outputs = [gr.outputs.Textbox(lines=10,
33
  label="Summary")],
34
 
35
  title = "🎈 Summarizer 🎈",
requirements.txt CHANGED
@@ -2,4 +2,8 @@ gradio
2
  torch
3
  tqdm
4
  transformers
5
- sentencepiece
 
 
 
 
 
2
  torch
3
  tqdm
4
  transformers
5
+ sentencepiece
6
+ protobuf==3.20.0
7
+ transformers==4.26.1
8
+ icetk
9
+ cpm_kernels