Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -29,13 +29,13 @@ device = "cuda"
|
|
29 |
dtype = torch.float16
|
30 |
result=[]
|
31 |
step = 2
|
32 |
-
repo = "ByteDance/AnimateDiff-Lightning"
|
33 |
-
ckpt = f"animatediff_lightning_{step}step_diffusers.safetensors"
|
34 |
#base = "emilianJR/epiCRealism"
|
35 |
base = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
|
36 |
-
#adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-3")
|
37 |
vae = AutoencoderKL.from_single_file("https://huggingface.co/stabilityai/sd-vae-ft-mse-original/vae-ft-mse-840000-ema-pruned.safetensors")
|
38 |
#unet = UNet2DConditionModel.from_config("emilianJR/epiCRealism",subfolder="unet").to(device, dtype).load_state_dict(load_file(hf_hub_download("emilianJR/epiCRealism", "unet/diffusion_pytorch_model.safetensors"), device=device), strict=False)
|
|
|
39 |
|
40 |
css="""
|
41 |
input, input::placeholder {
|
@@ -128,10 +128,10 @@ def generate_random_string(length):
|
|
128 |
return ''.join(random.choice(characters) for _ in range(length))
|
129 |
|
130 |
@spaces.GPU(duration=65)
|
131 |
-
def Piper(positive,negative,motion):
|
132 |
global last_motion
|
133 |
|
134 |
-
pipe.unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device=device), strict=False)
|
135 |
|
136 |
if last_motion != motion:
|
137 |
pipe.unload_lora_weights()
|
@@ -145,6 +145,7 @@ def Piper(positive,negative,motion):
|
|
145 |
negative_prompt=negative,
|
146 |
height=896,
|
147 |
width=896,
|
|
|
148 |
num_inference_steps=step,
|
149 |
guidance_scale=1,
|
150 |
num_frames=(fps*time)
|
@@ -162,15 +163,15 @@ def infer(pm):
|
|
162 |
_do.append(f'{p1}')
|
163 |
posi = " ".join(_do)
|
164 |
|
165 |
-
out = Piper(posi,neg,pm["m"])
|
166 |
export_to_gif(out.frames[0],name,fps=fps)
|
167 |
return name
|
168 |
|
169 |
-
def run(m,p1,p2,*result):
|
170 |
|
171 |
p1_en = translate(p1,"english")
|
172 |
p2_en = translate(p2,"english")
|
173 |
-
pm = {"p":p1_en,"n":p2_en,"m":m}
|
174 |
ln = len(result)
|
175 |
print("images: "+str(ln))
|
176 |
rng = list(range(ln))
|
@@ -184,8 +185,17 @@ def run(m,p1,p2,*result):
|
|
184 |
|
185 |
return out
|
186 |
|
187 |
-
pipe = AnimateDiffPipeline.from_pretrained(base, vae=vae, torch_dtype=dtype).to(device)
|
188 |
-
pipe.scheduler = EulerDiscreteScheduler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
pipe.enable_free_init(method="butterworth", use_fast_sampling=False)
|
190 |
|
191 |
mp.set_start_method("spawn", force=True)
|
@@ -195,6 +205,8 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
195 |
gr.Markdown(f"""
|
196 |
# MULTI-LANGUAGE IMAGE GENERATOR
|
197 |
""")
|
|
|
|
|
198 |
with gr.Row():
|
199 |
prompt = gr.Textbox(
|
200 |
elem_id="prompt",
|
@@ -235,6 +247,6 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
235 |
|
236 |
gr.on(
|
237 |
triggers=[run_button.click, prompt.submit, prompt2.submit],
|
238 |
-
fn=run,inputs=[motion,prompt,prompt2,*result],outputs=result
|
239 |
)
|
240 |
demo.queue().launch()
|
|
|
29 |
dtype = torch.float16
|
30 |
result=[]
|
31 |
step = 2
|
32 |
+
#repo = "ByteDance/AnimateDiff-Lightning"
|
33 |
+
#ckpt = f"animatediff_lightning_{step}step_diffusers.safetensors"
|
34 |
#base = "emilianJR/epiCRealism"
|
35 |
base = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
|
|
|
36 |
vae = AutoencoderKL.from_single_file("https://huggingface.co/stabilityai/sd-vae-ft-mse-original/vae-ft-mse-840000-ema-pruned.safetensors")
|
37 |
#unet = UNet2DConditionModel.from_config("emilianJR/epiCRealism",subfolder="unet").to(device, dtype).load_state_dict(load_file(hf_hub_download("emilianJR/epiCRealism", "unet/diffusion_pytorch_model.safetensors"), device=device), strict=False)
|
38 |
+
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-3", torch_dtype=dtype)
|
39 |
|
40 |
css="""
|
41 |
input, input::placeholder {
|
|
|
128 |
return ''.join(random.choice(characters) for _ in range(length))
|
129 |
|
130 |
@spaces.GPU(duration=65)
|
131 |
+
def Piper(image,positive,negative,motion):
|
132 |
global last_motion
|
133 |
|
134 |
+
#pipe.unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device=device), strict=False)
|
135 |
|
136 |
if last_motion != motion:
|
137 |
pipe.unload_lora_weights()
|
|
|
145 |
negative_prompt=negative,
|
146 |
height=896,
|
147 |
width=896,
|
148 |
+
ip_adapter_image=image,
|
149 |
num_inference_steps=step,
|
150 |
guidance_scale=1,
|
151 |
num_frames=(fps*time)
|
|
|
163 |
_do.append(f'{p1}')
|
164 |
posi = " ".join(_do)
|
165 |
|
166 |
+
out = Piper(pm["i"],posi,neg,pm["m"])
|
167 |
export_to_gif(out.frames[0],name,fps=fps)
|
168 |
return name
|
169 |
|
170 |
+
def run(i,m,p1,p2,*result):
|
171 |
|
172 |
p1_en = translate(p1,"english")
|
173 |
p2_en = translate(p2,"english")
|
174 |
+
pm = {"p":p1_en,"n":p2_en,"m":m,"i":i}
|
175 |
ln = len(result)
|
176 |
print("images: "+str(ln))
|
177 |
rng = list(range(ln))
|
|
|
185 |
|
186 |
return out
|
187 |
|
188 |
+
pipe = AnimateDiffPipeline.from_pretrained(base, vae=vae, motion_adapter=adapter, torch_dtype=dtype).to(device)
|
189 |
+
pipe.scheduler = EulerDiscreteScheduler(
|
190 |
+
clip_sample=False,
|
191 |
+
beta_start=0.00085,
|
192 |
+
beta_end=0.012,
|
193 |
+
beta_schedule="linear",
|
194 |
+
timestep_spacing="trailing",
|
195 |
+
steps_offset=1
|
196 |
+
)
|
197 |
+
pipe.load_ip_adapter("h94/IP-Adapter", subfolder="models", weight_name="ip-adapter_sd15.bin")
|
198 |
+
pipe.enable_vae_slicing()
|
199 |
pipe.enable_free_init(method="butterworth", use_fast_sampling=False)
|
200 |
|
201 |
mp.set_start_method("spawn", force=True)
|
|
|
205 |
gr.Markdown(f"""
|
206 |
# MULTI-LANGUAGE IMAGE GENERATOR
|
207 |
""")
|
208 |
+
with gr.Row():
|
209 |
+
img = gr.Image(type="filepath")
|
210 |
with gr.Row():
|
211 |
prompt = gr.Textbox(
|
212 |
elem_id="prompt",
|
|
|
247 |
|
248 |
gr.on(
|
249 |
triggers=[run_button.click, prompt.submit, prompt2.submit],
|
250 |
+
fn=run,inputs=[img,motion,prompt,prompt2,*result],outputs=result
|
251 |
)
|
252 |
demo.queue().launch()
|