Slawek Biel commited on
Commit ·
a738611
1
Parent(s): b93826b
testing diffusers version
Browse files- handler.py +27 -17
- requirements.txt +1 -0
handler.py
CHANGED
|
@@ -4,7 +4,16 @@ from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
|
| 4 |
from PIL import Image
|
| 5 |
from skimage.exposure import match_histograms, adjust_gamma
|
| 6 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
class EndpointHandler():
|
| 10 |
def __init__(self, path=""):
|
|
@@ -39,23 +48,24 @@ class EndpointHandler():
|
|
| 39 |
return ret
|
| 40 |
|
| 41 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
all_stories
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
def match_colors(src,tar):
|
| 61 |
ret = match_histograms(np.array(tar), np.array(src), multichannel=True)
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from skimage.exposure import match_histograms, adjust_gamma
|
| 6 |
import numpy as np
|
| 7 |
+
import diffusers
|
| 8 |
+
def image_grid(imgs, rows, cols):
|
| 9 |
+
assert len(imgs) == rows*cols
|
| 10 |
|
| 11 |
+
w, h = imgs[0].size
|
| 12 |
+
grid = Image.new('RGB', size=(cols*w, rows*h))
|
| 13 |
+
|
| 14 |
+
for i, img in enumerate(imgs):
|
| 15 |
+
grid.paste(img, box=(i%cols*w, i//cols*h))
|
| 16 |
+
return grid
|
| 17 |
|
| 18 |
class EndpointHandler():
|
| 19 |
def __init__(self, path=""):
|
|
|
|
| 48 |
return ret
|
| 49 |
|
| 50 |
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
| 51 |
+
return diffusers.__version__
|
| 52 |
+
# prompts = data["prompts"]
|
| 53 |
+
# num_images_per_prompt = data.get("num_images_per_prompt", 1)
|
| 54 |
+
# do_img2img = data.get("do_img2img", True)
|
| 55 |
+
# match_histogram = data.get("match_histogram", True)
|
| 56 |
+
# adjust_contrast = data.get("adjust_contrast", True)
|
| 57 |
+
# num_inference_steps = data.get("num_inference_steps", 25)
|
| 58 |
+
# guidance_scale = data.pop("guidance_scale", 7.5)
|
| 59 |
+
# all_stories = []
|
| 60 |
+
# for _ in range(num_images_per_prompt):
|
| 61 |
+
# story = self.generate_story(prompts, do_img2img, num_inference_steps, guidance_scale)
|
| 62 |
+
# if match_histogram:
|
| 63 |
+
# story = [match_colors(story[0], img) for img in story]
|
| 64 |
+
# if adjust_contrast:
|
| 65 |
+
# story = [add_contrast(img) for img in story]
|
| 66 |
+
# all_stories.append(story)
|
| 67 |
+
# all_stories = [self.generate_story(prompts, do_img2img, num_inference_steps, guidance_scale) for _ in range(num_images_per_prompt)]
|
| 68 |
+
# return all_stories
|
| 69 |
|
| 70 |
def match_colors(src,tar):
|
| 71 |
ret = match_histograms(np.array(tar), np.array(src), multichannel=True)
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
scikit-image
|
|
|
|
|
|
| 1 |
scikit-image
|
| 2 |
+
git+https://github.com/huggingface/diffusers@4fc7084875ac
|