@ -1,3 +1,4 @@
import logging
import os . path
from imaginairy . animations import make_gif_animation
@ -6,52 +7,65 @@ from imaginairy.enhancers.facecrop import detect_faces
from imaginairy . img_utils import add_caption_to_image , pillow_fit_image_within
from imaginairy . schema import ControlInput , ImaginePrompt , LazyLoadingImage
logger = logging . getLogger ( __name__ )
preserve_head_kwargs = {
" mask_prompt " : " head|face " ,
" mask_mode " : " keep " ,
}
preserve_face_kwargs = {
" mask_prompt " : " face " ,
" mask_mode " : " keep " ,
}
generic_prompts = [
( " add confetti " , 6 , { } ) ,
( " add confetti " , 15 , { } ) ,
# ("add sparkles", 14, {}),
( " make it christmas " , 15 , preserve_head_kwargs ) ,
( " make it halloween " , 15 , { } ) ,
( " give it a d ark omninous vibe" , 15 , { } ) ,
( " give it a bright cheery vibe " , 1 5 , { } ) ,
( " make it christmas " , 15 , preserve_ face _kwargs) ,
( " make it halloween " , 15 , preserve_face_kwargs ) ,
( " give it a d epressing vibe" , 10 , { } ) ,
( " give it a bright cheery vibe " , 1 0 , { } ) ,
# weather
( " make it look like a snowstorm " , 20, { } ) ,
( " make it midnight" , 15 , { } ) ,
( " make it a sunny day " , 15 , { } ) ,
( " add misty fog " , 1 5 , { } ) ,
( " make it look like a snowstorm " , 15, preserve_face_kwargs ) ,
( " make it sunset" , 15 , preserve_face_kwargs ) ,
( " make it a sunny day " , 15 , preserve_face_kwargs ) ,
( " add misty fog " , 1 0 , { } ) ,
( " make it flooded " , 10 , { } ) ,
# setting
( " make it underwater " , 1 5 , { } ) ,
( " make it underwater " , 1 0 , { } ) ,
( " add fireworks to the sky " , 15 , { } ) ,
# ("make it in a forest", 10, {}),
# ("make it grassy", 11, {}),
( " make it on mars " , 14 , { } ) ,
# style
( " add glitter " , 10 , { } ) ,
( " turn it into a still from a western " , 1 5 , { } ) ,
( " turn it into a still from a western " , 1 0 , { } ) ,
( " old 1900s photo " , 11.5 , { } ) ,
( " Daguerreotype " , 12 , { } ) ,
( " make it anime style " , 18 , { } ) ,
( " Daguerreotype " , 14 , { } ) ,
( " make it anime style " , 15 , { } ) ,
( " watercolor painting " , 10 , { } ) ,
( " crayon drawing " , 10 , { } ) ,
# ("make it pen and ink style", 20, {}),
( " graphite pencil " , 15 , { } ) ,
# ("make it a thomas kinkade painting", 20, {}) ,
( " make it pixar style " , 20 , { } ) ,
( " graphite pencil " , 1 0, { " negative_prompt " : " low quality " } ) ,
( " make it a thomas kinkade painting " , 10 , { } ) ,
( " make it pixar style " , 18 , { } ) ,
( " low-poly " , 20 , { } ) ,
( " make it stained glass " , 10 , { } ) ,
( " make it pop art " , 12 , { } ) ,
# ("make it street graffiti", 15, {}),
( " make it stained glass " , 15 , { } ) ,
( " make it pop art " , 15 , { } ) ,
( " oil painting " , 11 , { } ) ,
( " street graffiti " , 10 , { } ) ,
( " photorealistic " , 8 , { } ) ,
( " vector art " , 8 , { } ) ,
( " comic book style. happy " , 9 , { } ) ,
( " starry night painting " , 15 , { } ) ,
( " make it minecraft " , 12 , { } ) ,
# materials
( " make it look like a marble statue " , 15 , { } ) ,
( " marble statue " , 15 , { } ) ,
( " make it look like a golden statue " , 15 , { } ) ,
# ("make it claymation", 8, {}),
( " golden statue " , 15 , { } ) ,
# ("make it claymation", 15, {}),
( " play-doh " , 15 , { } ) ,
( " voxel " , 15 , { } ) ,
# ("lego", 15, {}),
@ -74,22 +88,26 @@ only_face_kwargs = {
person_prompt_configs = [
# face
( " make the person close their eyes " , 10 , only_face_kwargs ) ,
# (
# "make the person wear intricate highly detailed facepaint. ornate, artistic",
# 9 ,
# only_face_kwargs,
# ) ,
# ("make the person wear makeup. professional photoshoot", 8 , only_face_kwargs),
( " make the person close their eyes " , 7 , only_face_kwargs ) ,
(
" make the person wear intricate highly detailed facepaint. ornate, artistic " ,
6 ,
only_face_kwargs ,
) ,
# ("make the person wear makeup. professional photoshoot", 15 , only_face_kwargs),
# ("make the person wear mime makeup. intricate, artistic", 7, only_face_kwargs),
# ("make the person wear clown makeup. intricate, artistic", 6, only_face_kwargs) ,
( " make the person wear clown makeup. intricate, artistic " , 7 , only_face_kwargs ) ,
( " make the person a cyborg " , 14 , { } ) ,
# clothes
( " make the person wear shiny metal clothes " , 14 , preserve_head_kwargs ) ,
( " make the person wear a tie-dye shirt " , 7.5 , preserve_head_kwargs ) ,
( " make the person wear a suit " , 7.5 , preserve_head_kwargs ) ,
# ("make the person bald", 7.5, {}),
( " change the hair to pink " , 7.5 , { " mask_mode " : " replace " , " mask_prompt " : " hair " } ) ,
( " make the person wear shiny metal clothes " , 14 , preserve_face_kwargs ) ,
( " make the person wear a tie-dye shirt " , 14 , preserve_face_kwargs ) ,
( " make the person wear a suit " , 14 , preserve_face_kwargs ) ,
( " make the person bald " , 15 , { } ) ,
(
" change the hair to pink " ,
7.5 ,
{ " mask_mode " : " keep " , " mask_prompt " : " face " } ,
) ,
# ("change the hair to black", 7.5, {"mask_mode": "replace", "mask_prompt": "hair"}),
# ("change the hair to blonde", 7.5, {"mask_mode": "replace", "mask_prompt": "hair"}),
# ("change the hair to red", 7.5, {"mask_mode": "replace", "mask_prompt": "hair"}),
@ -101,22 +119,22 @@ person_prompt_configs = [
# ("change the hair to silver", 7.5, {"mask_mode": "replace", "mask_prompt": "hair"}),
(
" professional corporate photo headshot. Canon EOS, sharp focus, high resolution " ,
10 ,
{ " negative_prompt " : " old, ugl y" } ,
6 ,
{ " negative_prompt " : " low qualit y" } ,
) ,
# ("make the person stoic. pensive", 10, only_face_kwargs) ,
# ("make the person sad", 20, {}) ,
# ("make the person angry", 20, {}) ,
# ("make the person look like a celebrity", 10, {}) ,
( " make the person younger " , 11 , { } ) ,
( " make the person 70 years old " , 9 , { } ) ,
( " make the person a disney cartoon character " , 7.5 , { } ) ,
( " make the person stoic. pensive " , 7 , only_face_kwargs ) ,
( " make the person sad " , 7 , only_face_kwargs ) ,
( " make the person angry " , 7 , only_face_kwargs ) ,
( " make the person look like a celebrity " , 10 , { } ) ,
( " make the person younger " , 7 , { } ) ,
( " make the person 70 years old " , 10 , { } ) ,
( " make the person a disney cartoon character " , 9 , { } ) ,
( " turn the humans into robots " , 13 , { } ) ,
( " make the person darth vader" , 15 , { } ) ,
( " make the person a starfleet officer " , 15 , preserve_head_kwargs ) ,
( " make the person a superhero " , 15 , { } ) ,
( " make the person a tiger " , 15 , only_face_kwargs ) ,
# ("lego minifig", 15, {}) ,
( " make the person a jedi knight. star wars" , 15 , preserve_head_kwargs ) ,
( " make the person a starfleet officer . star trek " , 15 , preserve_head_kwargs ) ,
( " make the person a superhero " , 15 , preserve_head_kwargs ) ,
# ("a tiger", 15, only_face_kwargs) ,
( " lego minifig " , 15 , { } ) ,
]
@ -132,22 +150,21 @@ def surprise_me_prompts(
if person is None :
person = bool ( detect_faces ( img ) )
prompts = [ ]
logger . info ( " Person detected in photo. Adjusting edits accordingly. " )
init_image_strength = 0.3
for prompt_text , strength , kwargs in generic_prompts :
kwargs . setdefault ( " negative_prompt " , None )
kwargs . setdefault ( " init_image_strength " , init_image_strength )
if use_controlnet :
strength = 5
control_input = ControlInput ( mode = " edit " , strength = 2 )
control_input = ControlInput ( mode = " edit " )
prompts . append (
ImaginePrompt (
prompt_text ,
negative_prompt = " " ,
init_image = img ,
init_image_strength = 0.3 ,
prompt_strength = strength ,
control_inputs = [ control_input ] ,
steps = steps ,
width = width ,
height = height ,
size = ( width , height ) ,
* * kwargs ,
)
)
@ -159,8 +176,7 @@ def surprise_me_prompts(
prompt_strength = strength ,
model_weights = " edit " ,
steps = steps ,
width = width ,
height = height ,
size = ( width , height ) ,
* * kwargs ,
)
)
@ -175,16 +191,16 @@ def surprise_me_prompts(
control_input = ControlInput (
mode = " edit " ,
)
kwargs . setdefault ( " negative_prompt " , None )
kwargs . setdefault ( " init_image_strength " , init_image_strength )
prompts . append (
ImaginePrompt (
prompt_text ,
init_image = img ,
init_image_strength = 0.05 ,
prompt_strength = strength ,
control_inputs = [ control_input ] ,
steps = steps ,
width = width ,
height = height ,
size = ( width , height ) ,
seed = seed ,
* * kwargs ,
)
@ -197,8 +213,7 @@ def surprise_me_prompts(
prompt_strength = strength ,
model_weights = " edit " ,
steps = steps ,
width = width ,
height = height ,
size = ( width , height ) ,
seed = seed ,
* * kwargs ,
)
@ -241,7 +256,7 @@ def create_surprise_me_images(
gif_imgs . append ( gen_img )
make_gif_animation ( outpath = new_filename , imgs = gif_imgs )
make_gif_animation ( outpath = new_filename , imgs = gif_imgs , frame_duration_ms = 1000 )
if __name__ == " __main__ " :