Skip to content

Commit 3ae4f34

Browse files
committed
feat(add more image generation variants):
1 parent 1ba6c58 commit 3ae4f34

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ garak_rest.json
1515
2025.*.json
1616
inv/
1717
scripts/
18+
docx/

agentic_security/probe_data/image_generator.py

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,70 @@ def generate_image_dataset(
3838

3939

4040
@cache_to_disk()
41-
def generate_image(prompt: str) -> bytes:
41+
def generate_image(prompt: str, variant: int = 0) -> bytes:
4242
"""
4343
Generate an image based on the provided prompt and return it as bytes.
4444
4545
Parameters:
4646
prompt (str): Text to display on the generated image.
47+
variant (int): The variant style of the image.
4748
4849
Returns:
4950
bytes: The image data in JPG format.
5051
"""
5152
# Create a matplotlib figure
5253
fig, ax = plt.subplots(figsize=(6, 4))
5354

54-
# Customize the plot (background color, text, etc.)
55-
ax.set_facecolor("lightblue")
56-
ax.text(
57-
0.5,
58-
0.5,
59-
prompt,
60-
fontsize=16,
61-
ha="center",
62-
va="center",
63-
wrap=True,
64-
color="darkblue",
65-
)
55+
# Customize the plot based on the variant
56+
if variant == 1:
57+
# Dark Theme
58+
ax.set_facecolor("darkgray")
59+
text_color = "white"
60+
fontsize = 18
61+
elif variant == 2:
62+
# Artistic Theme
63+
ax.set_facecolor("lightpink")
64+
text_color = "black"
65+
fontsize = 20
66+
# Add a border around the text
67+
ax.text(
68+
0.5,
69+
0.5,
70+
prompt,
71+
fontsize=fontsize,
72+
ha="center",
73+
va="center",
74+
wrap=True,
75+
color=text_color,
76+
bbox=dict(
77+
facecolor="lightyellow", edgecolor="black", boxstyle="round,pad=0.5"
78+
),
79+
)
80+
elif variant == 3:
81+
# Minimalist Theme
82+
ax.set_facecolor("white")
83+
text_color = "black"
84+
fontsize = 14
85+
# Add a simple geometric shape (circle) behind the text
86+
circle = plt.Circle((0.5, 0.5), 0.3, color="lightblue", fill=True)
87+
ax.add_artist(circle)
88+
else:
89+
# Default Theme
90+
ax.set_facecolor("lightblue")
91+
text_color = "darkblue"
92+
fontsize = 16
93+
94+
if variant != 2:
95+
ax.text(
96+
0.5,
97+
0.5,
98+
prompt,
99+
fontsize=fontsize,
100+
ha="center",
101+
va="center",
102+
wrap=True,
103+
color=text_color,
104+
)
66105

67106
# Remove axes for a cleaner look
68107
ax.axis("off")

agentic_security/probe_data/test_image_generator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest.mock import patch
2+
import pytest
23

34
from agentic_security.probe_data.image_generator import (
45
generate_image,
@@ -7,9 +8,10 @@
78
from agentic_security.probe_data.models import ImageProbeDataset, ProbeDataset
89

910

10-
def test_generate_image():
11+
@pytest.mark.parametrize("variant", [0, 1, 2, 3])
12+
def test_generate_image(variant):
1113
prompt = "Test prompt"
12-
image_bytes = generate_image(prompt)
14+
image_bytes = generate_image(prompt, variant)
1315

1416
assert isinstance(image_bytes, bytes)
1517
assert len(image_bytes) > 0

0 commit comments

Comments
 (0)