JohnKouf commited on
Commit
a77cc2d
·
verified ·
1 Parent(s): 8a30555

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -21,13 +21,17 @@ model = AutoModelForSeq2SeqLM.from_pretrained("kriton/greek-text-summarization")
21
 
22
  #remove incomplete sentences from the output
23
  def remove_incomplete_sentence(text):
24
- match = re.search(r'(.+?[.!?;])(?:\s|$)', text[::-1])
25
 
26
- if match:
27
- return match.group(1)[::-1].strip()
28
- else:
29
  return text.strip()
30
 
 
 
 
 
31
  # Define the summary generation function
32
  def genarate_summary(article):
33
  inputs = tokenizer(
 
21
 
22
  #remove incomplete sentences from the output
23
  def remove_incomplete_sentence(text):
24
+ sentence_endings = r'[.!?;]'
25
 
26
+ sentences = re.split(r'(?<=[.!?;])\s+', text.strip())
27
+
28
+ if len(sentences) == 0 or len(sentences) == 1:
29
  return text.strip()
30
 
31
+ if re.match(f'.*[{sentence_endings}]$', sentences[-1]):
32
+ return text.strip()
33
+ return ' '.join(sentences[:-1]).strip()
34
+
35
  # Define the summary generation function
36
  def genarate_summary(article):
37
  inputs = tokenizer(