import requests import base64 import json # Your HuggingFace endpoint configuration ENDPOINT_URL = "https://your-endpoint-url.huggingface.co" API_TOKEN = "your-hf-token-here" def encode_file_to_base64(file_path): """Convert file to base64 string""" with open(file_path, "rb") as f: return base64.b64encode(f.read()).decode() # Test the endpoint def test_endpoint(): headers = { "Authorization": f"Bearer {API_TOKEN}", "Content-Type": "application/json", } # Encode your files to base64 image_base64 = encode_file_to_base64("path/to/your/image.png") audio_spk1_base64 = encode_file_to_base64("path/to/speaker1.wav") audio_spk2_base64 = encode_file_to_base64("path/to/speaker2.wav") # Optional # Request payload - this is what you send to your endpoint payload = { "inputs": { "prompt": "A person speaking about technology", "image": image_base64, "audio_spk1": audio_spk1_base64, "audio_spk2": audio_spk2_base64, # Optional - remove if single speaker }, "parameters": {"sample_steps": 12}, # Between 2-25 } print("Sending request to endpoint...") print(f"Prompt: {payload['inputs']['prompt']}") print(f"Sample steps: {payload['parameters']['sample_steps']}") # Make the request response = requests.post(ENDPOINT_URL, headers=headers, json=payload) if response.status_code == 200: result = response.json() if "generated_video" in result: # Save the generated video video_data = base64.b64decode(result["generated_video"]) with open("output_video.mp4", "wb") as f: f.write(video_data) print("✅ Success! Video saved as output_video.mp4") else: print("❌ Error in response:", result.get("error", "Unknown error")) else: print(f"❌ Request failed with status {response.status_code}") print(response.text) if __name__ == "__main__": test_endpoint() # ============================================ # SAMPLE REQUEST FORMATS # ============================================ # Single speaker request: single_speaker_request = { "inputs": { "prompt": "A person talking about the weather", "image": "base64_encoded_image_data_here", "audio_spk1": "base64_encoded_audio_data_here", }, "parameters": {"sample_steps": 12}, } # Two speakers request: two_speakers_request = { "inputs": { "prompt": "Two people having a conversation", "image": "base64_encoded_image_data_here", "audio_spk1": "base64_encoded_audio1_data_here", "audio_spk2": "base64_encoded_audio2_data_here", }, "parameters": {"sample_steps": 15}, } # Expected response format: expected_response = { "generated_video": "base64_encoded_video_data", "content_type": "video/mp4", } # Error response format: error_response = {"error": "Error message here"} print("\n" + "=" * 50) print("SAMPLE REQUEST FORMATS:") print("=" * 50) print("\n1. Single Speaker Request:") print(json.dumps(single_speaker_request, indent=2)) print("\n2. Two Speakers Request:") print(json.dumps(two_speakers_request, indent=2)) print("\n3. Expected Success Response:") print(json.dumps(expected_response, indent=2)) print("\n4. Expected Error Response:") print(json.dumps(error_response, indent=2))