Yaron Koresh commited on
Commit
10260dd
·
verified ·
1 Parent(s): 616aab0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -9,19 +9,20 @@ import requests
9
  import gradio as gr
10
  import numpy as np
11
  from lxml.html import fromstring
12
- from transformers import pipeline
13
  from torch import multiprocessing as mp, nn
14
  #from torch.multiprocessing import Pool
15
  #from pathos.multiprocessing import ProcessPool as Pool
16
- from pathos.threading import ThreadPool as Pool
17
- from diffusers.pipelines.flux import FluxPipeline
18
  from diffusers.utils import export_to_gif, load_image
19
  from diffusers.models.modeling_utils import ModelMixin
20
  from huggingface_hub import hf_hub_download
21
  from safetensors.torch import load_file, save_file
22
  from diffusers import DiffusionPipeline, AnimateDiffPipeline, MotionAdapter, EulerDiscreteScheduler, DDIMScheduler, StableDiffusionXLPipeline, UNet2DConditionModel, AutoencoderKL, UNet3DConditionModel
23
- import jax
24
- import jax.numpy as jnp
 
25
  import sys
26
  import warnings
27
 
@@ -210,17 +211,11 @@ def run(i,m,p1,p2,*result):
210
  p2_en = translate(p2,"english")
211
  pm = {"p":p1_en,"n":p2_en,"m":m,"i":i}
212
  ln = len(result)
213
- print("Threads: "+str(ln))
214
  rng = list(range(ln))
215
-
216
  arr = [pm for _ in rng]
217
- pool = Pool(ln)
218
- out = list(pool.imap(infer,arr))
219
- pool.close()
220
- pool.join()
221
- pool.clear()
222
 
223
- return out
 
224
 
225
  pipe = AnimateDiffPipeline.from_pretrained(base, motion_adapter=adapter, torch_dtype=dtype).to(device)
226
  pipe.scheduler = DDIMScheduler(
 
9
  import gradio as gr
10
  import numpy as np
11
  from lxml.html import fromstring
12
+ #from transformers import pipeline
13
  from torch import multiprocessing as mp, nn
14
  #from torch.multiprocessing import Pool
15
  #from pathos.multiprocessing import ProcessPool as Pool
16
+ #from pathos.threading import ThreadPool as Pool
17
+ #from diffusers.pipelines.flux import FluxPipeline
18
  from diffusers.utils import export_to_gif, load_image
19
  from diffusers.models.modeling_utils import ModelMixin
20
  from huggingface_hub import hf_hub_download
21
  from safetensors.torch import load_file, save_file
22
  from diffusers import DiffusionPipeline, AnimateDiffPipeline, MotionAdapter, EulerDiscreteScheduler, DDIMScheduler, StableDiffusionXLPipeline, UNet2DConditionModel, AutoencoderKL, UNet3DConditionModel
23
+ #import jax
24
+ #import jax.numpy as jnp
25
+ from pyina.launchers import TorqueMpiPool as Pool
26
  import sys
27
  import warnings
28
 
 
211
  p2_en = translate(p2,"english")
212
  pm = {"p":p1_en,"n":p2_en,"m":m,"i":i}
213
  ln = len(result)
 
214
  rng = list(range(ln))
 
215
  arr = [pm for _ in rng]
 
 
 
 
 
216
 
217
+ with Pool(f'{ ln }:ppn=2', queue='productionQ', timelimit='5:00:00', workdir='.') as pool:
218
+ return pool.map(infer,arr)
219
 
220
  pipe = AnimateDiffPipeline.from_pretrained(base, motion_adapter=adapter, torch_dtype=dtype).to(device)
221
  pipe.scheduler = DDIMScheduler(