File size: 1,037 Bytes
cb91e74 |
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 |
import requests
import os
def test_vision_api(image_path, prompt, api_url, output_json_path):
with open(image_path, "rb") as img_file:
files = {"image": img_file}
data = {"prompt": prompt}
response = requests.post(api_url, files=files, data=data)
try:
result = response.json()
except Exception as e:
print("Non-JSON response from API:")
print(response.text)
result = {"error": str(e), "raw_response": response.text}
with open(output_json_path, "w") as f:
import json
json.dump({"frame": os.path.basename(image_path), "result": result}, f, indent=2)
print(f"Logged response to {output_json_path}")
if __name__ == "__main__":
# Example usage
test_vision_api(
image_path="frames/sample_task_0001.png",
prompt="Describe the user's task, app, actions, and the final goal.",
api_url="http://localhost:8000/vision",
output_json_path="annotations/test_vision_api_response.json"
)
|