tomato commited on
Commit
17409ce
β€’
1 Parent(s): 7d93f13

use another kind of gradio interface

Browse files
Files changed (2) hide show
  1. app.py +19 -40
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,6 +1,4 @@
1
  import gradio as gr
2
- import torch
3
- from tqdm import tqdm
4
  import re
5
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
6
 
@@ -12,47 +10,28 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
12
  model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
13
 
14
  def summarize(text):
 
15
 
16
- input_ids = tokenizer(
17
- [WHITESPACE_HANDLER(text)],
18
- return_tensors="pt",
19
- padding="max_length",
20
- truncation=True,
21
- max_length=512
22
- )["input_ids"]
23
-
24
- output_ids = model.generate(
25
- input_ids=input_ids,
26
- max_length=84,
27
- no_repeat_ngram_size=2,
28
- num_beams=4
29
- )[0]
30
-
31
- summary = tokenizer.decode(
32
- output_ids,
33
- skip_special_tokens=True,
34
- clean_up_tokenization_spaces=False
35
- )
36
  return summary
37
 
38
 
39
-
40
- demo = gr.Blocks(title="⭐ Summ4rizer ⭐")
41
- demo.encrypt = False
42
-
43
- with demo:
44
- gr.Markdown(f'''
45
- <div>
46
- <h1 style='text-align: center'>Text Summarizer</h1>
47
- </div>
48
- <div>
49
- Using summarization Model from <a href='https://huggingface.co/{MODEL_NAME}' target='_blank'><b>{MODEL_NAME}</b></a>.
50
- </div>
51
- ''')
52
- text = gr.Textbox(label="Text here !!", lines=1, interactive=True)
53
- summarize_btn = gr.Button("Let's Summarize",)
54
- summarization = gr.Textbox()
55
- html_output = gr.Markdown()
56
- summarize_btn.click(summarize, [text], outputs=[html_output, summarization])
57
 
58
  demo.launch()
 
1
  import gradio as gr
 
 
2
  import re
3
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
 
 
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 🎈",
35
+ enable_queue=True)
 
 
 
 
 
 
 
 
 
36
 
37
  demo.launch()
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  gradio
2
  torch
3
  tqdm
4
- transformers
 
 
1
  gradio
2
  torch
3
  tqdm
4
+ transformers
5
+ sentencepiece