# coding:utf-8 from __future__ import print_function import sys import base64 from volcengine.visual.VisualService import VisualService def read_image_base64(file_path): with open(file_path, "rb") as file: image_bytes = file.read() encoded_image = base64.b64encode(image_bytes) return encoded_image.decode('utf-8') if __name__ == '__main__': visual_service = VisualService() # call below method if you don't set ak and sk in $HOME/.volc/config visual_service.set_ak('AKLTY2YyYmI5MmQwZGNhNDhjZGIxMGJhNTJjYzQ4OTk1NTg') visual_service.set_sk('Wmpoa1ptSTBabU0zWXprek5HRXpZV0l3TVRabU5qRXpZVEV3TVRNMk1qYw==') if len(sys.argv) < 4: sys.exit(1) image_file_path = sys.argv[1] output_file_path = sys.argv[2] effect = sys.argv[3] # Read image file and encode to base64 image_base64 = read_image_base64(image_file_path) form = { "image_base64": image_base64, "cartoon_type": effect, "do_risk": False } resp = visual_service.jpcartoon(form) # Check if response is successful if resp['code'] == 10000: # Extract and print the 'content' part content = resp['data']['image'] # Write content to file with open(output_file_path, "wb") as file: file.write(base64.b64decode(content)) else: with open("debug_effect.txt", "w") as file: file.write(str(resp))