File size: 2,053 Bytes
58f0729
1223036
58f0729
 
 
 
 
 
 
 
 
1223036
58f0729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1223036
 
 
 
 
 
58f0729
 
 
 
 
 
 
 
5efe51a
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""Test script for the current synchronous upload-video API."""

import requests
from pathlib import Path

# API configuration
API_BASE = "http://localhost:7860"  # Change to your deployed URL
TEST_VIDEO = "../test_video/test.mp4"  # Adjust path as needed

def test_api():
    """Test health + upload-video workflow."""
    print("🧪 Testing HuggingFace Segment-Based Video Highlights API")
    
    # Check if test video exists
    if not Path(TEST_VIDEO).exists():
        print(f"❌ Test video not found: {TEST_VIDEO}")
        return
    
    try:
        # 1. Test health endpoint
        print("\n1️⃣ Testing health endpoint...")
        response = requests.get(f"{API_BASE}/health")
        print(f"Health check: {response.status_code} - {response.json()}")
        
        # 2. Upload video
        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
        
        result = response.json()
        print("✅ Upload and processing completed!")
        print(f"Success: {result.get('success')}")
        print(f"Message: {result.get('message')}")
        print(f"Video Description: {result.get('video_description')}")
        print(f"Analysis File: {result.get('analysis_file')}")
    
    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()