Spaces:
Sleeping
Sleeping
changes sentence extraction from kosmos2
Browse files
app.py
CHANGED
|
@@ -77,25 +77,10 @@ def get_caption(image_in):
|
|
| 77 |
)
|
| 78 |
print(f"KOSMOS2 RETURNS: {kosmos2_result}")
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
for sublist in data:
|
| 85 |
-
reconstructed_sentence.append(sublist[0])
|
| 86 |
-
|
| 87 |
-
full_sentence = ' '.join(reconstructed_sentence)
|
| 88 |
-
#print(full_sentence)
|
| 89 |
-
|
| 90 |
-
# Find the pattern matching the expected format ("Describe this image in detail:" followed by optional space and then the rest)...
|
| 91 |
-
pattern = r'^Describe this image in detail:\s*(.*)$'
|
| 92 |
-
# Apply the regex pattern to extract the description text.
|
| 93 |
-
match = re.search(pattern, full_sentence)
|
| 94 |
-
if match:
|
| 95 |
-
description = match.group(1)
|
| 96 |
-
print(description)
|
| 97 |
-
else:
|
| 98 |
-
print("Unable to locate valid description.")
|
| 99 |
|
| 100 |
# Find the last occurrence of "."
|
| 101 |
#last_period_index = full_sentence.rfind('.')
|
|
@@ -106,7 +91,7 @@ def get_caption(image_in):
|
|
| 106 |
# print(truncated_caption)
|
| 107 |
#print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
|
| 108 |
|
| 109 |
-
return
|
| 110 |
|
| 111 |
def get_caption_from_MD(image_in):
|
| 112 |
client = Client("https://vikhyatk-moondream1.hf.space/")
|
|
|
|
| 77 |
)
|
| 78 |
print(f"KOSMOS2 RETURNS: {kosmos2_result}")
|
| 79 |
|
| 80 |
+
data = kosmos2_result[1]
|
| 81 |
+
|
| 82 |
+
# Extract and combine tokens starting from the second element
|
| 83 |
+
sentence = ''.join(item['token'] for item in data[1:])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
# Find the last occurrence of "."
|
| 86 |
#last_period_index = full_sentence.rfind('.')
|
|
|
|
| 91 |
# print(truncated_caption)
|
| 92 |
#print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
|
| 93 |
|
| 94 |
+
return sentence
|
| 95 |
|
| 96 |
def get_caption_from_MD(image_in):
|
| 97 |
client = Client("https://vikhyatk-moondream1.hf.space/")
|