Spaces:
Sleeping
Sleeping
Upload 6 files
Browse filesFiles changed (3)
- src/fal_api.py+2-1
- src/rep_api.py+10-19
- src/utils.py+19-3
1234563 unmodified lines10111213141516import fal_clientfrom src.utils import numpy_to_base64from src.helpers import resize_imagedef fal_ipadapter_api(input_image,ip_image,seg_prompt):#print(input_image,ip_image,seg_prompt)3 unmodified linesarguments={"loadimage_1":numpy_to_base64(input_image),"loadimage_2":numpy_to_base64(ip_image),"groundingdinosamsegment (segment anything)_prompt":seg_prompt},)#print(handler)12345673 unmodified lines11121314151617import fal_clientfrom src.utils import numpy_to_base64from src.helpers import resize_imagefrom src.deepl import detect_and_translatedef fal_ipadapter_api(input_image,ip_image,seg_prompt):#print(input_image,ip_image,seg_prompt)3 unmodified linesarguments={"loadimage_1":numpy_to_base64(input_image),"loadimage_2":numpy_to_base64(ip_image),"groundingdinosamsegment (segment anything)_prompt":detect_and_translate(seg_prompt)},)#print(handler)
326 unmodified lines32732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936010 unmodified lines371372373374375376377326 unmodified lines"Ambient"]def replicate_iclight_BG(img,prompt,bg_img,light_source="Use Background Image",negative_prompt="(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation"):assert light_source in light_source_options, "Please select a correct ligh source option"#if type(img)!=str:# img=open_image_from_url(img)#if type(bg_img)!=str:# bg_img=open_image_from_url(bg_img)width, height = img.sizeprint(width,height)#print()target_width = find_closest_valid_dimension(width)target_height = find_closest_valid_dimension(height)resized_img = resize_image(img, target_width, target_height)img=image_to_base64(resized_img)#if light_source=="Use Background Image":bg_width, bg_height = bg_img.sizetarget_width = find_closest_valid_dimension(bg_width)target_height = find_closest_valid_dimension(bg_height)print(bg_img)bg_img = resize_image(bg_img, target_width, target_height)bg_img=image_to_base64(bg_img)output=replicate.run("zsxkib/ic-light-background:60015df78a8a795470da6494822982140d57b150b9ef14354e79302ff89f69e3",input={10 unmodified lines"output_quality": 100,"appended_prompt": "best quality","highres_denoise": 0.5,"negative_prompt": "lowres, bad anatomy, bad hands, cropped, worst quality","background_image": bg_img,"number_of_images": 1}326 unmodified lines32732832933033133233333433533633733833934034134234334434534634734834935035110 unmodified lines362363364365366367368326 unmodified lines"Ambient"]defult_image="https://replicate.delivery/pbxt/KxPIbJUjSmVBlvn0M3C8PAz6brN5Z0eyZSGcKIVw3XfJ6vNV/7.webp"def replicate_iclight_BG(img,prompt,bg_img,light_source="Use Background Image",negative_prompt="(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation"):assert light_source in light_source_options, "Please select a correct ligh source option"width, height = img.sizeprint(width,height)img=image_to_base64(img)#if light_source=="Use Background Image":if bg_img is None:bg_img=open_image_from_url(defult_image)bg_img=image_to_base64(bg_img)#else:#bg_img=Noneprompt=promptoutput=replicate.run("zsxkib/ic-light-background:60015df78a8a795470da6494822982140d57b150b9ef14354e79302ff89f69e3",input={10 unmodified lines"output_quality": 100,"appended_prompt": "best quality","highres_denoise": 0.5,"negative_prompt": negative_prompt,"background_image": bg_img,"number_of_images": 1}
9 unmodified lines101112131415161745 unmodified lines6364656667686970719 unmodified linesimport numpy as npimport jsonimport gradio as grdef resize_image(img, target_width, target_height):"""Resizes an image while maintaining aspect ratio.45 unmodified linesif isinstance(img, np.ndarray):img = Image.fromarray(img)# If the image is a URL, fetch the image and convert it to a PIL imageelif isinstance(img, str) and img.startswith('http'):response = requests.get(img)img = Image.open(BytesIO(response.content))return imgdef open_image_from_url(image_url):9 unmodified lines101112131415161718192021222324252627282945 unmodified lines757677787980818283848586879 unmodified linesimport numpy as npimport jsonimport gradio as grimport subprocessclass dwebpException(Exception):passdef dwebp(file: str):webp = subprocess.run(f"dwebp {file} -quiet -o -", shell=True, capture_output=True)if webp.returncode != 0:raise dwebpException(webp.stderr.decode())else:return Image.open(BytesIO(webp.stdout))def resize_image(img, target_width, target_height):"""Resizes an image while maintaining aspect ratio.45 unmodified linesif isinstance(img, np.ndarray):img = Image.fromarray(img)# If the image is a URL, fetch the image and convert it to a PIL imageelif isinstance(img, str):if "https:" in img or "http:" in img:response = requests.get(img)img = Image.open(BytesIO(response.content))#else is pil typeelse:img=Image.open(img)return imgdef open_image_from_url(image_url):
src/fal_api.py+2-1
src/rep_api.py+10-19
src/utils.py+19-3