Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,25 +19,10 @@ def get_caption_from_kosmos(image_in):
|
|
| 19 |
|
| 20 |
print(f"KOSMOS2 RETURNS: {kosmos2_result}")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
for sublist in data:
|
| 27 |
-
reconstructed_sentence.append(sublist[0])
|
| 28 |
-
|
| 29 |
-
full_sentence = ' '.join(reconstructed_sentence)
|
| 30 |
-
#print(full_sentence)
|
| 31 |
-
|
| 32 |
-
# Find the pattern matching the expected format ("Describe this image in detail:" followed by optional space and then the rest)...
|
| 33 |
-
pattern = r'^Describe this image in detail:\s*(.*)$'
|
| 34 |
-
# Apply the regex pattern to extract the description text.
|
| 35 |
-
match = re.search(pattern, full_sentence)
|
| 36 |
-
if match:
|
| 37 |
-
description = match.group(1)
|
| 38 |
-
print(description)
|
| 39 |
-
else:
|
| 40 |
-
print("Unable to locate valid description.")
|
| 41 |
|
| 42 |
# Find the last occurrence of "."
|
| 43 |
#last_period_index = full_sentence.rfind('.')
|
|
@@ -48,7 +33,7 @@ def get_caption_from_kosmos(image_in):
|
|
| 48 |
# print(truncated_caption)
|
| 49 |
#print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
|
| 50 |
|
| 51 |
-
return
|
| 52 |
|
| 53 |
def get_caption_from_MD(image_in):
|
| 54 |
client = Client("https://vikhyatk-moondream1.hf.space/")
|
|
|
|
| 19 |
|
| 20 |
print(f"KOSMOS2 RETURNS: {kosmos2_result}")
|
| 21 |
|
| 22 |
+
data = kosmos2_result[1]
|
| 23 |
+
|
| 24 |
+
# Extract and combine tokens starting from the second element
|
| 25 |
+
sentence = ''.join(item['token'] for item in data[1:])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Find the last occurrence of "."
|
| 28 |
#last_period_index = full_sentence.rfind('.')
|
|
|
|
| 33 |
# print(truncated_caption)
|
| 34 |
#print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
|
| 35 |
|
| 36 |
+
return sentence
|
| 37 |
|
| 38 |
def get_caption_from_MD(image_in):
|
| 39 |
client = Client("https://vikhyatk-moondream1.hf.space/")
|