Spaces:
Runtime error
Runtime error
LeoXing1996 commited on
Commit ·
62ab16e
1
Parent(s): 0f3562d
return state for examples
Browse files36 unmodified lines3738394041424311 unmodified lines555657585960194 unmodified lines2552562572582592608 unmodified lines26927027127227327427527627727827928028128228328428553 unmodified lines339340341342343344345346347348349122 unmodified lines4724734744754764774787 unmodified lines4864874884894904914924934944954964978 unmodified lines5065075085095105115125135148 unmodified lines5235245255265275285295305318 unmodified lines5405415425435445455465475488 unmodified lines55755855956056156256356456556656756856936 unmodified linesexcept EOFError:passtext = ['Happy New Year!', 'Happy New Year!', 'Happy New Year!', 'Happy New Year!'][text_index]size = [36, 36, 36, 36][text_index]for i, frame in enumerate(frames):11 unmodified linesmp4_file = convert_gif_to_mp4(gif_file, mp4_file)return gif_file, mp4_filecss = """.toolbutton {margin-buttom: 0em 0em 0em 0em;194 unmodified linesreturn n_prompt, ip_adapter_scaledef animate(self,init_img,motion_scale,8 unmodified lineswith_text=False,text_idx=0,progress=gr.Progress(),):global sample_idxprint(example_img)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 = np.array(Image.open(example_img))if seed_textbox != -1 and seed_textbox != "":torch.manual_seed(int(seed_textbox))53 unmodified linesadd_text(save_sample_path_gif, save_sample_path_mp4, text_idx)sample_idx += 1# return (save_sample_path_mp4,# gr.update(link=f'file/{save_sample_path_mp4}'),# gr.update(link=f'file/{save_sample_path_gif}'))return (save_sample_path_mp4,[save_sample_path_mp4, save_sample_path_gif])controller = AnimateController()122 unmodified linesresult_video = gr.Video(label="Generated Animation", interactive=False)with gr.Row():download = gr.Files(file_types=['gif', 'mp4'], label='Donwload Output')generate_button.click(fn=controller.animate,7 unmodified linesseed_textbox,ip_adapter_scale,style_dropdown,# None,],outputs=[result_video, download])default_1.click(fn=controller.animate,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_1_idx,],outputs=[result_video, download])default_2.click(fn=controller.animate,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_2_idx,],outputs=[result_video, download])default_3.click(fn=controller.animate,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_3_idx,],outputs=[result_video, download])default_4.click(fn=controller.animate,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_4_idx,],outputs=[result_video, download])# save_as_gif.click(# fn=None,# inputs=[save_as_gif],# js=_js_open_if_not_logged_in,# )def create_example(input_list):return gr.Examples(36 unmodified lines373839404142434411 unmodified lines56575859606162194 unmodified lines2572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383398 unmodified lines34834935035135235335435535635735853 unmodified lines412413414415416417418419420421422423424122 unmodified lines5475485495505515525535547 unmodified lines5625635645655665675685695705715728 unmodified lines5815825835845855865875885895905915925935945955968 unmodified lines6056066076086096106116126136146156166176186196208 unmodified lines6296306316326336346356366376386396406416426436448 unmodified lines65365465565665765865966066166266366466566636 unmodified linesexcept EOFError:passtext = ['Happy New Year!', 'Happy New Year!','Happy New Year!', 'Happy New Year!'][text_index]size = [36, 36, 36, 36][text_index]for i, frame in enumerate(frames):11 unmodified linesmp4_file = convert_gif_to_mp4(gif_file, mp4_file)return gif_file, mp4_filecss = """.toolbutton {margin-buttom: 0em 0em 0em 0em;194 unmodified linesreturn n_prompt, ip_adapter_scaledef animate(self,init_img,motion_scale,prompt_textbox,negative_prompt_textbox,sample_step_slider,cfg_scale_slider,seed_textbox,ip_adapter_scale,style,progress=gr.Progress(),):global sample_idxif init_img is None:gr.Warning('Please upload image or use example images.')if seed_textbox != -1 and seed_textbox != "":torch.manual_seed(int(seed_textbox))seed = int(seed_textbox)else:seed = torch.initial_seed()generator = torch.Generator(device='cuda')generator.manual_seed(seed)seed_everything(seed)print(f'Seed: {seed}')pipeline = self.pipeline_dict[style]init_img, h, w = preprocess_img(init_img)print(f'img size: {h, w}')sample = pipeline(image=init_img,prompt=prompt_textbox,negative_prompt=negative_prompt_textbox,generator=generator,num_inference_steps=sample_step_slider,guidance_scale=cfg_scale_slider,width=w,height=h,video_length=16,mask_sim_template_idx=motion_scale - 1,ip_adapter_scale=ip_adapter_scale,progress_fn=progress,).videossave_sample_path_mp4 = os.path.join(self.savedir_sample, f"{sample_idx}.mp4")save_sample_path_gif = os.path.join(self.savedir_sample, f"{sample_idx}.gif")save_videos_grid(sample, save_sample_path_mp4)save_videos_grid(sample, save_sample_path_gif)sample_config = {"prompt": prompt_textbox,"n_prompt": negative_prompt_textbox,"num_inference_steps": sample_step_slider,"guidance_scale": cfg_scale_slider,"width": w,"height": h,"seed": seed,"motion": motion_scale,}print(sample_config)json_str = json.dumps(sample_config, indent=4)with open(os.path.join(self.savedir, "logs.json"), "a") as f:f.write(json_str)f.write("\n\n")sample_idx += 1return (save_sample_path_mp4,[save_sample_path_mp4, save_sample_path_gif])def animate_example(self,init_img,motion_scale,8 unmodified lineswith_text=False,text_idx=0,progress=gr.Progress(),):global sample_idxif init_img is None:gr.Warning('Please upload image or use example images.')if seed_textbox != -1 and seed_textbox != "":torch.manual_seed(int(seed_textbox))53 unmodified linesadd_text(save_sample_path_gif, save_sample_path_mp4, text_idx)sample_idx += 1return (save_sample_path_mp4,[save_sample_path_mp4, save_sample_path_gif],example_img,seed,motion_scale,cfg_scale_slider,)controller = AnimateController()122 unmodified linesresult_video = gr.Video(label="Generated Animation", interactive=False)with gr.Row():download = gr.Files(file_types=['gif', 'mp4'], label='Donwload Output')generate_button.click(fn=controller.animate,7 unmodified linesseed_textbox,ip_adapter_scale,style_dropdown,],outputs=[result_video, download])default_1.click(fn=controller.animate_example,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_1_idx,],outputs=[result_video,download,example_img,default_seed,default_motion,default_cfg,])default_2.click(fn=controller.animate_example,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_2_idx,],outputs=[result_video,download,example_img,default_seed,default_motion,default_cfg,])default_3.click(fn=controller.animate_example,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_3_idx,],outputs=[result_video,download,example_img,default_seed,default_motion,default_cfg,])default_4.click(fn=controller.animate_example,inputs=[init_img,default_motion,8 unmodified lineswith_wishes,default_4_idx,],outputs=[result_video,download,example_img,default_seed,default_motion,default_cfg,])def create_example(input_list):return gr.Examples(
app-huggingface.py+126-29