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.")