Spaces:
Sleeping
Sleeping
Update src/image_functions.py
Browse files- src/image_functions.py +14 -3
src/image_functions.py
CHANGED
|
@@ -73,13 +73,24 @@ def _encode_image_to_base64(image_path):
|
|
| 73 |
return ""
|
| 74 |
|
| 75 |
|
| 76 |
-
def generate_image(file_path, size, quality, category, sentiment, user_prompt, platform, blur):
|
| 77 |
try:
|
| 78 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 79 |
if not api_key:
|
| 80 |
logger.critical("OPENAI_API_KEY is not set.")
|
| 81 |
raise RuntimeError("OPENAI_API_KEY is missing")
|
| 82 |
client = OpenAI(api_key=api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
with open(file_path, "rb") as img_file:
|
| 85 |
if blur:
|
|
@@ -91,9 +102,9 @@ def generate_image(file_path, size, quality, category, sentiment, user_prompt, p
|
|
| 91 |
prompt=(
|
| 92 |
f"You are a top-tier performance digital marketer and creative strategist with 15+ years of expertise in affiliate marketing.\n"
|
| 93 |
f"Your objective is to analyze the provided winning ad image, deconstruct its concept, visual composition, and color scheme, and generate a fresh, conversion-focused ad visual tailored for the {category} niche.\n"
|
| 94 |
-
f"The new design should convey a {sentiment} sentiment and incorporate the user instruction: {user_prompt}.\n"
|
| 95 |
f"Create a visually compelling ad optimized for {platform} Ads that is scroll-stopping, pattern-interrupting, and designed to drive high CTR and Conversion Rate. Utilize striking color combinations, dynamic contrast levels, and strategic layout compositions to command attention while aligning with the target audience avatar.\n"
|
| 96 |
-
f"Make sure the images should be realistic, not be stocky at all and raw which should look like they are shot from an iPhone with {background}."
|
| 97 |
),
|
| 98 |
image=img_file,
|
| 99 |
size=size,
|
|
|
|
| 73 |
return ""
|
| 74 |
|
| 75 |
|
| 76 |
+
def generate_image(file_path, size, quality, category, sentiment, user_prompt, platform, blur, i=None):
|
| 77 |
try:
|
| 78 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 79 |
if not api_key:
|
| 80 |
logger.critical("OPENAI_API_KEY is not set.")
|
| 81 |
raise RuntimeError("OPENAI_API_KEY is missing")
|
| 82 |
client = OpenAI(api_key=api_key)
|
| 83 |
+
|
| 84 |
+
if platform == "Google Display Network":
|
| 85 |
+
size_messages = {
|
| 86 |
+
0: "The aspect ratio of the image should be 1024x1024",
|
| 87 |
+
1: "The aspect ratio of the image should be 1536x1024.",
|
| 88 |
+
2: "The aspect ratio of the image should be 1024x1536.",
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
img_size = size_messages.get(i, "")
|
| 92 |
+
else:
|
| 93 |
+
img_size = ""
|
| 94 |
|
| 95 |
with open(file_path, "rb") as img_file:
|
| 96 |
if blur:
|
|
|
|
| 102 |
prompt=(
|
| 103 |
f"You are a top-tier performance digital marketer and creative strategist with 15+ years of expertise in affiliate marketing.\n"
|
| 104 |
f"Your objective is to analyze the provided winning ad image, deconstruct its concept, visual composition, and color scheme, and generate a fresh, conversion-focused ad visual tailored for the {category} niche.\n"
|
| 105 |
+
f"The new design should convey a {sentiment} sentiment and incorporate the user instruction: \n {user_prompt}.\n If user has given multple choices or options to be include in the image so choose randomly relevant to the reference image."
|
| 106 |
f"Create a visually compelling ad optimized for {platform} Ads that is scroll-stopping, pattern-interrupting, and designed to drive high CTR and Conversion Rate. Utilize striking color combinations, dynamic contrast levels, and strategic layout compositions to command attention while aligning with the target audience avatar.\n"
|
| 107 |
+
f"Make sure the images should be realistic, not be stocky at all and raw which should look like they are shot from an iPhone with {background}.{img_size}"
|
| 108 |
),
|
| 109 |
image=img_file,
|
| 110 |
size=size,
|