lyttt commited on
Commit
1506268
·
1 Parent(s): cfc2299
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -13,7 +13,13 @@ def greet(image):
13
  image = Image.fromarray(image, mode='RGB')
14
  with torch.no_grad():
15
  outputs = model([image], 300).generated_text[0]
16
- return outputs
 
 
 
 
 
 
17
 
18
  demo = gr.Interface(fn=greet, inputs="image", outputs="text")
19
  demo.launch()
 
13
  image = Image.fromarray(image, mode='RGB')
14
  with torch.no_grad():
15
  outputs = model([image], 300).generated_text[0]
16
+ def drop_incomplete_tail(text):
17
+ sentences = text.split('.')
18
+ complete_sentences = [s.strip() for s in sentences if s.strip()]
19
+ if not text.strip().endswith('.'):
20
+ complete_sentences = complete_sentences[:-1]
21
+ return '. '.join(complete_sentences) + ('.' if complete_sentences else '')
22
+ return drop_incomplete_tail(outputs)
23
 
24
  demo = gr.Interface(fn=greet, inputs="image", outputs="text")
25
  demo.launch()