ar08 commited on
Commit
dcd6dd2
·
verified ·
1 Parent(s): 3c0c86a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -10,20 +10,25 @@ model_name = "Rahmat82/t5-small-finetuned-summarization-xsum"
10
  model = ORTModelForSeq2SeqLM.from_pretrained(model_name, export=True)
11
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
12
 
13
- # Create summarizer pipeline with Optimum
14
  summarizer = pipeline("summarization", model=model, tokenizer=tokenizer, device_map="auto", batch_size=12)
15
 
16
- # Define summarization function with 1024 token cap
17
  def summarize_text(text):
18
  if not text.strip():
19
  return "Please enter some text."
20
 
21
- # Tokenize and truncate to max 1024 tokens
22
  inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
23
  input_text = tokenizer.decode(inputs["input_ids"][0], skip_special_tokens=True)
24
 
25
- # Summarize the truncated text
26
- result = summarizer(input_text)
 
 
 
 
 
27
  return result[0]["summary_text"]
28
 
29
  # Gradio app
@@ -31,9 +36,9 @@ app = gr.Interface(
31
  fn=summarize_text,
32
  inputs=gr.Textbox(lines=15, placeholder="Paste your text here...", label="Input Text"),
33
  outputs=gr.Textbox(label="Summary"),
34
- title="🚀 ONNX-Powered T5 Summarizer (1024 tokens)",
35
- description="Summarize long text using a fine-tuned ONNX-accelerated T5-small model (max input: 1024 tokens)"
36
  )
37
 
38
- # Launch the app
39
  app.launch()
 
10
  model = ORTModelForSeq2SeqLM.from_pretrained(model_name, export=True)
11
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
12
 
13
+ # Create summarizer pipeline
14
  summarizer = pipeline("summarization", model=model, tokenizer=tokenizer, device_map="auto", batch_size=12)
15
 
16
+ # Summarization function with max input tokens and medium summary length
17
  def summarize_text(text):
18
  if not text.strip():
19
  return "Please enter some text."
20
 
21
+ # Tokenize and truncate to 1024 tokens
22
  inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
23
  input_text = tokenizer.decode(inputs["input_ids"][0], skip_special_tokens=True)
24
 
25
+ # Generate medium-length summary
26
+ result = summarizer(
27
+ input_text,
28
+ min_length=30, # 👈 medium minimum length
29
+ max_length=100, # 👈 medium maximum length
30
+ do_sample=False
31
+ )
32
  return result[0]["summary_text"]
33
 
34
  # Gradio app
 
36
  fn=summarize_text,
37
  inputs=gr.Textbox(lines=15, placeholder="Paste your text here...", label="Input Text"),
38
  outputs=gr.Textbox(label="Summary"),
39
+ title="🚀 ONNX-Powered T5 Summarizer (Medium Summary)",
40
+ description="Summarize long text into a medium-length summary using an ONNX-accelerated T5-small model (max input: 1024 tokens)"
41
  )
42
 
43
+ # Launch
44
  app.launch()