JohnKouf commited on
Commit
a162763
·
verified ·
1 Parent(s): 36f3185

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -16,6 +16,18 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
16
  tokenizer = AutoTokenizer.from_pretrained("kriton/greek-text-summarization")
17
  model = AutoModelForSeq2SeqLM.from_pretrained("kriton/greek-text-summarization")
18
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Define the summary generation function
20
  def genarate_summary(article):
21
  inputs = tokenizer(
@@ -37,7 +49,7 @@ def genarate_summary(article):
37
  no_repeat_ngram_size=3
38
  )
39
 
40
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
41
 
42
  # Set up Gradio Interface
43
  iface = gr.Interface(
 
16
  tokenizer = AutoTokenizer.from_pretrained("kriton/greek-text-summarization")
17
  model = AutoModelForSeq2SeqLM.from_pretrained("kriton/greek-text-summarization")
18
 
19
+
20
+
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(
 
49
  no_repeat_ngram_size=3
50
  )
51
 
52
+ return remove_incomplete_sentence(tokenizer.decode(outputs[0], skip_special_tokens=True))
53
 
54
  # Set up Gradio Interface
55
  iface = gr.Interface(