patrickvonplaten commited on
Commit
4a092d4
1 Parent(s): 10fe40c

Clean up image transformation (#3)

Browse files

- Clean up image transformation (1f7e59ac919006647ff801d9d673da0b62945f97)

Files changed (1) hide show
  1. image_transformation.py +4 -7
image_transformation.py CHANGED
@@ -6,7 +6,6 @@ from transformers.tools.base import Tool, get_default_device
6
  from transformers.utils import (
7
  is_accelerate_available,
8
  is_diffusers_available,
9
- is_opencv_available,
10
  is_vision_available,
11
  )
12
 
@@ -17,9 +16,6 @@ if is_vision_available():
17
  if is_diffusers_available():
18
  from diffusers import DiffusionPipeline
19
 
20
- if is_opencv_available():
21
- import cv2
22
-
23
 
24
  IMAGE_TRANSFORMATION_DESCRIPTION = (
25
  "This is a tool that transforms an image according to a prompt. It takes two inputs: `image`, which should be "
@@ -41,8 +37,6 @@ class ImageTransformationTool(Tool):
41
  raise ImportError("Diffusers should be installed in order to use the StableDiffusionTool.")
42
  if not is_vision_available():
43
  raise ImportError("Pillow should be installed in order to use the StableDiffusionTool.")
44
- if not is_opencv_available():
45
- raise ImportError("opencv should be installed in order to use the StableDiffusionTool.")
46
 
47
  super().__init__()
48
 
@@ -63,10 +57,13 @@ class ImageTransformationTool(Tool):
63
 
64
  self.is_initialized = True
65
 
66
- def __call__(self, image, prompt, negative_prompt="low quality, bad quality, deformed, low resolution", added_prompt=" , highest quality, highly realistic, very high resolution"):
67
  if not self.is_initialized:
68
  self.setup()
69
 
 
 
 
70
  return self.pipeline(
71
  prompt + added_prompt,
72
  image,
 
6
  from transformers.utils import (
7
  is_accelerate_available,
8
  is_diffusers_available,
 
9
  is_vision_available,
10
  )
11
 
 
16
  if is_diffusers_available():
17
  from diffusers import DiffusionPipeline
18
 
 
 
 
19
 
20
  IMAGE_TRANSFORMATION_DESCRIPTION = (
21
  "This is a tool that transforms an image according to a prompt. It takes two inputs: `image`, which should be "
 
37
  raise ImportError("Diffusers should be installed in order to use the StableDiffusionTool.")
38
  if not is_vision_available():
39
  raise ImportError("Pillow should be installed in order to use the StableDiffusionTool.")
 
 
40
 
41
  super().__init__()
42
 
 
57
 
58
  self.is_initialized = True
59
 
60
+ def __call__(self, image, prompt):
61
  if not self.is_initialized:
62
  self.setup()
63
 
64
+ negative_prompt = "low quality, bad quality, deformed, low resolution"
65
+ added_prompt = " , highest quality, highly realistic, very high resolution"
66
+
67
  return self.pipeline(
68
  prompt + added_prompt,
69
  image,