|
|
|
|
|
""" |
|
|
Test script for the HuggingFace Segment-Based Video Highlights API |
|
|
""" |
|
|
|
|
|
import requests |
|
|
import time |
|
|
import json |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
API_BASE = "http://localhost:7860" |
|
|
TEST_VIDEO = "../test_video/test.mp4" |
|
|
|
|
|
def test_api(): |
|
|
"""Test the complete API workflow""" |
|
|
print("π§ͺ Testing HuggingFace Segment-Based Video Highlights API") |
|
|
|
|
|
|
|
|
if not Path(TEST_VIDEO).exists(): |
|
|
print(f"β Test video not found: {TEST_VIDEO}") |
|
|
return |
|
|
|
|
|
try: |
|
|
|
|
|
print("\n1οΈβ£ Testing health endpoint...") |
|
|
response = requests.get(f"{API_BASE}/health") |
|
|
print(f"Health check: {response.status_code} - {response.json()}") |
|
|
|
|
|
|
|
|
print("\n2οΈβ£ Uploading video...") |
|
|
with open(TEST_VIDEO, 'rb') as video_file: |
|
|
files = {'video': video_file} |
|
|
data = { |
|
|
'segment_length': 5.0, |
|
|
'model_name': 'HuggingFaceTB/SmolVLM2-256M-Video-Instruct', |
|
|
'with_effects': True |
|
|
} |
|
|
response = requests.post(f"{API_BASE}/upload-video", files=files, data=data) |
|
|
|
|
|
if response.status_code != 200: |
|
|
print(f"β Upload failed: {response.status_code} - {response.text}") |
|
|
return |
|
|
|
|
|
job_data = response.json() |
|
|
job_id = job_data['job_id'] |
|
|
print(f"β
Video uploaded successfully! Job ID: {job_id}") |
|
|
|
|
|
|
|
|
print("\n3οΈβ£ Monitoring job progress...") |
|
|
while True: |
|
|
response = requests.get(f"{API_BASE}/job-status/{job_id}") |
|
|
if response.status_code != 200: |
|
|
print(f"β Status check failed: {response.status_code}") |
|
|
break |
|
|
|
|
|
status_data = response.json() |
|
|
print(f"Status: {status_data['status']} - {status_data['message']} ({status_data['progress']}%)") |
|
|
|
|
|
if status_data['status'] == 'completed': |
|
|
print(f"β
Processing completed!") |
|
|
print(f"πΉ Highlights URL: {status_data['highlights_url']}") |
|
|
print(f"π Analysis URL: {status_data['analysis_url']}") |
|
|
print(f"π¬ Segments: {status_data['selected_segments']}/{status_data['total_segments']}") |
|
|
print(f"π Compression: {status_data['compression_ratio']:.1%}") |
|
|
break |
|
|
elif status_data['status'] == 'failed': |
|
|
print(f"β Processing failed: {status_data['message']}") |
|
|
break |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
|
|
|
if status_data['status'] == 'completed': |
|
|
print("\n4οΈβ£ Download URLs available:") |
|
|
print(f"Highlights: {API_BASE}{status_data['highlights_url']}") |
|
|
print(f"Analysis: {API_BASE}{status_data['analysis_url']}") |
|
|
|
|
|
except requests.exceptions.ConnectionError: |
|
|
print(f"β Cannot connect to API at {API_BASE}") |
|
|
print("Make sure the API server is running with: uvicorn app:app --host 0.0.0.0 --port 7860") |
|
|
except Exception as e: |
|
|
print(f"β Test failed: {str(e)}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
test_api() |
|
|
|