File size: 615 Bytes
cf7c183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import requests

API_URL = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-base"
headers = {"Authorization": f"Bearer KEY"}

def image2textFilename(filename):
    with open(filename, "rb") as f:
        data = f.read()
    response = requests.post(API_URL, headers=headers, data=data)
    return response.json()[0]["generated_text"]
def image2textData(data):
    print(data)
    response = requests.post(API_URL, headers=headers, data=data)
    return response.json()[0]["generated_text"]

# output = image2textFilename("/home/wznmickey/Pictures/20230130-153108.jpeg")

# print(output)