File size: 1,315 Bytes
3a8bfcd
 
5dd1cbf
 
a2b6d64
5dd1cbf
 
a2b6d64
5dd1cbf
 
 
 
 
3a8bfcd
5dd1cbf
 
 
 
 
 
 
 
 
 
 
 
 
 
3a8bfcd
 
bc80882
 
bcf356c
 
3a8bfcd
bc80882
5dd1cbf
 
3a8bfcd
5dd1cbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import requests

# Define base URL for your Hugging Face Space
BASE_URL = "https://danilohssantana-qwen2-5-vl-api.hf.space"

# Image URL to be encoded
image_url = "https://cdn.britannica.com/35/238335-050-2CB2EB8A/Lionel-Messi-Argentina-Netherlands-World-Cup-Qatar-2022.jpg"

# Step 1: Download the image
response = requests.get(image_url)
if response.status_code != 200:
    print("Error downloading image:", response.status_code, response.text)
    exit()

# Step 2: Send the image to the encode-image endpoint
files = {"file": ("image.jpg", response.content, "image/jpeg")}
encode_response = requests.post(f"{BASE_URL}/encode-image/", files=files)

if encode_response.status_code != 200:
    print("Error encoding image:", encode_response.status_code, encode_response.text)
    exit()

encoded_image = encode_response.json().get("encoded_image")

# Step 3: Send the encoded image to the predict endpoint
predict_payload = {
    "image_base64": encoded_image,
    "prompt": "describe the image",
}

print("Payload:", predict_payload)

predict_response = requests.post(f"{BASE_URL}/predict", json=predict_payload)


# # Step 4: Print the response
if predict_response.status_code == 200:
    print("Response:", predict_response.json())
else:
    print("Error:", predict_response.status_code, predict_response.text)