@@ -70,18 +70,19 @@ def run_inference(params):
7070 url = '%s%s' % (config ["baseurl" ], api_path ),
7171 timeout = config ["timeout" ])
7272
73- # You can send the input_image as binary encoded into url-safe base64 string or as publicly accessible url link string
74- img_content = None
75- if "input_image" in params :
76- try :
77- if not re .search (r'https?://\S+' , params ["input_image" ]) is None :
78- img_url = params .get ('input_image' )
79- img_content = requests .get (img_url ).content
80- else :
81- img_content = base64 .urlsafe_b64decode (params ['input_image' ])
82- except Exception as e :
83- print ("Image conversion task failed: " , e )
84- return None
73+ # You can send the input_image, input_mask, and cn_images as binary encoded into url-safe base64 string or as publicly accessible url link string
74+ input_imgs = {'input_image' :None , 'input_mask' :None , 'cn_img1' :None , 'cn_img2' :None , 'cn_img3' :None , 'cn_img4' :None ,}
75+ for key in input_imgs .items ():
76+ if key in params :
77+ try :
78+ if not re .search (r'https?://\S+' , params [key ]) is None :
79+ img_url = params .get (key )
80+ input_imgs [key ] = requests .get (img_url ).content
81+ else :
82+ input_imgs [key ] = base64 .urlsafe_b64decode (params [key ])
83+ except Exception as e :
84+ print ("Image conversion task failed: " , e )
85+ return None
8586
8687 if api_verb == "POST" :
8788 # If the request should be multipart/form-data, convert the application/json data into it.
@@ -90,7 +91,7 @@ def run_inference(params):
9091 # Remove the input_image key/value from original request data (it gets confused otherwise)
9192 del params ['input_image' ]
9293 # Convert
93- multipart_data = MultipartEncoder (fields = {'input_image' : ('image .png' , img_content , 'image/png' ), ** params } )
94+ multipart_data = MultipartEncoder (fields = {key : (f' { key } .png' , value , 'image/png' ) for key , value in input_imgs . items ()}, ** params )
9495 headers = {'Content-Type' : multipart_data .content_type }
9596 response = sd_session .post (
9697 url = '%s%s' % (config ["baseurl" ], api_path ),
@@ -102,8 +103,9 @@ def run_inference(params):
102103 return None
103104 # If the final request should be application/json. Send the original request data
104105 else :
105- if not img_content is None :
106- params ["input_image" ] = base64 .urlsafe_b64encode (img_content ).decode ('utf-8' )
106+ for key , value in input_imgs .items ():
107+ if not value is None :
108+ params [key ] = base64 .urlsafe_b64encode (value ).decode ('utf-8' )
107109 response = sd_session .post (
108110 url = '%s%s' % (config ["baseurl" ], api_path ),
109111 json = params ,
@@ -129,4 +131,4 @@ def handler(event):
129131
130132 print ("Fooocus API Service is ready. Starting RunPod..." )
131133
132- runpod .serverless .start ({"handler" : handler })
134+ runpod .serverless .start ({"handler" : handler })
0 commit comments