Update
Browse files52 unmodified lines53545556575859606162636465666768697071727374757677787980818283848586878889909192939413 unmodified lines1081091101111121131141 unmodified line11611711811912012112291 unmodified lines21421521621721821922022122222322422522622722822923023152 unmodified linesexample_image = Image.open("imgs/example.jpg").convert("RGB")def load_example(steps: int,randomize_seed: bool,seed: int,randomize_cfg: bool,text_cfg_scale: float,image_cfg_scale: float,):example_instruction = random.choice(example_instructions)return [example_image, example_instruction] + generate(example_image,example_instruction,steps,randomize_seed,seed,randomize_cfg,text_cfg_scale,image_cfg_scale,)def generate(input_image: Image.Image,instruction: str,steps: int,randomize_seed: bool,seed: int,randomize_cfg: bool,text_cfg_scale: float,image_cfg_scale: float,progress=gr.Progress(track_tqdm=True),):seed = random.randint(0, 100000) if randomize_seed else seedtext_cfg_scale = round(random.uniform(6.0, 9.0), ndigits=2) if randomize_cfg else text_cfg_scaleimage_cfg_scale = round(random.uniform(1.2, 1.8), ndigits=2) if randomize_cfg else image_cfg_scalewidth, height = input_image.sizefactor = 512 / max(width, height)factor = math.ceil(min(width, height) * factor / 64) * 64 / min(width, height)13 unmodified linesnum_inference_steps=steps,generator=generator,).images[0]return [seed, text_cfg_scale, image_cfg_scale, edited_image]def reset():1 unmodified linedef process_example(input_image: Image.Image, instruction: str, seed: int) -> Image.Image:return generate(input_image, instruction, 50, False, seed, False, 7.5, 1.5)[-1]with gr.Blocks() as demo:91 unmodified linestext_cfg_scale.submit,image_cfg_scale.submit,],fn=generate,inputs=[input_image,instruction,steps,randomize_seed,seed,randomize_cfg,text_cfg_scale,image_cfg_scale,],outputs=[seed, text_cfg_scale, image_cfg_scale, edited_image],api_name="run",)52 unmodified lines5354555657585960616263646566676869707172737475767778798013 unmodified lines9495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301 unmodified line13213313413513613713891 unmodified lines23023123223323423523623723823924024124224324424524624724824925025125225325425525625752 unmodified linesexample_image = Image.open("imgs/example.jpg").convert("RGB")def randomize(randomize_seed: bool,seed: int,randomize_cfg: bool,text_cfg_scale: float,image_cfg_scale: float,) -> tuple[int, float, float]:seed = random.randint(0, 100000) if randomize_seed else seedtext_cfg_scale = round(random.uniform(6.0, 9.0), ndigits=2) if randomize_cfg else text_cfg_scaleimage_cfg_scale = round(random.uniform(1.2, 1.8), ndigits=2) if randomize_cfg else image_cfg_scalereturn seed, text_cfg_scale, image_cfg_scaledef generate(input_image: Image.Image,instruction: str,steps: int,seed: int,text_cfg_scale: float,image_cfg_scale: float,progress=gr.Progress(track_tqdm=True),) -> Image.Image:width, height = input_image.sizefactor = 512 / max(width, height)factor = math.ceil(min(width, height) * factor / 64) * 64 / min(width, height)13 unmodified linesnum_inference_steps=steps,generator=generator,).images[0]return edited_imagedef load_example(steps: int,randomize_seed: bool,seed: int,randomize_cfg: bool,text_cfg_scale: float,image_cfg_scale: float,progress=gr.Progress(track_tqdm=True),):example_instruction = random.choice(example_instructions)seed, text_cfg_scale, image_cfg_scale = randomize(randomize_seed, seed, randomize_cfg, text_cfg_scale, image_cfg_scale)return [example_image,example_instruction,seed,text_cfg_scale,image_cfg_scale,generate(example_image,example_instruction,steps,seed,text_cfg_scale,image_cfg_scale,),]def reset():1 unmodified linedef process_example(input_image: Image.Image, instruction: str, seed: int) -> Image.Image:return generate(input_image, instruction, 50, seed, 7.5, 1.5)with gr.Blocks() as demo:91 unmodified linestext_cfg_scale.submit,image_cfg_scale.submit,],fn=randomize,inputs=[randomize_seed,seed,randomize_cfg,text_cfg_scale,image_cfg_scale,],outputs=[seed, text_cfg_scale, image_cfg_scale],queue=False,api_name=False,).then(fn=generate,inputs=[input_image,instruction,steps,seed,text_cfg_scale,image_cfg_scale,],outputs=edited_image,api_name="run",)
edit_app.py+52-26