pavishnikarthikeyan commited on
Commit
b651447
·
verified ·
1 Parent(s): c4edab0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -7,8 +7,13 @@ device = 0 if torch.cuda.is_available() else -1
7
  text_summary = pipeline("summarization", model="Falconsai/text_summarization", device=device, torch_dtype=torch.bfloat16)
8
 
9
  def summary(input):
10
- # Adjust max_length and min_length for better summarization
11
- output = text_summary(input, max_length=200, min_length=50, truncation=True)
 
 
 
 
 
12
  return output[0]['summary_text']
13
 
14
  gr.close_all()
@@ -24,3 +29,4 @@ demo = gr.Interface(
24
 
25
  demo.launch()
26
 
 
 
7
  text_summary = pipeline("summarization", model="Falconsai/text_summarization", device=device, torch_dtype=torch.bfloat16)
8
 
9
  def summary(input):
10
+ # Calculate the number of tokens based on input length
11
+ input_length = len(input.split())
12
+ max_output_tokens = max(20, input_length // 2) # Ensure output is less than half of the input
13
+ min_output_tokens = max(10, input_length // 4) # Ensure a meaningful summary
14
+
15
+ # Generate summary with dynamic token limits
16
+ output = text_summary(input, max_length=max_output_tokens, min_length=min_output_tokens, truncation=True)
17
  return output[0]['summary_text']
18
 
19
  gr.close_all()
 
29
 
30
  demo.launch()
31
 
32
+