sguna commited on
Commit
7594787
·
verified ·
1 Parent(s): 01816ff

Upload test_blip_api.py

Browse files
Files changed (1) hide show
  1. test_blip_api.py +38 -0
test_blip_api.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import io
3
+
4
+ import requests
5
+ from PIL import Image
6
+
7
+ API_URL = "https://xt41z6d0qly7bg8w.us-east-1.aws.endpoints.huggingface.cloud"
8
+ headers = {
9
+ "Accept": "application/json",
10
+ "Content-Type": "application/json"
11
+ }
12
+
13
+
14
+ def query(payload):
15
+ response = requests.post(API_URL, headers=headers, json=payload)
16
+ return response.json()
17
+
18
+
19
+ image_path = 'data/train/images/111736998195_1.JPG' # Replace with the path to your image file
20
+
21
+ # Open the image and convert it to bytes
22
+ with Image.open(image_path) as img:
23
+ img_bytes = io.BytesIO()
24
+ img.save(img_bytes, format='JPEG')
25
+ image_bytes = img_bytes.getvalue()
26
+ image_base64 = base64.b64encode(image_bytes).decode('utf-8')
27
+
28
+ output = query({
29
+ "inputs": {
30
+ "text": "",
31
+ "image": image_base64
32
+ },
33
+ "parameters": {
34
+ "max_new_tokens": 150
35
+ }
36
+ })
37
+
38
+ print(output)