File size: 17,733 Bytes
b1d4203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2266c59
 
 
dec3ec5
2266c59
 
 
 
 
 
 
 
7b45bbe
 
2266c59
 
 
 
 
dec3ec5
2266c59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dec3ec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2266c59
 
 
 
 
 
dec3ec5
2266c59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dec3ec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2266c59
 
 
 
 
 
 
 
 
 
 
dec3ec5
2266c59
 
 
 
dec3ec5
2266c59
 
 
 
 
 
dec3ec5
 
 
 
2266c59
dec3ec5
 
 
 
 
2266c59
 
 
 
dec3ec5
2266c59
 
 
 
 
 
 
 
 
 
7b45bbe
2266c59
 
 
 
 
 
 
 
7b45bbe
2266c59
 
 
 
 
 
 
 
 
 
7b45bbe
2266c59
 
 
 
 
 
 
 
7b45bbe
2266c59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b45bbe
2266c59
 
 
 
 
 
 
 
 
dec3ec5
2266c59
 
 
 
 
 
 
 
dec3ec5
 
2266c59
 
 
 
 
dec3ec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1d4203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Clips: ['1.mp4', '1.mp4']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['1.mp4', '1.mp4']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "files = {\n",
    "    1: \"1.mp4\", 2: \"2.mp4\", 3: \"3.mp4\", 4: \"4.mp4\", 5: \"5.mp4\",\n",
    "    6: \"6.mp4\", 7: \"7.mp4\", 8: \"8.mp4\", 9: \"9.mp4\",\n",
    "    10: \"10.mp4\", 11: \"11.mp4\", 12: \"12.mp4\", 13: \"13.mp4\", 14: \"14.mp4\",\n",
    "    15: \"15.mp4\", 16: \"16.mp4\", 17: \"17.mp4\", 18: \"18.mp4\", 19: \"19.mp4\",\n",
    "    20: \"20.mp4\", 30: \"30.mp4\", 40: \"40.mp4\", 50: \"50.mp4\", \n",
    "    60: \"60.mp4\", 70: \"70.mp4\", 80: \"80.mp4\", 90: \"90.mp4\",\n",
    "    100: \"100.mp4\", 1000: \"1000.mp4\",\n",
    "    100000: \"100000.mp4\"\n",
    "}\n",
    "\n",
    "def get_clips(number):\n",
    "    num_digits = len(str(number))\n",
    "    place_values = []\n",
    "    place = 1\n",
    "\n",
    "    # Split number into place values\n",
    "    while number > 0:\n",
    "        digit = number % 10\n",
    "        if digit > 0:\n",
    "            place_values.append((digit, place))\n",
    "        number //= 10\n",
    "        place *= 10\n",
    "    \n",
    "    place_values.reverse()  # To process from the highest place value\n",
    "    clips = []\n",
    "    i = 0\n",
    "\n",
    "    while i < len(place_values):\n",
    "        digit, place = place_values[i]\n",
    "\n",
    "        # Handle cases for 1-20 at specific positions\n",
    "        if place == 1 and i > 0 and place_values[i - 1][1] == 10:  # Check for numbers ending in 1-20\n",
    "            combined = place_values[i - 1][0] * 10 + digit\n",
    "            if 1 <= combined <= 20:\n",
    "                clips.pop()  # Remove the previous 10's place clip\n",
    "                clips.append(files[combined])\n",
    "                i += 1\n",
    "                continue\n",
    "        \n",
    "        if place == 10 and digit * 10 <= 20:  # Numbers between 1-20 at higher positions\n",
    "            if i + 1 < len(place_values) and place_values[i + 1][1] == 1:\n",
    "                combined = digit * 10 + place_values[i + 1][0]\n",
    "                if 1 <= combined <= 20:\n",
    "                    clips.append(files[combined])\n",
    "                    i += 2\n",
    "                    continue\n",
    "\n",
    "        # Add individual clips\n",
    "        if digit in files:\n",
    "            clips.append(files[digit])\n",
    "        if digit * place in files:\n",
    "            clips.append(files[digit * place])\n",
    "\n",
    "        i += 1\n",
    "\n",
    "    # Handle 10,000 and 10,00,000 special cases\n",
    "    if len(place_values) % 2 == 1 and place_values[0][1] in [10000, 100000]:\n",
    "        first_digit = place_values[0][0]\n",
    "        if 1 <= first_digit <= 20:\n",
    "            clips.insert(0, files[first_digit])\n",
    "        elif first_digit * 10 in files:\n",
    "            clips.insert(0, files[first_digit * 10])\n",
    "        place_values = place_values[1:]\n",
    "\n",
    "    print(\"Clips:\", clips)\n",
    "    return clips\n",
    "\n",
    "# Example usage\n",
    "number = int(input(\"Enter a number: \"))\n",
    "get_clips(number)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99: ['90.mp4', '9.mp4']\n",
      "111: ['1.mp4', '100.mp4', '11.mp4']\n",
      "256: ['2.mp4', '100.mp4', '50.mp4', '6.mp4']\n",
      "1000: ['1.mp4', '1000.mp4']\n",
      "1011: ['1.mp4', '1000.mp4', '11.mp4']\n",
      "9999: ['9.mp4', '1000.mp4', '9.mp4', '100.mp4', '90.mp4', '9.mp4']\n",
      "10000: ['10.mp4', '1000.mp4']\n",
      "24256: ['20.mp4', '4.mp4', '1000.mp4', '2.mp4', '100.mp4', '50.mp4', '6.mp4']\n",
      "22: ['20.mp4', '2.mp4']\n",
      "19: ['19.mp4']\n",
      "4: ['4.mp4']\n"
     ]
    }
   ],
   "source": [
    "files = {\n",
    "    1: \"1.mp4\", 2: \"2.mp4\", 3: \"3.mp4\", 4: \"4.mp4\", 5: \"5.mp4\",\n",
    "    6: \"6.mp4\", 7: \"7.mp4\", 8: \"8.mp4\", 9: \"9.mp4\",\n",
    "    10: \"10.mp4\", 11: \"11.mp4\", 12: \"12.mp4\", 13: \"13.mp4\", 14: \"14.mp4\",\n",
    "    15: \"15.mp4\", 16: \"16.mp4\", 17: \"17.mp4\", 18: \"18.mp4\", 19: \"19.mp4\",\n",
    "    20: \"20.mp4\", 30: \"30.mp4\", 40: \"40.mp4\", 50: \"50.mp4\",\n",
    "    60: \"60.mp4\", 70: \"70.mp4\", 80: \"80.mp4\", 90: \"90.mp4\",\n",
    "    100: \"100.mp4\", 1000: \"1000.mp4\",\n",
    "    100000: \"100000.mp4\"\n",
    "}\n",
    "\n",
    "def number_to_clips(n):\n",
    "    components = []\n",
    "    if n >= 100000:\n",
    "        lakh = n // 100000\n",
    "        if lakh > 0:\n",
    "            components.append(lakh)\n",
    "            components.append(100000)\n",
    "        n %= 100000\n",
    "    if n >= 1000:\n",
    "        thousand = n // 1000\n",
    "        if thousand > 0:\n",
    "            components.append(thousand)\n",
    "            components.append(1000)\n",
    "        n %= 1000\n",
    "    if n >= 100:\n",
    "        hundred = n // 100\n",
    "        if hundred > 0:\n",
    "            components.append(hundred)\n",
    "            components.append(100)\n",
    "        n %= 100\n",
    "    if n > 20:\n",
    "        tens = (n // 10) * 10\n",
    "        if tens > 0:\n",
    "            components.append(tens)\n",
    "        n %= 10\n",
    "    if n > 0:\n",
    "        components.append(n)\n",
    "    return components\n",
    "\n",
    "def generate_clip_sequence(n):\n",
    "    components = number_to_clips(n)\n",
    "    clip_sequence = []\n",
    "    for component in components:\n",
    "        if component in files:\n",
    "            clip_sequence.append(files[component])\n",
    "        else:\n",
    "            # Break down further if component is not in files\n",
    "            sub_components = number_to_clips(component)\n",
    "            clip_sequence.extend([files[sub] for sub in sub_components])\n",
    "    return clip_sequence\n",
    "\n",
    "# Example usage\n",
    "examples = [99, 111, 256, 1000, 1011, 9999, 10000, 24256, 22, 19, 4]\n",
    "for example in examples:\n",
    "    print(f\"{example}: {generate_clip_sequence(example)}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# code to remove first few and last few frames of clips using moviepy\n",
    "import os\n",
    "from moviepy.editor import VideoFileClip\n",
    "\n",
    "def trim_clips(clips, start=0, end=0):\n",
    "    trimmed_clips = []\n",
    "    for clip in clips:\n",
    "        clip_path = os.path.join(\"clips\", clip)\n",
    "        video = VideoFileClip(clip_path)\n",
    "        trimmed = video.subclip(start, video.duration - end)\n",
    "        trimmed_clips.append(trimmed)\n",
    "    return trimmed_clips\n",
    "\n",
    "# Example usage\n",
    "clips = os.listdir(\"clips\")\n",
    "clips = [clip for clip in clips if clip.endswith(\".mp4\")]\n",
    "\n",
    "# Trim first 1 second and last 2 seconds\n",
    "trimmed_clips = trim_clips(clips, 0.3, 0.3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "payload = {\n",
    "  \"title\": \"Sample Avatar Video\",\n",
    "  \"caption\": False,\n",
    "  \"callback_id\": \"your_custom_id_123\",\n",
    "  \"dimension\": {\n",
    "    \"width\": 720,\n",
    "    \"height\": 1280\n",
    "  },\n",
    "  \"video_inputs\": [\n",
    "    {\n",
    "      \"character\": {\n",
    "        \"type\": \"avatar\",\n",
    "        \"avatar_id\": \"42b4f9358cc9443a8610fda90bd3ad87\",\n",
    "        \"scale\": 1.0,\n",
    "        \"avatar_style\": \"normal\",\n",
    "        \"offset\": {\n",
    "          \"x\": 0.0,\n",
    "          \"y\": 0.0\n",
    "        },\n",
    "        \"matting\": False\n",
    "      },\n",
    "      \"voice\": {\n",
    "        \"type\": \"audio\",\n",
    "        \"audio_url\": \"https://drive.google.com/file/d/1CF8TjWwPWiIPJX3D1bjpMopinHt4iw1D/view?usp=sharing\"\n",
    "      },\n",
    "    }\n",
    "  ],\n",
    "  \"callback_url\": \"https://your-callback-url.com\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "payload = {\n",
    "    \"title\": \"Sample Talking Photo Video\",\n",
    "    \"caption\": False,\n",
    "    \"callback_id\": \"your_custom_id_123\",\n",
    "    \"dimension\": {\n",
    "        \"width\": 720,\n",
    "        \"height\": 1280\n",
    "    },\n",
    "    \"video_inputs\": [\n",
    "        {\n",
    "            \"character\": {\n",
    "                \"type\": \"talking_photo\",\n",
    "                \"talking_photo_id\": 'cf557bdc461b487fb703b0c3138df325'\n",
    "            },\n",
    "            \"voice\": {\n",
    "                \"type\": \"audio\",\n",
    "                \"audio_url\": \"https://drive.google.com/file/d/1CF8TjWwPWiIPJX3D1bjpMopinHt4iw1D/view?usp=sharing\"\n",
    "            },\n",
    "            \"talking_style\": \"stable\",\n",
    "            \"expression\": \"happy\",\n",
    "            # \"background\": {\n",
    "            #     \"type\": \"color\",\n",
    "            #     \"value\": \"#FAFAFA\"\n",
    "            # }\n",
    "        }\n",
    "    ]\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"error\": null, \"data\": {\"video_id\": \"d8194dfd76fa40c49bfc9a99c67ffbe3\"}}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "url = \"https://api.heygen.com/v2/video/generate\"\n",
    "\n",
    "\n",
    "headers = {\n",
    "    \"accept\": \"application/json\",\n",
    "    \"content-type\": \"application/json\",\n",
    "    \"x-api-key\": \"YTBjYzk5MjI1ZWQzNGViOTgxMTI0NjM2OGQ5NDc2OGEtMTczMzk5MjA5MA==\"\n",
    "}\n",
    "\n",
    "response = requests.post(url, json=payload, headers=headers)\n",
    "\n",
    "print(response.text)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'d8194dfd76fa40c49bfc9a99c67ffbe3'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "video_id = response.json()[\"data\"][\"video_id\"]\n",
    "video_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "url = \"https://api.heygen.com/v1/video_status.get\"\n",
    "\n",
    "headers = {\n",
    "    \"accept\": \"application/json\",\n",
    "    \"x-api-key\": \"YTBjYzk5MjI1ZWQzNGViOTgxMTI0NjM2OGQ5NDc2OGEtMTczMzk5MjA5MA==\"\n",
    "}\n",
    "\n",
    "\n",
    "response = requests.get(url, headers=headers, params={\"video_id\": video_id}).json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': 100,\n",
       " 'data': {'callback_id': None,\n",
       "  'caption_url': None,\n",
       "  'created_at': 1736231063,\n",
       "  'duration': None,\n",
       "  'error': None,\n",
       "  'gif_url': None,\n",
       "  'id': 'd8194dfd76fa40c49bfc9a99c67ffbe3',\n",
       "  'status': 'processing',\n",
       "  'thumbnail_url': None,\n",
       "  'video_url': None,\n",
       "  'video_url_caption': None},\n",
       " 'message': 'Success'}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response[\"code\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "video_url = response.get(\"data\").get(\"video_url\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "downloaded_video = requests.get(video_url)\n",
    "\n",
    "# save the video to a file\n",
    "with open(\"UPIBOT.mp4\", \"wb\") as f:\n",
    "    f.write(downloaded_video.content)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import json\n",
    "from moviepy.editor import VideoFileClip\n",
    "\n",
    "# Load the clips metadata\n",
    "with open(\"clips_metadata.json\", \"r\") as f:\n",
    "    clips_metadata = json.load(f)\n",
    "\n",
    "# Load the downloaded video\n",
    "video = VideoFileClip(\"UPIBOT.mp4\")\n",
    "\n",
    "\n",
    "# use that video to generate short clips from using timestamps mentioned in clips_metadata\n",
    "clips = []\n",
    "for clip_data in clips_metadata:\n",
    "    start_time = clip_data[\"start_time_ms\"]\n",
    "    end_time = clip_data[\"end_time_ms\"]\n",
    "\n",
    "    # convert milliseconds to seconds\n",
    "    start_time /= 1000\n",
    "    end_time /= 1000\n",
    "\n",
    "    try:\n",
    "        clip_name = clip_data[\"file_name\"].split(\".\")[0]+\".mp4\"\n",
    "        clip = video.subclip(start_time, end_time)\n",
    "        clips.append(clip)\n",
    "    except Exception as e:\n",
    "        print(f\"Error in clip {clip_name}: {e}\")\n",
    "\n",
    "# save the clips to a dir\n",
    "\n",
    "import os\n",
    "clips_dir = str(input(\"Enter the directory to save the clips: \"))\n",
    "os.makedirs(clips_dir, exist_ok=True)\n",
    "\n",
    "for i, clip in enumerate(clips):\n",
    "    clip_path = os.path.join(clips_dir, clips_metadata[i][\"file_name\"].split(\".\")[0]+\".mp4\")\n",
    "    clip.write_videofile(clip_path, codec=\"libx264\", audio_codec=\"aac\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "with open(\"clips_metadata.json\", \"r\") as f:\n",
    "    clips_metadata = json.load(f)\n",
    "\n",
    "for item in clips_metadata:\n",
    "    item[\"start_time_ms\"]=item[\"start_time_ms\"]+20\n",
    "    item[\"end_time_ms\"]=item[\"end_time_ms\"]-20\n",
    "\n",
    "# update the file with new timestamps\n",
    "with open(\"clips_metadata.json\", \"w\") as f:\n",
    "    json.dump(clips_metadata, f, indent=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 100, 'data': {'talking_photo_id': 'cf557bdc461b487fb703b0c3138df325', 'talking_photo_url': 'https://files2.heygen.ai/prod/movio/url_upload/user_upload/a0cc99225ed34eb9811246368d94768a/f670829259c24a0197966e9f7c767ada.image/png?Expires=1736835408&Signature=EcHmA-5R6USvUeus0Ku~NCoCfg~T9NteKjfR59HEYOOurb7in9T4QB3Um8aeHBGLhIz1~5epJuvzIVnuB9H2Ab5uwV9B84KdXWK5rWhrCefRRn8JQxFOnvoCDtQFeHhuTs8957xbboJkFdLiv8OLli90lkmO0fzZecs7WB~WFFhQGqeAhCPjAvQt325ECSngNA2Z4MbI96YbOanE5GiRvUg56hczdb9XqhZktDkZKIDZGl3jk45BcmoaYh6N~sySnGN4kBe-Ny8exFzH0cjloX3gwkHnwsitmI2yQKmse7LKQFEt8WyQYxQ6z6q4YN1FpjKqMjK1T~~UGLepdGIDCA__&Key-Pair-Id=K38HBHX5LX3X2H'}, 'msg': None, 'message': None}\n"
     ]
    }
   ],
   "source": [
    "api_key = \"YTBjYzk5MjI1ZWQzNGViOTgxMTI0NjM2OGQ5NDc2OGEtMTczMzk5MjA5MA==\"\n",
    "\n",
    "with open(\"man_portrait.png\", \"rb\") as f:\n",
    "  resp = requests.post(\"https://upload.heygen.com/v1/talking_photo\", data=f, headers={\"Content-Type\": \"image/png\", \"x-api-key\": api_key})\n",
    "  print(resp.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cf557bdc461b487fb703b0c3138df325'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response = resp.json()\n",
    "response[\"data\"][\"talking_photo_id\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "url = \"https://api.heygen.com/v1/talking_photo.list\"\n",
    "\n",
    "headers = {\n",
    "    \"accept\": \"application/json\",\n",
    "    \"x-api-key\": api_key\n",
    "}\n",
    "\n",
    "response = requests.get(url, headers=headers)\n",
    "\n",
    "print(response.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}