fffiloni commited on
Commit
9738ed3
1 Parent(s): a2c09c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import json
 
3
  from gradio_client import Client
4
 
5
  #fusecap_client = Client("https://noamrot-fusecap-image-captioning.hf.space/")
@@ -31,7 +32,17 @@ def get_caption(image_in):
31
  reconstructed_sentence.append(sublist[0])
32
 
33
  full_sentence = ' '.join(reconstructed_sentence)
34
- print(full_sentence)
 
 
 
 
 
 
 
 
 
 
35
 
36
  # Find the last occurrence of "."
37
  #last_period_index = full_sentence.rfind('.')
@@ -42,7 +53,7 @@ def get_caption(image_in):
42
  # print(truncated_caption)
43
  #print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
44
 
45
- return full_sentence
46
 
47
  import re
48
  import torch
 
1
  import gradio as gr
2
  import json
3
+ import re
4
  from gradio_client import Client
5
 
6
  #fusecap_client = Client("https://noamrot-fusecap-image-captioning.hf.space/")
 
32
  reconstructed_sentence.append(sublist[0])
33
 
34
  full_sentence = ' '.join(reconstructed_sentence)
35
+ #print(full_sentence)
36
+
37
+ # Find the pattern matching the expected format ("Describe this image in detail:" followed by optional space and then the rest)...
38
+ pattern = r'(?<=Describe this image in detail:\s*)(.*)$'
39
+ # Apply the regex pattern to extract the description text.
40
+ match = re.search(pattern, full_sentence)
41
+ if match:
42
+ description = match.group(1)
43
+ print(description)
44
+ else:
45
+ print("Unable to locate valid description.")
46
 
47
  # Find the last occurrence of "."
48
  #last_period_index = full_sentence.rfind('.')
 
53
  # print(truncated_caption)
54
  #print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
55
 
56
+ return description
57
 
58
  import re
59
  import torch