File size: 3,779 Bytes
19fe404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e262715
19fe404
 
 
 
 
 
 
 
 
 
 
e262715
19fe404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2a6cd2
19fe404
 
 
 
 
 
c2a6cd2
19fe404
 
 
 
 
 
e262715
 
b0f1243
e262715
19fe404
 
 
 
 
 
e262715
19fe404
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import base64
import json
import sys
import time
from datetime import datetime
from io import BytesIO

import cv2
import requests


def post_diffusion_transformer(diffusion_transformer_path, url='http://127.0.0.1:7860'):
    datas = json.dumps({
        "diffusion_transformer_path": diffusion_transformer_path
    })
    r = requests.post(f'{url}/easyanimate/update_diffusion_transformer', data=datas, timeout=1500)
    data = r.content.decode('utf-8')
    return data

def post_update_edition(edition, url='http://0.0.0.0:7860'):
    datas = json.dumps({
        "edition": edition
    })
    r = requests.post(f'{url}/easyanimate/update_edition', data=datas, timeout=1500)
    data = r.content.decode('utf-8')
    return data

def post_infer(generation_method, length_slider, url='http://127.0.0.1:7860'):
    datas = json.dumps({
        "base_model_path": "none",
        "motion_module_path": "none",
        "lora_model_path": "none", 
        "lora_alpha_slider": 0.55, 
        "prompt_textbox": "This video shows Mount saint helens, washington - the stunning scenery of a rocky mountains during golden hours - wide shot. A soaring drone footage captures the majestic beauty of a coastal cliff, its red and yellow stratified rock faces rich in color and against the vibrant turquoise of the sea.", 
        "negative_prompt_textbox": "Strange motion trajectory, a poor composition and deformed video, worst quality, normal quality, low quality, low resolution, duplicate and ugly, strange body structure, long and strange neck, bad teeth, bad eyes, bad limbs, bad hands, rotating camera, blurry camera, shaking camera", 
        "sampler_dropdown": "Euler", 
        "sample_step_slider": 30, 
        "width_slider": 672, 
        "height_slider": 384, 
        "generation_method": "Video Generation",
        "length_slider": length_slider,
        "cfg_scale_slider": 6,
        "seed_textbox": 43,
    })
    r = requests.post(f'{url}/easyanimate/infer_forward', data=datas, timeout=1500)
    data = r.content.decode('utf-8')
    return data

if __name__ == '__main__':
    # initiate time
    now_date    = datetime.now()
    time_start  = time.time()  
    
    # -------------------------- #
    #  Step 1: update edition
    # -------------------------- #
    edition = "v5.1"
    outputs = post_update_edition(edition)
    print('Output update edition: ', outputs)

    # -------------------------- #
    #  Step 2: update edition
    # -------------------------- #
    diffusion_transformer_path = "models/Diffusion_Transformer/EasyAnimateV5.1-12b-zh-InP"
    outputs = post_diffusion_transformer(diffusion_transformer_path)
    print('Output update edition: ', outputs)

    # -------------------------- #
    #  Step 3: infer
    # -------------------------- #
    # "Video Generation" and "Image Generation"
    generation_method = "Video Generation"
    length_slider = 21
    outputs = post_infer(generation_method, length_slider)
    
    # Get decoded data
    outputs = json.loads(outputs)
    base64_encoding = outputs["base64_encoding"]
    decoded_data = base64.b64decode(base64_encoding)

    is_image = True if generation_method == "Image Generation" else False
    if is_image or length_slider == 1:
        file_path = "1.png"
    else:
        file_path = "1.mp4"
    with open(file_path, "wb") as file:
        file.write(decoded_data)
        
    # End of record time
    # The calculated time difference is the execution time of the program, expressed in seconds / s
    time_end = time.time()  
    time_sum = (time_end - time_start) % 60 
    print('# --------------------------------------------------------- #')
    print(f'#   Total expenditure: {time_sum}s')
    print('# --------------------------------------------------------- #')