mahan_ym
commited on
Commit
·
50d1d7a
1
Parent(s):
e4ccc11
change input prompts
Browse files- src/tools.py +4 -15
src/tools.py
CHANGED
@@ -51,21 +51,18 @@ def privacy_preserve_image(
|
|
51 |
|
52 |
Args:
|
53 |
input_img: Input image or can be URL string of the image or base64 string. Cannot be None.
|
54 |
-
input_prompt (str): Object to obscure in the image
|
55 |
privacy_strength (int): Strength of the privacy preservation effect. Higher values result in stronger blurring. Default is 15.
|
56 |
Returns:
|
57 |
bytes: Binary image data of the modified image.
|
58 |
|
59 |
example:
|
60 |
-
input_prompt =
|
61 |
""" # noqa: E501
|
62 |
if not input_img:
|
63 |
raise gr.Error("Input image cannot be None or empty.")
|
64 |
-
valid_pattern = re.compile(r"^[a-zA-Z\s.]+$")
|
65 |
if not input_prompt or input_prompt.strip() == "":
|
66 |
raise gr.Error("Input prompt cannot be None or empty.")
|
67 |
-
if not valid_pattern.match(input_prompt):
|
68 |
-
raise gr.Error("Input prompt must contain only letters, spaces, and dots.")
|
69 |
|
70 |
func = modal.Function.from_name(modal_app_name, "preserve_privacy")
|
71 |
output_pil = func.remote(
|
@@ -99,7 +96,7 @@ def change_color_objects_hsv(
|
|
99 |
|
100 |
Args:
|
101 |
input_img: Input image or can be URL string of the image or base64 string. Cannot be None.
|
102 |
-
user_input : A list of target specifications for color transformation. Each inner list must contain exactly four elements in the following order: 1. target_object (str) - A short, human-readable description of the object to be modified. Multi-word
|
103 |
|
104 |
Returns:
|
105 |
Base64-encoded string.
|
@@ -198,7 +195,7 @@ def change_color_objects_lab(
|
|
198 |
- Purple: (L=?, A≈180, B≈100)
|
199 |
|
200 |
Args:
|
201 |
-
user_input: A list of color transformation instructions, each as a three-element list:[object_name (str), new_a (int, 0-255), new_b (int, 0-255)].- object_name: A short, unique identifier for the object to be recolored. Multi-word names are allowed
|
202 |
input_img : Input image can be URL string of the image. Cannot be None.
|
203 |
|
204 |
Returns:
|
@@ -256,13 +253,5 @@ def change_color_objects_lab(
|
|
256 |
raise TypeError(
|
257 |
f"Expected Image.Image from modal remote function, got {type(output_pil)}"
|
258 |
)
|
259 |
-
# img_link = upload_image_to_tmpfiles(output_pil)
|
260 |
|
261 |
return output_pil
|
262 |
-
|
263 |
-
|
264 |
-
if __name__ == "__main__":
|
265 |
-
image_pil = Image.open("./src/assets/test_image.jpg")
|
266 |
-
change_color_objects_hsv(
|
267 |
-
user_input=[["hair", 30, 1.2], ["shirt", 60, 1.0]], input_img=image_pil
|
268 |
-
)
|
|
|
51 |
|
52 |
Args:
|
53 |
input_img: Input image or can be URL string of the image or base64 string. Cannot be None.
|
54 |
+
input_prompt (str): Object to obscure in the image. It can be a single word or multiple words, e.g., "left person face", "license plate".
|
55 |
privacy_strength (int): Strength of the privacy preservation effect. Higher values result in stronger blurring. Default is 15.
|
56 |
Returns:
|
57 |
bytes: Binary image data of the modified image.
|
58 |
|
59 |
example:
|
60 |
+
input_prompt = "faces, license plates, logos"
|
61 |
""" # noqa: E501
|
62 |
if not input_img:
|
63 |
raise gr.Error("Input image cannot be None or empty.")
|
|
|
64 |
if not input_prompt or input_prompt.strip() == "":
|
65 |
raise gr.Error("Input prompt cannot be None or empty.")
|
|
|
|
|
66 |
|
67 |
func = modal.Function.from_name(modal_app_name, "preserve_privacy")
|
68 |
output_pil = func.remote(
|
|
|
96 |
|
97 |
Args:
|
98 |
input_img: Input image or can be URL string of the image or base64 string. Cannot be None.
|
99 |
+
user_input : A list of target specifications for color transformation. Each inner list must contain exactly four elements in the following order: 1. target_object (str) - A short, human-readable description of the object to be modified. Multi-word, descriptions are allowed for disambiguation (e.g., "right person shirt"), but they must be concise and free of punctuation, symbols, or special characters.2. Red (int) - Desired red value in RGB color space from 0 to 255. 3. Green (int) - Desired green value in RGB color space from 0 to 255. 4. Blue (int) - Desired blue value in RGB color space from 0 to 255. Example: user_input = [["hair", 30, 55, 255], ["shirt", 70, 0 , 157]].
|
100 |
|
101 |
Returns:
|
102 |
Base64-encoded string.
|
|
|
195 |
- Purple: (L=?, A≈180, B≈100)
|
196 |
|
197 |
Args:
|
198 |
+
user_input: A list of color transformation instructions, each as a three-element list:[object_name (str), new_a (int, 0-255), new_b (int, 0-255)].- object_name: A short, unique identifier for the object to be recolored. Multi-word names are allowed for specificity (e.g., "right person shirt") but must be free of punctuation or special symbols.- new_a: The desired 'a' channel value in LAB space (green-red axis, 0-255, with 128 as neutral).- new_b: The desired 'b' channel value in LAB space (blue-yellow axis, 0-255, with 128 as neutral).Each object must appear only once in the list. Example:[["hair", 80, 128], ["right person shirt", 180, 160]]
|
199 |
input_img : Input image can be URL string of the image. Cannot be None.
|
200 |
|
201 |
Returns:
|
|
|
253 |
raise TypeError(
|
254 |
f"Expected Image.Image from modal remote function, got {type(output_pil)}"
|
255 |
)
|
|
|
256 |
|
257 |
return output_pil
|
|
|
|
|
|
|
|
|
|
|
|
|
|