|
from handler import EndpointHandler |
|
from PIL import Image |
|
import requests |
|
import base64 |
|
from io import BytesIO |
|
import time |
|
|
|
|
|
my_handler = EndpointHandler(path=".") |
|
|
|
|
|
|
|
|
|
prompt = "<grounding>Describe this image in detail" |
|
|
|
url = "https://huggingface.co/microsoft/kosmos-2-patch14-224/resolve/main/snowman.png" |
|
image = Image.open(requests.get(url, stream=True).raw) |
|
|
|
|
|
image.save("new_image.jpg") |
|
image = Image.open("img1.jpg") |
|
buffered = BytesIO() |
|
image.save(buffered, format='JPEG') |
|
image_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8') |
|
|
|
|
|
non_holiday_payload = {"prompt": prompt, "image_base64": image_base64} |
|
|
|
init_t = time.time() |
|
|
|
non_holiday_pred=my_handler(non_holiday_payload) |
|
|
|
|
|
|
|
print("image_description", non_holiday_pred) |
|
print(time.time() - init_t) |
|
|
|
|
|
|
|
|