|
|
import requests
|
|
|
import os
|
|
|
import json
|
|
|
|
|
|
def test_analyze_endpoint():
|
|
|
|
|
|
url = "http://localhost:56789/analyze"
|
|
|
|
|
|
|
|
|
video_path = os.path.abspath(os.path.join("videos", "KUNIN-MICE-RAM-04.mp4"))
|
|
|
|
|
|
|
|
|
data = {
|
|
|
"videoUrl": video_path,
|
|
|
"videoOssId": "test_video_001"
|
|
|
}
|
|
|
|
|
|
print(f"Sending request with data: {json.dumps(data, indent=2)}")
|
|
|
|
|
|
try:
|
|
|
|
|
|
response = requests.post(url, json=data)
|
|
|
|
|
|
|
|
|
if response.status_code == 200:
|
|
|
print("Analysis successful!")
|
|
|
print(f"Response: {json.dumps(response.json(), indent=2)}")
|
|
|
|
|
|
|
|
|
h5_url = f"http://localhost:56789{response.json()['h5_file']}"
|
|
|
h5_response = requests.post(h5_url)
|
|
|
|
|
|
if h5_response.status_code == 200:
|
|
|
with open("result.h5", "wb") as f:
|
|
|
f.write(h5_response.content)
|
|
|
print("H5 file downloaded successfully!")
|
|
|
else:
|
|
|
print(f"Failed to download H5 file: {h5_response.status_code}")
|
|
|
|
|
|
|
|
|
video_url = f"http://localhost:56789{response.json()['labeled_video']}"
|
|
|
video_response = requests.post(video_url)
|
|
|
|
|
|
if video_response.status_code == 200:
|
|
|
with open("result_labeled.mp4", "wb") as f:
|
|
|
f.write(video_response.content)
|
|
|
print("Labeled video downloaded successfully!")
|
|
|
else:
|
|
|
print(f"Failed to download labeled video: {video_response.status_code}")
|
|
|
|
|
|
else:
|
|
|
print(f"Error: {response.status_code}")
|
|
|
print(f"Response: {response.text}")
|
|
|
|
|
|
except Exception as e:
|
|
|
print(f"Error occurred: {str(e)}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
test_analyze_endpoint() |