Yaron Koresh commited on
Commit
552490f
·
verified ·
1 Parent(s): 47bf657

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -107
app.py CHANGED
@@ -22,6 +22,56 @@ from diffusers import DiffusionPipeline, AnimateDiffPipeline, MotionAdapter, Eul
22
  import jax
23
  import jax.numpy as jnp
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def forest_schnell():
26
  PIPE = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16, token=os.getenv("hf_token")).to("cuda")
27
  return PIPE
@@ -85,8 +135,6 @@ def Piper(name,positive_prompt,negative,motion):
85
  global base
86
  global device
87
 
88
- progress((0, step))
89
-
90
  if last_motion != motion:
91
  pipe.unload_lora_weights()
92
  if motion != "":
@@ -107,47 +155,6 @@ def Piper(name,positive_prompt,negative,motion):
107
  export_to_gif(out.frames[0],name,fps=fps)
108
  return name
109
 
110
- css="""
111
- input, input::placeholder {
112
- text-align: center !important;
113
- }
114
- *, *::placeholder {
115
- font-family: Suez One !important;
116
- }
117
- h1,h2,h3,h4,h5,h6 {
118
- width: 100%;
119
- text-align: center;
120
- }
121
- footer {
122
- display: none !important;
123
- }
124
- #col-container {
125
- margin: 0 auto;
126
- max-width: 15cm;
127
- }
128
- .image-container {
129
- aspect-ratio: 576 / 1024 !important;
130
- }
131
- .dropdown-arrow {
132
- display: none !important;
133
- }
134
- *:has(>.btn) {
135
- display: flex;
136
- justify-content: space-evenly;
137
- align-items: center;
138
- }
139
- .btn {
140
- display: flex;
141
- }
142
- """
143
-
144
- js="""
145
- function custom(){
146
- document.querySelector("div#prompt input").setAttribute("maxlength","38")
147
- document.querySelector("div#prompt2 input").setAttribute("maxlength","38")
148
- }
149
- """
150
-
151
  def infer(pm):
152
  print("infer: started")
153
 
@@ -180,65 +187,42 @@ def run(m,p1,p2,*result):
180
 
181
  return out
182
 
183
- def main():
184
-
185
- global result
186
- global pipe
187
- global device
188
- global step
189
- global dtype
190
- global progress
191
- global fps
192
- global time
193
- global last_motion
194
- global base
195
-
196
- last_motion=None
197
- fps=20
198
- time=16
199
- device = "cuda"
200
- dtype = torch.float16
201
- result=[]
202
- step = 2
203
-
204
- progress=gr.Progress()
205
-
206
- adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-3")
207
- vae = AutoencoderKL.from_single_file("https://huggingface.co/stabilityai/sd-vae-ft-mse-original/vae-ft-mse-840000-ema-pruned.safetensors")
208
- 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)
209
 
210
- repo = "ByteDance/AnimateDiff-Lightning"
211
- ckpt = f"animatediff_lightning_{step}step_diffusers.safetensors"
212
- base = "black-forest-labs/FLUX.1-schnell"
213
- #base = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
214
 
215
- pipe = AnimateDiffPipeline.from_pretrained(base, vae=vae, motion_adapter=adapter, feature_extractor=None, image_encoder=None, unet=unet, torch_dtype=dtype, token=os.getenv("hf_token")).to(device)
216
- pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
217
- pipe.unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device=device), strict=False)
218
- pipe.enable_free_init(method="butterworth", use_fast_sampling=True)
219
 
220
- mp.set_start_method("spawn", force=True)
221
-
222
- with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
223
- with gr.Column(elem_id="col-container"):
224
- gr.Markdown(f"""
225
- # MULTI-LANGUAGE IMAGE GENERATOR
226
- """)
227
- with gr.Row():
228
- prompt = gr.Textbox(
229
- elem_id="prompt",
230
- placeholder="INCLUDE",
231
- container=False,
232
- max_lines=1
233
- )
234
- with gr.Row():
235
- prompt2 = gr.Textbox(
236
- elem_id="prompt2",
237
- placeholder="EXCLUDE",
238
- container=False,
239
- max_lines=1
240
- )
241
- with gr.Row():
242
  motion = gr.Dropdown(
243
  label='Motion',
244
  show_label=False,
@@ -256,17 +240,14 @@ def main():
256
  value="",
257
  interactive=True
258
  )
259
- with gr.Row():
260
  run_button = gr.Button("START",elem_classes="btn",scale=0)
