Sadem-12 commited on
Commit
807ebeb
·
verified ·
1 Parent(s): 09d7df9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -4,10 +4,11 @@ from transformers import pipeline
4
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
5
 
6
  def summarize_text(text, min_len, max_len):
7
- min_len = max(min_len, 10) # الحد الأدنى لا يمكن أن يقل عن 10
8
- max_len = min(max_len, 150) # الحد الأعلى لا يمكن أن يتجاوز 150
9
-
10
- min_len = min(min_len, max_len)
 
11
 
12
  summary = summarizer(text, min_length=min_len, max_length=max_len)
13
  return summary[0]['summary_text']
@@ -21,7 +22,7 @@ interface = gr.Interface(
21
  ],
22
  outputs=gr.Textbox(label="Summarized Text"),
23
  title="Text Summarizer with Sliders",
24
- description="This app uses the BART model to summarize your text with adjustable min and max length. Set the desired length for the summary."
25
  )
26
 
27
  interface.launch()
 
4
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
5
 
6
  def summarize_text(text, min_len, max_len):
7
+ word_count = len(text.split())
8
+ if word_count < min_len:
9
+ return f"Error: The text should have at least {min_len} words."
10
+ elif word_count > max_len:
11
+ return f"Error: The text should have no more than {max_len} words."
12
 
13
  summary = summarizer(text, min_length=min_len, max_length=max_len)
14
  return summary[0]['summary_text']
 
22
  ],
23
  outputs=gr.Textbox(label="Summarized Text"),
24
  title="Text Summarizer with Sliders",
25
+ description="This app uses the BART model to summarize your text. The input text must be between the min and max length you set using the sliders."
26
  )
27
 
28
  interface.launch()