qwen2.5-VL-api / model.py
danilohssantana's picture
fixing messages
bc80882
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)