261
- with gr.Row():
262
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
263
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
264
 
265
- gr.on(
266
  triggers=[run_button.click, prompt.submit, prompt2.submit],
267
  fn=run,inputs=[motion,prompt,prompt2,*result],outputs=result
268
- )
269
- demo.queue().launch()
270
-
271
- if __name__ == "__main__":
272
- main()
 
22
  import jax
23
  import jax.numpy as jnp
24
 
25
+ last_motion=None
26
+ fps=20
27
+ time=16
28
+ device = "cuda"
29
+ dtype = torch.float16
30
+ result=[]
31
+ step = 2
32
+ progress=gr.Progress()
33
+
34
+ css="""
35
+ input, input::placeholder {
36
+ text-align: center !important;
37
+ }
38
+ *, *::placeholder {
39
+ font-family: Suez One !important;
40
+ }
41
+ h1,h2,h3,h4,h5,h6 {
42
+ width: 100%;
43
+ text-align: center;
44
+ }
45
+ footer {
46
+ display: none !important;
47
+ }
48
+ #col-container {
49
+ margin: 0 auto;
50
+ max-width: 15cm;
51
+ }
52
+ .image-container {
53
+ aspect-ratio: 576 / 1024 !important;
54
+ }
55
+ .dropdown-arrow {
56
+ display: none !important;
57
+ }
58
+ *:has(>.btn) {
59
+ display: flex;
60
+ justify-content: space-evenly;
61
+ align-items: center;
62
+ }
63
+ .btn {
64
+ display: flex;
65
+ }
66
+ """
67
+
68
+ js="""
69
+ function custom(){
70
+ document.querySelector("div#prompt input").setAttribute("maxlength","38")
71
+ document.querySelector("div#prompt2 input").setAttribute("maxlength","38")
72
+ }
73
+ """
74
+
75
  def forest_schnell():
76
  PIPE = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16, token=os.getenv("hf_token")).to("cuda")
77
  return PIPE
 
135
  global base
136
  global device
137
 
 
 
138
  if last_motion != motion:
139
  pipe.unload_lora_weights()
140
  if motion != "":
 
155
  export_to_gif(out.frames[0],name,fps=fps)
156
  return name
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  def infer(pm):
159
  print("infer: started")
160
 
 
187
 
188
  return out
189
 
190
+ adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-3")
191
+ vae = AutoencoderKL.from_single_file("https://huggingface.co/stabilityai/sd-vae-ft-mse-original/vae-ft-mse-840000-ema-pruned.safetensors")
192
+ 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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
+ repo = "ByteDance/AnimateDiff-Lightning"
195
+ ckpt = f"animatediff_lightning_{step}step_diffusers.safetensors"
196
+ base = "black-forest-labs/FLUX.1-schnell"
197
+ #base = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
198
 
199
+ pipe = AnimateDiffPipeline.from_pretrained(base, vae=vae, motion_adapter=adapter, feature_extractor=None, image_encoder=None, unet=unet, torch_dtype=dtype, token=os.getenv("hf_token")).to(device)
200
+ pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
201
+ pipe.unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device=device), strict=False)
202
+ pipe.enable_free_init(method="butterworth", use_fast_sampling=True)
203
 
204
+ mp.set_start_method("spawn", force=True)
205
+
206
+ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
207
+ with gr.Column(elem_id="col-container"):
208
+ gr.Markdown(f"""
209
+ # MULTI-LANGUAGE IMAGE GENERATOR
210
+ """)
211
+ with gr.Row():
212
+ prompt = gr.Textbox(
213
+ elem_id="prompt",
214
+ placeholder="INCLUDE",
215
+ container=False,
216
+ max_lines=1
217
+ )
218
+ with gr.Row():
219
+ prompt2 = gr.Textbox(
220
+ elem_id="prompt2",
221
+ placeholder="EXCLUDE",
222
+ container=False,
223
+ max_lines=1
224
+ )
225
+ with gr.Row():
226
  motion = gr.Dropdown(
227
  label='Motion',
228
  show_label=False,
 
240
  value="",
241
  interactive=True
242
  )
243
+ with gr.Row():
244
  run_button = gr.Button("START",elem_classes="btn",scale=0)
245
+ with gr.Row():
246
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
247
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
248
 
249
+ gr.on(
250
  triggers=[run_button.click, prompt.submit, prompt2.submit],
251
  fn=run,inputs=[motion,prompt,prompt2,*result],outputs=result
252
+ )
253
+ demo.queue().launch()