@@ -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" )
0 commit comments