File size: 3,419 Bytes
5f061c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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))