from handler import EndpointHandler from PIL import Image import requests, json # init handler my_handler = EndpointHandler(use_cuda=False, test_mode=True) # API_URL = "https://oncm9ojdmjwesag2.eu-west-1.aws.endpoints.huggingface.cloud" # headers = { # "Authorization": "Bearer MY_API_TOKEN", # "Content-Type": "image/jpg" # } # def query(filename): # with open(filename, "rb") as f: # data = f.read() # response = requests.request("POST", API_URL, headers=headers, data=data) # return json.loads(response.content.decode("utf-8")) # output = query("food.jpg") # prepare sample payload image_path = '/Users/francois/Documents/dev/Maurice/maurice/test_602.jpg' with open(image_path, 'rb') as f: img = f.read() single_image = { 'inputs': [ img ], 'prompt': 'Describe the image' } multiple_images = { 'inputs': [ img, img, img ], 'prompt': 'Describe the image' } # test the handler print(my_handler(single_image)) print(my_handler(multiple_images)) # non_holiday_payload = {"inputs": "I am quite excited how this will turn out", "date": "2022-08-08"} # holiday_payload = {"inputs": "Today is a though day", "date": "2022-07-04"} # # # # # test the handler # non_holiday_pred=my_handler(non_holiday_payload) # holiday_payload=my_handler(holiday_payload) # # # show results # print("non_holiday_pred", non_holiday_pred) # print("holiday_payload", holiday_payload) # # # non_holiday_pred [{'label': 'joy', 'score': 0.9985942244529724}] # # holiday_payload [{'label': 'happy', 'score': 1}]