kyserS09 commited on
Commit
bbb8ec0
·
verified ·
1 Parent(s): a2dfd02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -1,22 +1,34 @@
1
  import gradio as gr
2
- from transformers import BartTokenizer, BartForConditionalGeneration
3
 
4
- model_name = "facebook/bart-large-cnn"
5
- tokenizer = BartTokenizer.from_pretrained(model_name)
6
- model = BartForConditionalGeneration.from_pretrained(model_name)
 
7
 
8
  def summarize_text(text):
9
- inputs = tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
10
- summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=128, early_stopping=True)
 
 
 
 
 
 
 
 
 
 
11
  summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
12
  return summary
13
 
 
14
  iface = gr.Interface(
15
  fn=summarize_text,
16
  inputs="text",
17
  outputs="text",
18
- title="BART Summarizer",
19
- description="Enter text to get a summary using Facebook BART."
20
  )
21
 
22
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from transformers import LEDTokenizer, LEDForConditionalGeneration
3
 
4
+ # Use Longformer Encoder-Decoder (LED) model
5
+ model_name = "allenai/led-large-16384"
6
+ tokenizer = LEDTokenizer.from_pretrained(model_name)
7
+ model = LEDForConditionalGeneration.from_pretrained(model_name)
8
 
9
  def summarize_text(text):
10
+ # Tokenize input with truncation to fit within 16,384 tokens
11
+ inputs = tokenizer([text], max_length=16384, return_tensors="pt", truncation=True)
12
+
13
+ # Generate summary with adjusted parameters
14
+ summary_ids = model.generate(
15
+ inputs["input_ids"],
16
+ num_beams=4,
17
+ max_length=512, # Can be adjusted based on summary size needs
18
+ min_length=100,
19
+ early_stopping=True
20
+ )
21
+
22
  summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
23
  return summary
24
 
25
+ # Gradio Interface
26
  iface = gr.Interface(
27
  fn=summarize_text,
28
  inputs="text",
29
  outputs="text",
30
+ title="Longformer Summarizer",
31
+ description="Enter text to get a summary using the Longformer Encoder-Decoder."
32
  )
33
 
34
  if __name__ == "__main__":