Yaron Koresh commited on
Commit
4deddd3
·
verified ·
1 Parent(s): 407bfc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -1,6 +1,7 @@
1
 
2
  # built-in
3
 
 
4
  import os
5
  import subprocess
6
  import logging
@@ -11,18 +12,15 @@ import requests
11
  import sys
12
  import warnings
13
  import time
14
- from concurrent.futures import ProcessPoolExecutor
15
- import threading
16
  import asyncio
17
- from queue import Queue as BlockingQueue
18
  from functools import partial
19
- from multiprocessing import Process, Queue
20
 
21
  # external
22
 
23
  import spaces
24
  import torch
25
  import gradio as gr
 
26
  from numpy import asarray as array
27
  from lxml.html import fromstring
28
  from diffusers.utils import export_to_gif, load_image
@@ -136,9 +134,9 @@ pipe_flux = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_d
136
 
137
  # Parallelism
138
 
139
- def parallel(workers,func,*args):
140
- with ProcessPoolExecutor(workers) as ex:
141
- res = ex.map(func, args)
142
  return list(res)
143
 
144
  # functionality
@@ -248,8 +246,9 @@ def handle_generate(*inp):
248
  inp[1] = ", ".join(_do)
249
 
250
  ln = len(result)
251
-
252
- pipe_out = parallel(ln,pipe_generate,inp[0],inp[1],inp[2],inp[3])
 
253
  names = []
254
  for i in pipe_out:
255
  name = generate_random_string(12)+".png"
 
1
 
2
  # built-in
3
 
4
+ from inspect import signature
5
  import os
6
  import subprocess
7
  import logging
 
12
  import sys
13
  import warnings
14
  import time
 
 
15
  import asyncio
 
16
  from functools import partial
 
17
 
18
  # external
19
 
20
  import spaces
21
  import torch
22
  import gradio as gr
23
+ from pathos.multiprocessing import ProcessPool as Pool
24
  from numpy import asarray as array
25
  from lxml.html import fromstring
26
  from diffusers.utils import export_to_gif, load_image
 
134
 
135
  # Parallelism
136
 
137
+ def parallel(func,*args):
138
+ with Pool(nodes=len(args)) as pool:
139
+ res = pool.imap(func, *args)
140
  return list(res)
141
 
142
  # functionality
 
246
  inp[1] = ", ".join(_do)
247
 
248
  ln = len(result)
249
+ parallel_args = [inp for i in range(ln)]
250
+
251
+ pipe_out = parallel( pipe_generate, *parallel_args )
252
  names = []
253
  for i in pipe_out:
254
  name = generate_random_string(12)+".png"