Spaces:
Runtime error
Runtime error
LeoXing1996 commited on
Commit ·
558e11c
1
Parent(s): d4ba169
add quick run button
Browse filesFiles changed (2)
- README.md+1-1
- app-huggingface.py+92-7
12345---title: Demo Spaceemoji: 🤗colorFrom: yellowcolorTo: pink12345---title: "PIA: Your Personalized Image Animator"emoji: 🤗colorFrom: yellowcolorTo: pink
1234200 unmodified lines20520620720820921021111 unmodified lines22322422522622722822923023136 unmodified lines26826927027127227327415 unmodified lines29029129229329429529629729829923 unmodified lines32332432532632732832933033133233333433533633733835 unmodified lines374375376377378379380381import jsonimport osimport os.path as ospimport random200 unmodified linesdef fetch_default_n_prompt(self, style: str):cfg = self.style_configs[style]n_prompt = cfg.get('n_prompt', '')ip_adapter_scale = cfg.get('real_ip_adapter_scale', 0)gr.Info('Set default negative prompt and ip_adapter_scale.')print('Set default negative prompt and ip_adapter_scale.')11 unmodified linesseed_textbox,ip_adapter_scale,style,progress=gr.Progress(),):if seed_textbox != -1 and seed_textbox != "":torch.manual_seed(int(seed_textbox))else:36 unmodified linesf.write(json_str)f.write("\n\n")return save_sample_pathcontroller = AnimateController()15 unmodified lines)with gr.Row(equal_height=False):with gr.Column():with gr.Row():init_img = gr.Image(label='Input Image')style_dropdown = gr.Dropdown(label='Style', choices=list(STYLE_CONFIG_LIST.keys()), value=list(STYLE_CONFIG_LIST.keys())[0])23 unmodified linesmotion_scale_silder = gr.Slider(label='Motion Scale (Larger value means larger motion but less identity consistency)',value=1, step=1, minimum=1, maximum=len(RANGE_LIST))ip_adapter_scale = gr.Slider(label='IP-Apdater Scale', value=controller.fetch_default_n_prompt(list(STYLE_CONFIG_LIST.keys())[0])[1], minimum=0, maximum=1)with gr.Accordion('Advance Options', open=False):negative_prompt_textbox = gr.Textbox(value=controller.fetch_default_n_prompt(list(STYLE_CONFIG_LIST.keys())[0])[0],label="Negative prompt", lines=2)sample_step_slider = gr.Slider(label="Sampling steps", value=20, minimum=10, maximum=100, step=1)35 unmodified linesip_adapter_scale,style_dropdown,],outputs=[result_video])def create_example(input_list):return gr.Examples(12345200 unmodified lines20620720820921021121211 unmodified lines22422522622722822923023123223323423523623723823924024136 unmodified lines27827928028128228328415 unmodified lines30030130230330430530630730830931031131231331431531631731831932032132232332432532632732832923 unmodified lines35335435535635735835936036136236336436536636735 unmodified lines403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466import jsonimport copyimport osimport os.path as ospimport random200 unmodified linesdef fetch_default_n_prompt(self, style: str):cfg = self.style_configs[style]n_prompt = cfg.get('n_prompt', '')ip_adapter_scale = cfg.get('ip_adapter_scale', 0)gr.Info('Set default negative prompt and ip_adapter_scale.')print('Set default negative prompt and ip_adapter_scale.')11 unmodified linesseed_textbox,ip_adapter_scale,style,example_img=None,progress=gr.Progress(),):if init_img is None:if example_img is None:gr.Warning('Please upload image or use example images.')else:gr.Info('Use exmaple image for fast try!')init_img = example_imginit_img_bk = copy.deepcopy(init_img)if seed_textbox != -1 and seed_textbox != "":torch.manual_seed(int(seed_textbox))else:36 unmodified linesf.write(json_str)f.write("\n\n")return init_img_bk, save_sample_pathcontroller = AnimateController()15 unmodified lines)with gr.Row(equal_height=False):# build state for default buttonsexample_img = gr.State(value=np.array(Image.open('__assets__/image_animation/zhening/zhening.jpeg')))default_motion = gr.State(value=1)default_prompt1 = gr.State(value='lift a red envelope, Chinese new year')default_prompt2 = gr.State(value='New Year\'s greetings, Chinese new year')default_prompt3 = gr.State(value='Chinese costume, Chinese new year')default_prompt4 = gr.State(value='sparklers, Chinese new year')default_n_prompt = gr.State(value='wrong white balance, dark, sketches,worst quality,low quality, deformed, distorted, disfigured, bad eyes, wrong lips,weird mouth, bad teeth, mutated hands and fingers, bad anatomy,wrong anatomy, amputation, extra limb, missing limb, floating,limbs, disconnected limbs, mutation, ugly, disgusting, bad_pictures, negative_hand-neg')default_seed = gr.State(10201304011203481448)default_ip_adapter_scale = gr.State(0.2)default_style = gr.State('3d_cartoon')default_cfg = gr.State(7.5)with gr.Column():with gr.Row():init_img = gr.Image(label='Input Image')gr.Markdown('## Fast Try!')with gr.Row():default_1 = gr.Button('🧧', variant='primary')default_2 = gr.Button('🏮', variant='primary')default_3 = gr.Button('👨👩👧👦', variant='primary')default_4 = gr.Button('🧨', variant='primary')style_dropdown = gr.Dropdown(label='Style', choices=list(STYLE_CONFIG_LIST.keys()), value=list(STYLE_CONFIG_LIST.keys())[0])23 unmodified linesmotion_scale_silder = gr.Slider(label='Motion Scale (Larger value means larger motion but less identity consistency)',value=1, step=1, minimum=1, maximum=len(RANGE_LIST))with gr.Accordion('Advance Options', open=False):negative_prompt_textbox = gr.Textbox(value=controller.fetch_default_n_prompt(list(STYLE_CONFIG_LIST.keys())[0])[0],label="Negative prompt", lines=2)ip_adapter_scale = gr.Slider(label='IP-Apdater Scale', value=controller.fetch_default_n_prompt(list(STYLE_CONFIG_LIST.keys())[0])[1], minimum=0, maximum=1)sample_step_slider = gr.Slider(label="Sampling steps", value=20, minimum=10, maximum=100, step=1)35 unmodified linesip_adapter_scale,style_dropdown,],outputs=[init_img, result_video])default_1.click(fn=controller.animate,inputs=[init_img,default_motion,default_prompt1,default_n_prompt,default_cfg ,default_seed,default_ip_adapter_scale,default_style,example_img,],outputs=[init_img, result_video])default_2.click(fn=controller.animate,inputs=[init_img,default_motion,default_prompt2,default_n_prompt,default_cfg ,default_seed,default_ip_adapter_scale,default_style,example_img,],outputs=[init_img, result_video])default_3.click(fn=controller.animate,inputs=[init_img,default_motion,default_prompt3,default_n_prompt,default_cfg ,default_seed,default_ip_adapter_scale,default_style,example_img,],outputs=[init_img, result_video])default_4.click(fn=controller.animate,inputs=[init_img,default_motion,default_prompt4,default_n_prompt,default_cfg ,default_seed,default_ip_adapter_scale,default_style,example_img,],outputs=[init_img, result_video])def create_example(input_list):return gr.Examples(
README.md+1-1
app-huggingface.py+92-7