Spaces:
Sleeping
Sleeping
added kosmos2 api
Browse files
app.py
CHANGED
@@ -2,21 +2,29 @@ import gradio as gr
|
|
2 |
from gradio_client import Client
|
3 |
|
4 |
#fusecap_client = Client("https://noamrot-fusecap-image-captioning.hf.space/")
|
5 |
-
fuyu_client = Client("https://adept-fuyu-8b-demo.hf.space/")
|
|
|
6 |
|
7 |
def get_caption(image_in):
|
8 |
-
|
9 |
fuyu_result = fuyu_client.predict(
|
10 |
image_in, # str representing input in 'raw_image' Image component
|
11 |
True, # bool in 'Enable detailed captioning' Checkbox component
|
12 |
fn_index=2
|
13 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Find the last occurrence of "."
|
16 |
-
last_period_index =
|
17 |
|
18 |
# Truncate the string up to the last period
|
19 |
-
truncated_caption =
|
20 |
|
21 |
# print(truncated_caption)
|
22 |
print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
|
|
|
2 |
from gradio_client import Client
|
3 |
|
4 |
#fusecap_client = Client("https://noamrot-fusecap-image-captioning.hf.space/")
|
5 |
+
#fuyu_client = Client("https://adept-fuyu-8b-demo.hf.space/")
|
6 |
+
kosmos2_client = Client("https://ydshieh-kosmos-2.hf.space/")
|
7 |
|
8 |
def get_caption(image_in):
|
9 |
+
"""
|
10 |
fuyu_result = fuyu_client.predict(
|
11 |
image_in, # str representing input in 'raw_image' Image component
|
12 |
True, # bool in 'Enable detailed captioning' Checkbox component
|
13 |
fn_index=2
|
14 |
)
|
15 |
+
"""
|
16 |
+
|
17 |
+
kosmos2_result = kosmos2_client.predict(
|
18 |
+
image_in, # str (filepath or URL to image) in 'Test Image' Image component
|
19 |
+
"Brief", # str in 'Description Type' Radio component
|
20 |
+
fn_index=4
|
21 |
+
)
|
22 |
|
23 |
# Find the last occurrence of "."
|
24 |
+
last_period_index = kosmos2_result.rfind('.')
|
25 |
|
26 |
# Truncate the string up to the last period
|
27 |
+
truncated_caption = kosmos2_result[:last_period_index + 1]
|
28 |
|
29 |
# print(truncated_caption)
|
30 |
print(f"\n—\nIMAGE CAPTION: {truncated_caption}")
|