|
|
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__":
|
|
|
|
|
|
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"
|
|
|
)
|
|
|
|