Sadem-12 commited on
Commit
3ed20ad
·
verified ·
1 Parent(s): cea8fc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -3,20 +3,22 @@ from transformers import pipeline
3
 
4
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
5
 
6
- def summarize_text(text, min_len, max_len):
7
- summary = summarizer(text, min_length=min_len, max_length=max_len)
 
 
 
 
 
 
8
  return summary[0]['summary_text']
9
 
10
  interface = gr.Interface(
11
  fn=summarize_text,
12
- inputs=[
13
- gr.Textbox(label="Enter Text", lines=10, placeholder="Paste your long text here..."),
14
- gr.Slider(label="Min Length", minimum=10, maximum=50, step=1, value=10),
15
- gr.Slider(label="Max Length", minimum=50, maximum=100, step=1, value=100)
16
- ],
17
  outputs=gr.Textbox(label="Summarized Text"),
18
  title="Text Summarizer",
19
- description="This app uses the BART model to summarize your text into a concise form with a minimum of 10 tokens and a maximum of 100 tokens."
20
  )
21
 
22
  interface.launch()
 
3
 
4
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
5
 
6
+ def summarize_text(text):
7
+ word_count = len(text.split()) # حساب عدد الكلمات
8
+ if word_count < 10:
9
+ return "Error: The text should have at least 10 words."
10
+ elif word_count > 100:
11
+ return "Error: The text should have no more than 100 words."
12
+
13
+ summary = summarizer(text, min_length=10, max_length=100)
14
  return summary[0]['summary_text']
15
 
16
  interface = gr.Interface(
17
  fn=summarize_text,
18
+ inputs=gr.Textbox(label="Enter Text", lines=10, placeholder="Paste your long text here..."),
 
 
 
 
19
  outputs=gr.Textbox(label="Summarized Text"),
20
  title="Text Summarizer",
21
+ description="This app uses the BART model to summarize your text. The input text must be between 10 and 100 words."
22
  )
23
 
24
  interface.launch()