Skip to main content
Glama
by clipsense
test_video_analysis.py•5.15 kB
#!/usr/bin/env python3 """Test ClipSense video analysis""" import requests import os import time API_KEY = "cs_sk_pNQhgId_0X8P-gt010CkRfZ4cgVVAejH9JQj_LpPmYg" BASE_URL = "https://api.clipsense.app/api/v1" def get_content_type(filename): """Get content type from filename""" ext = filename.lower().split(".")[-1] types = { "mp4": "video/mp4", "mov": "video/quicktime", "webm": "video/webm", "avi": "video/x-msvideo" } return types.get(ext, "video/mp4") def test_analysis(video_path, question): """Test video analysis with ClipSense API""" # Check if video exists if not os.path.exists(video_path): print(f"āŒ Video not found: {video_path}") return file_size = os.path.getsize(video_path) filename = os.path.basename(video_path) content_type = get_content_type(filename) print(f"šŸ“¹ Video: {video_path}") print(f"šŸ“¦ Size: {file_size / (1024*1024):.2f} MB") print(f"šŸ“„ Type: {content_type}") print(f"ā“ Question: {question}") print("\nšŸ”„ Getting presigned URL...") # Step 1: Get presigned URL presign_response = requests.post( f"{BASE_URL}/upload/presign", headers={"Authorization": f"Bearer {API_KEY}"}, json={ "filename": filename, "content_type": content_type, "file_size": file_size } ) if presign_response.status_code != 200: print(f"āŒ Presign failed: {presign_response.status_code}") print(f"Response: {presign_response.text}") return presign_data = presign_response.json() upload_url = presign_data["upload_url"] video_key = presign_data["video_key"] print(f"āœ… Video key: {video_key}") print(f"\nšŸ“¤ Uploading video...") # Step 2: Upload video with open(video_path, 'rb') as f: upload_response = requests.put( upload_url, data=f, headers={'Content-Type': content_type} ) if upload_response.status_code not in [200, 204]: print(f"āŒ Upload failed: {upload_response.status_code}") print(f"Response: {upload_response.text}") return print(f"āœ… Upload complete!") print(f"\nšŸ¤– Starting analysis...") # Step 3: Start analysis analyze_response = requests.post( f"{BASE_URL}/analyze/start", headers={"Authorization": f"Bearer {API_KEY}"}, json={ "video_key": video_key, "filename": filename, "question": question, "analysis_type": "mobile_bug" } ) if analyze_response.status_code != 200: print(f"āŒ Analysis start failed: {analyze_response.status_code}") print(f"Response: {analyze_response.text}") return job_data = analyze_response.json() job_id = job_data["id"] print(f"āœ… Job started: {job_id}") print(f"\nā³ Polling for results...") # Step 4: Poll for results max_attempts = 120 # 10 minutes max attempt = 0 while attempt < max_attempts: status_response = requests.get( f"{BASE_URL}/analyze/jobs/{job_id}/status", headers={"Authorization": f"Bearer {API_KEY}"} ) if status_response.status_code != 200: print(f"āŒ Status check failed: {status_response.status_code}") return status_data = status_response.json() status = status_data["status"] print(f" Attempt {attempt + 1}/{max_attempts}: {status}") if status == "completed": # Get full job details job_response = requests.get( f"{BASE_URL}/analyze/jobs/{job_id}", headers={"Authorization": f"Bearer {API_KEY}"} ) if job_response.status_code != 200: print(f"āŒ Failed to get job details: {job_response.status_code}") return result = job_response.json() print(f"\nāœ… Analysis complete!") print(f"\n{'='*80}") print(f"ANALYSIS RESULT:") print(f"{'='*80}") print(result.get("result", {}).get("response", "No analysis returned")) print(f"\n{'='*80}") print(f"Details:") print(f" - Frames analyzed: {result.get('frames_extracted', 'N/A')}") print(f" - Tokens used: {result.get('tokens_used', 0)}") print(f" - Cost: ${result.get('cost_total', 0):.4f}") print(f"{'='*80}\n") return elif status == "failed": error = status_data.get("error_message", "Unknown error") print(f"\nāŒ Analysis failed: {error}") return time.sleep(5) attempt += 1 print(f"\nāŒ Analysis timeout after {max_attempts * 5} seconds") if __name__ == "__main__": # Use one of the available videos video_path = "/Users/jerlitaburanday/Desktop/ASSORTED FILES/SCHOOL ASSORTED FILES/FALL 2022/TGM 557 Analytics/Tableau Vids/SB1 Q 1.mov" question = "Analyze this video and describe what you see happening." test_analysis(video_path, question)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/clipsense/-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server