mirror of
https://github.com/msoedov/agentic_security.git
synced 2026-08-08 10:48:37 +02:00
feat(add more image generation variants):
This commit is contained in:
@@ -15,3 +15,4 @@ garak_rest.json
|
|||||||
2025.*.json
|
2025.*.json
|
||||||
inv/
|
inv/
|
||||||
scripts/
|
scripts/
|
||||||
|
docx/
|
||||||
|
|||||||
@@ -38,12 +38,13 @@ def generate_image_dataset(
|
|||||||
|
|
||||||
|
|
||||||
@cache_to_disk()
|
@cache_to_disk()
|
||||||
def generate_image(prompt: str) -> bytes:
|
def generate_image(prompt: str, variant: int = 0) -> bytes:
|
||||||
"""
|
"""
|
||||||
Generate an image based on the provided prompt and return it as bytes.
|
Generate an image based on the provided prompt and return it as bytes.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
prompt (str): Text to display on the generated image.
|
prompt (str): Text to display on the generated image.
|
||||||
|
variant (int): The variant style of the image.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bytes: The image data in JPG format.
|
bytes: The image data in JPG format.
|
||||||
@@ -51,18 +52,56 @@ def generate_image(prompt: str) -> bytes:
|
|||||||
# Create a matplotlib figure
|
# Create a matplotlib figure
|
||||||
fig, ax = plt.subplots(figsize=(6, 4))
|
fig, ax = plt.subplots(figsize=(6, 4))
|
||||||
|
|
||||||
# Customize the plot (background color, text, etc.)
|
# Customize the plot based on the variant
|
||||||
ax.set_facecolor("lightblue")
|
if variant == 1:
|
||||||
ax.text(
|
# Dark Theme
|
||||||
0.5,
|
ax.set_facecolor("darkgray")
|
||||||
0.5,
|
text_color = "white"
|
||||||
prompt,
|
fontsize = 18
|
||||||
fontsize=16,
|
elif variant == 2:
|
||||||
ha="center",
|
# Artistic Theme
|
||||||
va="center",
|
ax.set_facecolor("lightpink")
|
||||||
wrap=True,
|
text_color = "black"
|
||||||
color="darkblue",
|
fontsize = 20
|
||||||
)
|
# Add a border around the text
|
||||||
|
ax.text(
|
||||||
|
0.5,
|
||||||
|
0.5,
|
||||||
|
prompt,
|
||||||
|
fontsize=fontsize,
|
||||||
|
ha="center",
|
||||||
|
va="center",
|
||||||
|
wrap=True,
|
||||||
|
color=text_color,
|
||||||
|
bbox=dict(
|
||||||
|
facecolor="lightyellow", edgecolor="black", boxstyle="round,pad=0.5"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
elif variant == 3:
|
||||||
|
# Minimalist Theme
|
||||||
|
ax.set_facecolor("white")
|
||||||
|
text_color = "black"
|
||||||
|
fontsize = 14
|
||||||
|
# Add a simple geometric shape (circle) behind the text
|
||||||
|
circle = plt.Circle((0.5, 0.5), 0.3, color="lightblue", fill=True)
|
||||||
|
ax.add_artist(circle)
|
||||||
|
else:
|
||||||
|
# Default Theme
|
||||||
|
ax.set_facecolor("lightblue")
|
||||||
|
text_color = "darkblue"
|
||||||
|
fontsize = 16
|
||||||
|
|
||||||
|
if variant != 2:
|
||||||
|
ax.text(
|
||||||
|
0.5,
|
||||||
|
0.5,
|
||||||
|
prompt,
|
||||||
|
fontsize=fontsize,
|
||||||
|
ha="center",
|
||||||
|
va="center",
|
||||||
|
wrap=True,
|
||||||
|
color=text_color,
|
||||||
|
)
|
||||||
|
|
||||||
# Remove axes for a cleaner look
|
# Remove axes for a cleaner look
|
||||||
ax.axis("off")
|
ax.axis("off")
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
import pytest
|
||||||
|
|
||||||
from agentic_security.probe_data.image_generator import (
|
from agentic_security.probe_data.image_generator import (
|
||||||
generate_image,
|
generate_image,
|
||||||
@@ -7,9 +8,10 @@ from agentic_security.probe_data.image_generator import (
|
|||||||
from agentic_security.probe_data.models import ImageProbeDataset, ProbeDataset
|
from agentic_security.probe_data.models import ImageProbeDataset, ProbeDataset
|
||||||
|
|
||||||
|
|
||||||
def test_generate_image():
|
@pytest.mark.parametrize("variant", [0, 1, 2, 3])
|
||||||
|
def test_generate_image(variant):
|
||||||
prompt = "Test prompt"
|
prompt = "Test prompt"
|
||||||
image_bytes = generate_image(prompt)
|
image_bytes = generate_image(prompt, variant)
|
||||||
|
|
||||||
assert isinstance(image_bytes, bytes)
|
assert isinstance(image_bytes, bytes)
|
||||||
assert len(image_bytes) > 0
|
assert len(image_bytes) > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user