File size: 1,581 Bytes
8fb085a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf360c
 
8fb085a
 
 
 
 
 
 
 
 
08814b6
8fb085a
 
 
 
 
 
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
import base64
import requests
import time

def image_to_base64_str(image_path):
    with open(image_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
        return encoded_string.decode('utf-8')

source_image_path = 'source.jpg'
target_image_path = 'target.jpg'

source_str = image_to_base64_str(source_image_path)
target_str = image_to_base64_str(target_image_path)

params = {
    'user_id': 'test',
    'source': source_str,
    'target': target_str,
    'source_type': 'jpg',
    'target_type': 'jpg',
    'frame_processors': ['face_swapper','face_enhancer'],#,'face_enhancer'
    # 'face_mask_blur': 0.5,
    # 'face_mask_padding': [5, 5, 5, 5],
    'face_enhancer_model':  'gfpgan_1.4',
    'keep_fps': True,
    "output_image_quality":100,
    'execution_thread_count': 40,
    'face_selector_mode': 'one',
}

# url = 'https://michaelj-facefusionapi.hf.space/'
url="http://0.0.0.0:7860"
response = requests.post(url, json=params)

# ステータスコードとレスポンスの内容を確認
print("Status Code:", response.status_code)
print("Response Body:")
start=time.time()
# ステータスコードが200の場合のみ処理を進める
if response.status_code == 200:
    output_data = base64.b64decode(response.json()['output'])
    print("response.json()",response.json())
    with open(f'/workspaces/facefusion-api/facefusion/api/temp/output/{int(time.time())}a.jpg', 'wb') as f:
        f.write(output_data)
        end=time.time()
        print("时间",end-start)
else:
    print("Error: The request did not succeed.")