Spaces:
Sleeping
Sleeping
new endpoint and processing
Browse files- app/services/banner_service.py +26 -9
- app/services/bestnetwork_service.py +7 -5
- app/services/byop_service.py +39 -34
- app/services/custom_banner_desktop_service.py +20 -12
- app/services/custom_banner_ipad_service.py +21 -12
- app/services/custom_banner_mobile_service.py +20 -12
- app/services/custom_byop_service.py +20 -14
- app/services/custom_network_service.py +18 -6
- app/services/logo_service.py +1 -0
- app/services/single_text_logo_service.py +7 -2
- app/utils/name_generator.py +9 -0
app/services/banner_service.py
CHANGED
|
@@ -7,16 +7,32 @@ from PIL import Image, ImageEnhance, ImageOps, ImageFilter
|
|
| 7 |
import logging
|
| 8 |
from app.config.settings import settings
|
| 9 |
from app.utils.reach_upload import upload_to_reach
|
|
|
|
| 10 |
import math
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
| 15 |
-
def get_banner_prompts(
|
| 16 |
device_prompts = {
|
| 17 |
-
'desktop': f
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
return device_prompts
|
| 22 |
|
|
@@ -146,21 +162,22 @@ def process_images_for_devices(image_data: bytes) -> Dict[str, bytes]:
|
|
| 146 |
'mobile': process_image(image_data, 375, 500)
|
| 147 |
}
|
| 148 |
|
| 149 |
-
def generate_banner(
|
| 150 |
"""
|
| 151 |
Generate multiple variations of banner images for each device using Gemini and upload to Reach platform.
|
| 152 |
Returns a dictionary with URLs for different device sizes and prompt variations.
|
| 153 |
"""
|
| 154 |
api_key = settings.GEMINI_API_KEY
|
| 155 |
client = genai.Client(api_key=api_key)
|
| 156 |
-
|
|
|
|
| 157 |
# For now, we just create one prompt set — extendable later
|
| 158 |
-
base_prompt = get_banner_prompts(
|
| 159 |
all_prompt_sets = [base_prompt] # Add more prompt sets for more variations
|
| 160 |
|
| 161 |
all_banner_results = []
|
| 162 |
|
| 163 |
-
logger.info(f"Starting banner generation
|
| 164 |
|
| 165 |
# Device-specific dimensions
|
| 166 |
device_dimensions = {
|
|
@@ -214,7 +231,7 @@ def generate_banner(brand_name: str, domain: str, primary_color: str) -> Dict:
|
|
| 214 |
# Upload to Reach
|
| 215 |
result = upload_to_reach(
|
| 216 |
processed_image,
|
| 217 |
-
f"banner_{
|
| 218 |
image_format,
|
| 219 |
1,
|
| 220 |
device_file_types[device]
|
|
|
|
| 7 |
import logging
|
| 8 |
from app.config.settings import settings
|
| 9 |
from app.utils.reach_upload import upload_to_reach
|
| 10 |
+
from app.utils.name_generator import generate_brand_name
|
| 11 |
import math
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
| 15 |
|
| 16 |
+
def get_banner_prompts(brand_details: str, primary_color: str) -> Dict[str, str]:
|
| 17 |
device_prompts = {
|
| 18 |
+
'desktop': f'''Generate a realistic image which includes real people and
|
| 19 |
+
The image must show essence of the brand:
|
| 20 |
+
|
| 21 |
+
{brand_details}
|
| 22 |
+
|
| 23 |
+
Exclude the use of color {primary_color} in the palette. Do not Include any text, typographic or Alphanumeric Elements.''',
|
| 24 |
+
'ipad': f'''Generate a realistic image which includes real people and
|
| 25 |
+
The image must show essence of the brand:
|
| 26 |
+
|
| 27 |
+
{brand_details}
|
| 28 |
+
|
| 29 |
+
Exclude the use of color {primary_color} in the palette. Do not Include any text, typographic or Alphanumeric Elements.''',
|
| 30 |
+
'mobile': f'''Generate a realistic image which includes real people and
|
| 31 |
+
The image must show essence of the brand:
|
| 32 |
+
|
| 33 |
+
{brand_details}
|
| 34 |
+
|
| 35 |
+
Exclude the use of color {primary_color} in the palette. Do not Include any text, typographic or Alphanumeric Elements.''',
|
| 36 |
}
|
| 37 |
return device_prompts
|
| 38 |
|
|
|
|
| 162 |
'mobile': process_image(image_data, 375, 500)
|
| 163 |
}
|
| 164 |
|
| 165 |
+
def generate_banner(brand_details: str, primary_color: str) -> Dict:
|
| 166 |
"""
|
| 167 |
Generate multiple variations of banner images for each device using Gemini and upload to Reach platform.
|
| 168 |
Returns a dictionary with URLs for different device sizes and prompt variations.
|
| 169 |
"""
|
| 170 |
api_key = settings.GEMINI_API_KEY
|
| 171 |
client = genai.Client(api_key=api_key)
|
| 172 |
+
brand_name = generate_brand_name()
|
| 173 |
+
|
| 174 |
# For now, we just create one prompt set — extendable later
|
| 175 |
+
base_prompt = get_banner_prompts(brand_details, primary_color)
|
| 176 |
all_prompt_sets = [base_prompt] # Add more prompt sets for more variations
|
| 177 |
|
| 178 |
all_banner_results = []
|
| 179 |
|
| 180 |
+
logger.info(f"Starting banner generation with ID: {brand_name}")
|
| 181 |
|
| 182 |
# Device-specific dimensions
|
| 183 |
device_dimensions = {
|
|
|
|
| 231 |
# Upload to Reach
|
| 232 |
result = upload_to_reach(
|
| 233 |
processed_image,
|
| 234 |
+
f"banner_{brand_details}_{device}_v{variation_index}",
|
| 235 |
image_format,
|
| 236 |
1,
|
| 237 |
device_file_types[device]
|
app/services/bestnetwork_service.py
CHANGED
|
@@ -8,13 +8,14 @@ from PIL import Image, ImageEnhance, ImageOps
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
|
|
|
| 11 |
|
| 12 |
# Set up logging
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
| 15 |
|
| 16 |
-
def get_network_prompts(
|
| 17 |
-
prompt = f"Generate a realistic representation of
|
| 18 |
return prompt
|
| 19 |
|
| 20 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
|
@@ -78,15 +79,16 @@ def process_image(image_data: bytes, width: int = 530, height: int = 352) -> byt
|
|
| 78 |
return buffer.getvalue()
|
| 79 |
|
| 80 |
|
| 81 |
-
def generate_network_banner(
|
| 82 |
"""
|
| 83 |
Generates image banners based on prompts using Gemini API, processes them, uploads to Reach platform,
|
| 84 |
and returns URLs for the generated variations.
|
| 85 |
"""
|
| 86 |
-
|
|
|
|
| 87 |
api_key = settings.GEMINI_API_KEY
|
| 88 |
client = genai.Client(api_key=api_key)
|
| 89 |
-
prompt = get_network_prompts(
|
| 90 |
all_banner_results = []
|
| 91 |
|
| 92 |
try:
|
|
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
| 11 |
+
from app.utils.name_generator import generate_brand_name
|
| 12 |
|
| 13 |
# Set up logging
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
logging.basicConfig(level=logging.INFO)
|
| 16 |
|
| 17 |
+
def get_network_prompts(brand_details: str) -> str:
|
| 18 |
+
prompt = f"Generate a realistic representation of {brand_details}. Use real objects and people. Ensure elements are centered or balanced. DO NOT INCLUDE ANY TEXT IN THE IMAGE."
|
| 19 |
return prompt
|
| 20 |
|
| 21 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
|
|
|
| 79 |
return buffer.getvalue()
|
| 80 |
|
| 81 |
|
| 82 |
+
def generate_network_banner(brand_details: str) -> Dict:
|
| 83 |
"""
|
| 84 |
Generates image banners based on prompts using Gemini API, processes them, uploads to Reach platform,
|
| 85 |
and returns URLs for the generated variations.
|
| 86 |
"""
|
| 87 |
+
brand_name = generate_brand_name()
|
| 88 |
+
logger.info(f"Generating network banners with ID: {brand_name}")
|
| 89 |
api_key = settings.GEMINI_API_KEY
|
| 90 |
client = genai.Client(api_key=api_key)
|
| 91 |
+
prompt = get_network_prompts(brand_details)
|
| 92 |
all_banner_results = []
|
| 93 |
|
| 94 |
try:
|
app/services/byop_service.py
CHANGED
|
@@ -14,8 +14,8 @@ logger = logging.getLogger(__name__)
|
|
| 14 |
logger.setLevel(logging.INFO)
|
| 15 |
|
| 16 |
|
| 17 |
-
def get_byop_prompts(
|
| 18 |
-
prompt = f"Generate an realistic image which includes real people and displays the essence of
|
| 19 |
return prompt
|
| 20 |
|
| 21 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
|
@@ -82,17 +82,19 @@ def process_image(image_data: bytes, width: int = 530, height: int = 352) -> byt
|
|
| 82 |
return buffer.getvalue()
|
| 83 |
|
| 84 |
|
| 85 |
-
def generate_byop_banner(
|
| 86 |
"""
|
| 87 |
Generates BYOP banners using Gemini image generation API,
|
| 88 |
processes them, uploads to Reach platform, and returns their URLs.
|
| 89 |
"""
|
| 90 |
-
|
| 91 |
api_key = settings.GEMINI_API_KEY
|
| 92 |
client = genai.Client(api_key=api_key)
|
| 93 |
-
prompt = get_byop_prompts(
|
| 94 |
all_banner_results = []
|
| 95 |
|
|
|
|
|
|
|
| 96 |
try:
|
| 97 |
logger.info("Sending prompt to Gemini API")
|
| 98 |
response = client.models.generate_content(
|
|
@@ -106,36 +108,39 @@ def generate_byop_banner(brand_name: str, domain: str) -> Dict:
|
|
| 106 |
for part in response.candidates[0].content.parts:
|
| 107 |
if part.inline_data is not None:
|
| 108 |
try:
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
except Exception as e:
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
raise
|
| 139 |
|
| 140 |
except Exception as e:
|
| 141 |
logger.error(f"Error generating banner: {str(e)}")
|
|
|
|
| 14 |
logger.setLevel(logging.INFO)
|
| 15 |
|
| 16 |
|
| 17 |
+
def get_byop_prompts(brand_details: str) -> str:
|
| 18 |
+
prompt = f"Generate an realistic image which includes real people and displays the essence of {brand_details} and how it brings them together. Include real people in the image. DO NOT USE ANY TEXT, LETTERS, NUMBERS, OR TYPOGRAPHIC ELEMENTS."
|
| 19 |
return prompt
|
| 20 |
|
| 21 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
|
|
|
| 82 |
return buffer.getvalue()
|
| 83 |
|
| 84 |
|
| 85 |
+
def generate_byop_banner(brand_details: str) -> Dict:
|
| 86 |
"""
|
| 87 |
Generates BYOP banners using Gemini image generation API,
|
| 88 |
processes them, uploads to Reach platform, and returns their URLs.
|
| 89 |
"""
|
| 90 |
+
brand_name = generate_brand_name()
|
| 91 |
api_key = settings.GEMINI_API_KEY
|
| 92 |
client = genai.Client(api_key=api_key)
|
| 93 |
+
prompt = get_byop_prompts(brand_details)
|
| 94 |
all_banner_results = []
|
| 95 |
|
| 96 |
+
logger.info(f"Generating BYOP banners with ID: {brand_name}")
|
| 97 |
+
|
| 98 |
try:
|
| 99 |
logger.info("Sending prompt to Gemini API")
|
| 100 |
response = client.models.generate_content(
|
|
|
|
| 108 |
for part in response.candidates[0].content.parts:
|
| 109 |
if part.inline_data is not None:
|
| 110 |
try:
|
| 111 |
+
mime_type = part.inline_data.mime_type
|
| 112 |
+
image_data = part.inline_data.data
|
| 113 |
+
|
| 114 |
+
# Determine image format
|
| 115 |
+
if "jpeg" in mime_type or "jpg" in mime_type:
|
| 116 |
+
image_format = "jpeg"
|
| 117 |
+
elif "png" in mime_type:
|
| 118 |
+
image_format = "png"
|
| 119 |
+
elif "webp" in mime_type:
|
| 120 |
+
image_format = "webp"
|
| 121 |
+
else:
|
| 122 |
+
image_format = "jpeg" # Default to JPEG
|
| 123 |
+
|
| 124 |
+
logger.info("Processing banner image")
|
| 125 |
+
processed_image = process_image(image_data)
|
| 126 |
+
|
| 127 |
+
result = upload_to_reach(
|
| 128 |
+
processed_image,
|
| 129 |
+
f"byop_banner_{brand_name}",
|
| 130 |
+
image_format,
|
| 131 |
+
1,
|
| 132 |
+
'BYOD_IMAGE'
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
logger.info("Banner uploaded successfully")
|
| 136 |
+
all_banner_results.append({
|
| 137 |
+
"variation": 1,
|
| 138 |
+
"banner": result['url']
|
| 139 |
+
})
|
| 140 |
+
|
| 141 |
except Exception as e:
|
| 142 |
+
logger.error(f"Error processing banner image: {str(e)}")
|
| 143 |
+
raise
|
|
|
|
| 144 |
|
| 145 |
except Exception as e:
|
| 146 |
logger.error(f"Error generating banner: {str(e)}")
|
app/services/custom_banner_desktop_service.py
CHANGED
|
@@ -8,13 +8,21 @@ from PIL import Image, ImageEnhance, ImageOps
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
|
|
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
-
def get_desktop_prompt(
|
|
|
|
|
|
|
| 15 |
return f'''
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def process_image(image_data: bytes, target_width: int, target_height: int) -> bytes:
|
|
@@ -64,18 +72,21 @@ def process_image(image_data: bytes, target_width: int, target_height: int) -> b
|
|
| 64 |
|
| 65 |
return buffer.getvalue()
|
| 66 |
|
| 67 |
-
def generate_desktop_banner(
|
|
|
|
|
|
|
| 68 |
"""
|
| 69 |
Generate desktop banner using Gemini and upload to Reach platform.
|
| 70 |
Returns a dictionary with the image URL.
|
| 71 |
"""
|
|
|
|
| 72 |
api_key = settings.GEMINI_API_KEY
|
| 73 |
client = genai.Client(api_key=api_key)
|
| 74 |
|
| 75 |
-
logger.info(f"Starting desktop banner generation
|
| 76 |
|
| 77 |
try:
|
| 78 |
-
prompt = get_desktop_prompt(
|
| 79 |
response = client.models.generate_content(
|
| 80 |
model="gemini-2.0-flash-exp-image-generation",
|
| 81 |
contents=prompt,
|
|
@@ -100,19 +111,16 @@ def generate_desktop_banner(brand_name: str, domain: str, primary_color: str, de
|
|
| 100 |
logger.info(f"Processing desktop banner image (format: {image_format})")
|
| 101 |
|
| 102 |
# Process image
|
| 103 |
-
processed_image = process_image(image_data, 1440, 500)
|
| 104 |
-
|
| 105 |
-
# Upload to Reach platform
|
| 106 |
result = upload_to_reach(
|
| 107 |
processed_image,
|
| 108 |
f"custom_desktop_banner_{brand_name}",
|
| 109 |
image_format,
|
| 110 |
1,
|
| 111 |
"DESKTOP_IMAGE"
|
| 112 |
-
)
|
| 113 |
-
|
| 114 |
logger.info("Desktop banner uploaded successfully.")
|
| 115 |
-
return {"img_url": result
|
| 116 |
|
| 117 |
except Exception as error:
|
| 118 |
logger.error(f"Error processing desktop banner: {str(error)}")
|
|
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
| 11 |
+
from app.utils.name_generator import generate_brand_name
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
+
def get_desktop_prompt(
|
| 16 |
+
prompt: str, brand_details: str
|
| 17 |
+
) -> str:
|
| 18 |
return f'''
|
| 19 |
+
Based on the prompt: {prompt}
|
| 20 |
+
|
| 21 |
+
Create an realistic image that reflects this brand:
|
| 22 |
+
{brand_details}
|
| 23 |
+
|
| 24 |
+
The image must be professional and realistic, and must not contain any text, typographic or alphanumeric elements.
|
| 25 |
+
'''
|
| 26 |
|
| 27 |
|
| 28 |
def process_image(image_data: bytes, target_width: int, target_height: int) -> bytes:
|
|
|
|
| 72 |
|
| 73 |
return buffer.getvalue()
|
| 74 |
|
| 75 |
+
def generate_desktop_banner(
|
| 76 |
+
prompt: str, brand_details: str
|
| 77 |
+
) -> Dict[str, str]:
|
| 78 |
"""
|
| 79 |
Generate desktop banner using Gemini and upload to Reach platform.
|
| 80 |
Returns a dictionary with the image URL.
|
| 81 |
"""
|
| 82 |
+
brand_name = generate_brand_name()
|
| 83 |
api_key = settings.GEMINI_API_KEY
|
| 84 |
client = genai.Client(api_key=api_key)
|
| 85 |
|
| 86 |
+
logger.info(f"Starting desktop banner generation with ID: {brand_name}")
|
| 87 |
|
| 88 |
try:
|
| 89 |
+
prompt = get_desktop_prompt(prompt, brand_details)
|
| 90 |
response = client.models.generate_content(
|
| 91 |
model="gemini-2.0-flash-exp-image-generation",
|
| 92 |
contents=prompt,
|
|
|
|
| 111 |
logger.info(f"Processing desktop banner image (format: {image_format})")
|
| 112 |
|
| 113 |
# Process image
|
| 114 |
+
processed_image = process_image(image_data, 1440, 500) # Upload to Reach platform
|
|
|
|
|
|
|
| 115 |
result = upload_to_reach(
|
| 116 |
processed_image,
|
| 117 |
f"custom_desktop_banner_{brand_name}",
|
| 118 |
image_format,
|
| 119 |
1,
|
| 120 |
"DESKTOP_IMAGE"
|
| 121 |
+
)
|
|
|
|
| 122 |
logger.info("Desktop banner uploaded successfully.")
|
| 123 |
+
return {"img_url": result.get("url")}
|
| 124 |
|
| 125 |
except Exception as error:
|
| 126 |
logger.error(f"Error processing desktop banner: {str(error)}")
|
app/services/custom_banner_ipad_service.py
CHANGED
|
@@ -8,13 +8,22 @@ from PIL import Image, ImageEnhance, ImageOps
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
|
|
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
-
def get_ipad_prompt(
|
|
|
|
|
|
|
| 15 |
return f'''
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def process_image(image_data: bytes, target_width: int, target_height: int) -> bytes:
|
| 19 |
"""
|
| 20 |
Resize, sharpen, enhance, and compress image for upload.
|
|
@@ -62,18 +71,21 @@ def process_image(image_data: bytes, target_width: int, target_height: int) -> b
|
|
| 62 |
|
| 63 |
return buffer.getvalue()
|
| 64 |
|
| 65 |
-
def generate_ipad_banner(
|
|
|
|
|
|
|
| 66 |
"""
|
| 67 |
Generate iPad banner using Gemini and upload to Reach platform.
|
| 68 |
Returns a dictionary with the image URL.
|
| 69 |
"""
|
|
|
|
| 70 |
api_key = settings.GEMINI_API_KEY
|
| 71 |
client = genai.Client(api_key=api_key)
|
| 72 |
|
| 73 |
-
logger.info(f"Starting iPad banner generation
|
| 74 |
|
| 75 |
try:
|
| 76 |
-
prompt = get_ipad_prompt(
|
| 77 |
response = client.models.generate_content(
|
| 78 |
model="gemini-2.0-flash-exp-image-generation",
|
| 79 |
contents=prompt,
|
|
@@ -98,19 +110,16 @@ def generate_ipad_banner(brand_name: str, domain: str, primary_color: str, descr
|
|
| 98 |
logger.info(f"Processing iPad banner image (format: {image_format})")
|
| 99 |
|
| 100 |
# Process image
|
| 101 |
-
processed_image = process_image(image_data, 768, 500)
|
| 102 |
-
|
| 103 |
-
# Upload to Reach platform
|
| 104 |
result = upload_to_reach(
|
| 105 |
processed_image,
|
| 106 |
f"custom_ipad_banner_{brand_name}",
|
| 107 |
image_format,
|
| 108 |
1,
|
| 109 |
"IPAD_IMAGE"
|
| 110 |
-
)
|
| 111 |
-
|
| 112 |
logger.info("iPad banner uploaded successfully.")
|
| 113 |
-
return {"img_url": result
|
| 114 |
|
| 115 |
except Exception as error:
|
| 116 |
logger.error(f"Error processing iPad banner: {str(error)}")
|
|
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
| 11 |
+
from app.utils.name_generator import generate_brand_name
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
+
def get_ipad_prompt(
|
| 16 |
+
prompt: str, brand_details: str
|
| 17 |
+
) -> str:
|
| 18 |
return f'''
|
| 19 |
+
{prompt}
|
| 20 |
+
|
| 21 |
+
Create an realistic image that reflects this brand:
|
| 22 |
+
{brand_details}
|
| 23 |
+
|
| 24 |
+
The image must be professional and realistic, and must not contain any text, typographic or alphanumeric elements.
|
| 25 |
+
'''
|
| 26 |
+
|
| 27 |
def process_image(image_data: bytes, target_width: int, target_height: int) -> bytes:
|
| 28 |
"""
|
| 29 |
Resize, sharpen, enhance, and compress image for upload.
|
|
|
|
| 71 |
|
| 72 |
return buffer.getvalue()
|
| 73 |
|
| 74 |
+
def generate_ipad_banner(
|
| 75 |
+
prompt: str, brand_details: str
|
| 76 |
+
) -> Dict[str, str]:
|
| 77 |
"""
|
| 78 |
Generate iPad banner using Gemini and upload to Reach platform.
|
| 79 |
Returns a dictionary with the image URL.
|
| 80 |
"""
|
| 81 |
+
brand_name = generate_brand_name()
|
| 82 |
api_key = settings.GEMINI_API_KEY
|
| 83 |
client = genai.Client(api_key=api_key)
|
| 84 |
|
| 85 |
+
logger.info(f"Starting iPad banner generation with ID: {brand_name}")
|
| 86 |
|
| 87 |
try:
|
| 88 |
+
prompt = get_ipad_prompt(prompt, brand_details)
|
| 89 |
response = client.models.generate_content(
|
| 90 |
model="gemini-2.0-flash-exp-image-generation",
|
| 91 |
contents=prompt,
|
|
|
|
| 110 |
logger.info(f"Processing iPad banner image (format: {image_format})")
|
| 111 |
|
| 112 |
# Process image
|
| 113 |
+
processed_image = process_image(image_data, 768, 500) # Upload to Reach platform
|
|
|
|
|
|
|
| 114 |
result = upload_to_reach(
|
| 115 |
processed_image,
|
| 116 |
f"custom_ipad_banner_{brand_name}",
|
| 117 |
image_format,
|
| 118 |
1,
|
| 119 |
"IPAD_IMAGE"
|
| 120 |
+
)
|
|
|
|
| 121 |
logger.info("iPad banner uploaded successfully.")
|
| 122 |
+
return {"img_url": result.get("url")}
|
| 123 |
|
| 124 |
except Exception as error:
|
| 125 |
logger.error(f"Error processing iPad banner: {str(error)}")
|
app/services/custom_banner_mobile_service.py
CHANGED
|
@@ -8,13 +8,21 @@ from PIL import Image, ImageEnhance, ImageOps
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
|
|
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
-
def get_mobile_prompt(
|
|
|
|
|
|
|
| 15 |
return f'''
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def process_image(image_data: bytes, target_width: int, target_height: int) -> bytes:
|
| 20 |
"""
|
|
@@ -63,18 +71,21 @@ def process_image(image_data: bytes, target_width: int, target_height: int) -> b
|
|
| 63 |
|
| 64 |
return buffer.getvalue()
|
| 65 |
|
| 66 |
-
def generate_mobile_banner(
|
|
|
|
|
|
|
| 67 |
"""
|
| 68 |
Generate mobile banner using Gemini and upload to Reach platform.
|
| 69 |
Returns a dictionary with the image URL.
|
| 70 |
"""
|
|
|
|
| 71 |
api_key = settings.GEMINI_API_KEY
|
| 72 |
client = genai.Client(api_key=api_key)
|
| 73 |
|
| 74 |
-
logger.info(f"Starting mobile banner generation
|
| 75 |
|
| 76 |
try:
|
| 77 |
-
prompt = get_mobile_prompt(
|
| 78 |
response = client.models.generate_content(
|
| 79 |
model="gemini-2.0-flash-exp-image-generation",
|
| 80 |
contents=prompt,
|
|
@@ -99,19 +110,16 @@ def generate_mobile_banner(brand_name: str, domain: str, primary_color: str, des
|
|
| 99 |
logger.info(f"Processing mobile banner image (format: {image_format})")
|
| 100 |
|
| 101 |
# Process image
|
| 102 |
-
processed_image = process_image(image_data, 375, 500)
|
| 103 |
-
|
| 104 |
-
# Upload to Reach platform
|
| 105 |
result = upload_to_reach(
|
| 106 |
processed_image,
|
| 107 |
f"custom_mobile_banner_{brand_name}",
|
| 108 |
image_format,
|
| 109 |
1,
|
| 110 |
"WEB_IMAGE"
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
logger.info("Mobile banner uploaded successfully.")
|
| 114 |
-
return {"img_url": result
|
| 115 |
|
| 116 |
except Exception as error:
|
| 117 |
logger.error(f"Error processing mobile banner: {str(error)}")
|
|
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
| 11 |
+
from app.utils.name_generator import generate_brand_name
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
+
def get_mobile_prompt(
|
| 16 |
+
prompt: str, brand_details: str
|
| 17 |
+
) -> str:
|
| 18 |
return f'''
|
| 19 |
+
{prompt}
|
| 20 |
+
|
| 21 |
+
Create an realistic image that reflects this brand:
|
| 22 |
+
{brand_details}
|
| 23 |
+
|
| 24 |
+
The image must be professional and realistic, and must not contain any text, typographic or alphanumeric elements.
|
| 25 |
+
'''
|
| 26 |
|
| 27 |
def process_image(image_data: bytes, target_width: int, target_height: int) -> bytes:
|
| 28 |
"""
|
|
|
|
| 71 |
|
| 72 |
return buffer.getvalue()
|
| 73 |
|
| 74 |
+
def generate_mobile_banner(
|
| 75 |
+
prompt: str, brand_details: str
|
| 76 |
+
) -> Dict[str, str]:
|
| 77 |
"""
|
| 78 |
Generate mobile banner using Gemini and upload to Reach platform.
|
| 79 |
Returns a dictionary with the image URL.
|
| 80 |
"""
|
| 81 |
+
brand_name = generate_brand_name()
|
| 82 |
api_key = settings.GEMINI_API_KEY
|
| 83 |
client = genai.Client(api_key=api_key)
|
| 84 |
|
| 85 |
+
logger.info(f"Starting mobile banner generation with ID: {brand_name}")
|
| 86 |
|
| 87 |
try:
|
| 88 |
+
prompt = get_mobile_prompt(prompt, brand_details)
|
| 89 |
response = client.models.generate_content(
|
| 90 |
model="gemini-2.0-flash-exp-image-generation",
|
| 91 |
contents=prompt,
|
|
|
|
| 110 |
logger.info(f"Processing mobile banner image (format: {image_format})")
|
| 111 |
|
| 112 |
# Process image
|
| 113 |
+
processed_image = process_image(image_data, 375, 500) # Upload to Reach platform
|
|
|
|
|
|
|
| 114 |
result = upload_to_reach(
|
| 115 |
processed_image,
|
| 116 |
f"custom_mobile_banner_{brand_name}",
|
| 117 |
image_format,
|
| 118 |
1,
|
| 119 |
"WEB_IMAGE"
|
| 120 |
+
)
|
|
|
|
| 121 |
logger.info("Mobile banner uploaded successfully.")
|
| 122 |
+
return {"img_url": result.get("url")}
|
| 123 |
|
| 124 |
except Exception as error:
|
| 125 |
logger.error(f"Error processing mobile banner: {str(error)}")
|
app/services/custom_byop_service.py
CHANGED
|
@@ -7,12 +7,16 @@ from google.genai import types
|
|
| 7 |
from PIL import Image, ImageEnhance, ImageOps
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
|
|
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
| 11 |
|
| 12 |
# Initialize logger for this module
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
-
def get_custom_byop_prompts(
|
|
|
|
|
|
|
|
|
|
| 16 |
"""
|
| 17 |
Generate a prompt for BYOP (Bring Your Own Product) banner image generation.
|
| 18 |
|
|
@@ -23,8 +27,14 @@ def get_custom_byop_prompts(brand_name: str, domain: str, description: str) -> s
|
|
| 23 |
Returns:
|
| 24 |
str: Prompt to send to the image generation API.
|
| 25 |
"""
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
|
@@ -112,24 +122,20 @@ def process_image(image_data: bytes, width: int = 530, height: int = 352) -> byt
|
|
| 112 |
return buffer.getvalue()
|
| 113 |
|
| 114 |
|
| 115 |
-
def generate_custom_byop_banner(
|
|
|
|
|
|
|
|
|
|
| 116 |
"""
|
| 117 |
Generate custom BYOP banner image using Gemini API and upload processed image to Reach platform.
|
| 118 |
-
|
| 119 |
-
Args:
|
| 120 |
-
brand_name (str): Brand name to include in the prompt.
|
| 121 |
-
domain (str): Industry domain.
|
| 122 |
-
description (str): Description for banner design.
|
| 123 |
-
|
| 124 |
-
Returns:
|
| 125 |
-
Dict: Dictionary containing banner image URL.
|
| 126 |
"""
|
|
|
|
| 127 |
api_key = settings.GEMINI_API_KEY
|
| 128 |
client = genai.Client(api_key=api_key)
|
| 129 |
-
prompt = get_custom_byop_prompts(
|
| 130 |
all_banner_results = []
|
| 131 |
|
| 132 |
-
logger.info(f"Generating BYOP banner
|
| 133 |
banner_result = None
|
| 134 |
try:
|
| 135 |
# Request image generation from Gemini API
|
|
|
|
| 7 |
from PIL import Image, ImageEnhance, ImageOps
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
+
from app.utils.name_generator import generate_brand_name
|
| 11 |
from app.utils.reach_upload import upload_to_reach
|
| 12 |
|
| 13 |
# Initialize logger for this module
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
+
def get_custom_byop_prompts(
|
| 17 |
+
prompt: str,
|
| 18 |
+
brand_details: str
|
| 19 |
+
) -> str:
|
| 20 |
"""
|
| 21 |
Generate a prompt for BYOP (Bring Your Own Product) banner image generation.
|
| 22 |
|
|
|
|
| 27 |
Returns:
|
| 28 |
str: Prompt to send to the image generation API.
|
| 29 |
"""
|
| 30 |
+
return f'''
|
| 31 |
+
{prompt}
|
| 32 |
+
|
| 33 |
+
Create an realistic image that reflects this brand:
|
| 34 |
+
{brand_details}
|
| 35 |
+
|
| 36 |
+
The image must be professional and realistic, and must not contain any text, typographic or alphanumeric elements.
|
| 37 |
+
'''
|
| 38 |
|
| 39 |
|
| 40 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
|
|
|
| 122 |
return buffer.getvalue()
|
| 123 |
|
| 124 |
|
| 125 |
+
def generate_custom_byop_banner(
|
| 126 |
+
prompt: str,
|
| 127 |
+
brand_details: str
|
| 128 |
+
) -> Dict:
|
| 129 |
"""
|
| 130 |
Generate custom BYOP banner image using Gemini API and upload processed image to Reach platform.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
"""
|
| 132 |
+
brand_name = generate_brand_name()
|
| 133 |
api_key = settings.GEMINI_API_KEY
|
| 134 |
client = genai.Client(api_key=api_key)
|
| 135 |
+
prompt = get_custom_byop_prompts(prompt, brand_details)
|
| 136 |
all_banner_results = []
|
| 137 |
|
| 138 |
+
logger.info(f"Generating BYOP banner with ID: {brand_name}")
|
| 139 |
banner_result = None
|
| 140 |
try:
|
| 141 |
# Request image generation from Gemini API
|
app/services/custom_network_service.py
CHANGED
|
@@ -8,13 +8,22 @@ from PIL import Image, ImageEnhance, ImageOps
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
|
|
|
| 11 |
|
| 12 |
# Initialize logger for this module
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
-
def get_custom_network_prompts(
|
| 16 |
-
prompt
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
| 20 |
"""
|
|
@@ -100,16 +109,19 @@ def process_image(image_data: bytes, width: int = 530, height: int = 352) -> byt
|
|
| 100 |
return buffer.getvalue()
|
| 101 |
|
| 102 |
|
| 103 |
-
def generate_custom_network_banner(
|
|
|
|
|
|
|
| 104 |
"""
|
| 105 |
Generate custom network banner image using Gemini API and upload processed image to Reach platform.
|
| 106 |
"""
|
|
|
|
| 107 |
api_key = settings.GEMINI_API_KEY
|
| 108 |
client = genai.Client(api_key=api_key)
|
| 109 |
-
prompt = get_custom_network_prompts(
|
| 110 |
all_banner_results = []
|
| 111 |
|
| 112 |
-
logger.info(f"Generating network banner
|
| 113 |
banner_result = None
|
| 114 |
try:
|
| 115 |
response = client.models.generate_content(
|
|
|
|
| 8 |
|
| 9 |
from app.config.settings import settings
|
| 10 |
from app.utils.reach_upload import upload_to_reach
|
| 11 |
+
from app.utils.name_generator import generate_brand_name
|
| 12 |
|
| 13 |
# Initialize logger for this module
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
+
def get_custom_network_prompts(
|
| 17 |
+
prompt: str, brand_details: str
|
| 18 |
+
) -> str:
|
| 19 |
+
return f'''
|
| 20 |
+
{prompt}
|
| 21 |
+
|
| 22 |
+
Create an realistic image that reflects this brand:
|
| 23 |
+
{brand_details}
|
| 24 |
+
|
| 25 |
+
The image must be professional and realistic, and must not contain any text, typographic or alphanumeric elements.
|
| 26 |
+
'''
|
| 27 |
|
| 28 |
def process_image(image_data: bytes, width: int = 530, height: int = 352) -> bytes:
|
| 29 |
"""
|
|
|
|
| 109 |
return buffer.getvalue()
|
| 110 |
|
| 111 |
|
| 112 |
+
def generate_custom_network_banner(
|
| 113 |
+
prompt: str, brand_details: str
|
| 114 |
+
) -> Dict:
|
| 115 |
"""
|
| 116 |
Generate custom network banner image using Gemini API and upload processed image to Reach platform.
|
| 117 |
"""
|
| 118 |
+
brand_name = generate_brand_name()
|
| 119 |
api_key = settings.GEMINI_API_KEY
|
| 120 |
client = genai.Client(api_key=api_key)
|
| 121 |
+
prompt = get_custom_network_prompts(prompt, brand_details)
|
| 122 |
all_banner_results = []
|
| 123 |
|
| 124 |
+
logger.info(f"Generating network banner with ID: {brand_name}")
|
| 125 |
banner_result = None
|
| 126 |
try:
|
| 127 |
response = client.models.generate_content(
|
app/services/logo_service.py
CHANGED
|
@@ -34,6 +34,7 @@ def get_logo_prompts(
|
|
| 34 |
return [
|
| 35 |
f'''Create a graphic, abstract icon that visually conveys the essence and feel of the brand '{brand_name}', while also clearly suggesting involvement in the {domain} field. {color_scheme}
|
| 36 |
Strict requirements:
|
|
|
|
| 37 |
- The icon must be entirely visual and abstract.
|
| 38 |
- Absolutely no text, letters, numbers, symbols, or any written elements of any kind should appear in the image.
|
| 39 |
- The image should not contain any watermark, signature, or typographic marks.
|
|
|
|
| 34 |
return [
|
| 35 |
f'''Create a graphic, abstract icon that visually conveys the essence and feel of the brand '{brand_name}', while also clearly suggesting involvement in the {domain} field. {color_scheme}
|
| 36 |
Strict requirements:
|
| 37 |
+
- The ratio must be 1024:384
|
| 38 |
- The icon must be entirely visual and abstract.
|
| 39 |
- Absolutely no text, letters, numbers, symbols, or any written elements of any kind should appear in the image.
|
| 40 |
- The image should not contain any watermark, signature, or typographic marks.
|
app/services/single_text_logo_service.py
CHANGED
|
@@ -27,8 +27,13 @@ def get_single_text_logo_prompt(
|
|
| 27 |
if tertiary_color:
|
| 28 |
background = f"{tertiary_color} background"
|
| 29 |
return (
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
def optimize_logo_image(image: Image.Image) -> Image.Image:
|
|
|
|
| 27 |
if tertiary_color:
|
| 28 |
background = f"{tertiary_color} background"
|
| 29 |
return (
|
| 30 |
+
f'''Design a sophisticated, text-only logo for {brand_name}.
|
| 31 |
+
Use only the brand name as the sole visual element—do not include any icons, symbols, images, shapes, or graphic embellishments of any kind.
|
| 32 |
+
The logo must feature {text_color} text on a {background}.
|
| 33 |
+
Employ elegant, modern typography and refined font styling to convey the brand's personality.
|
| 34 |
+
Focus on creative use of font, spacing, capitalization, and layout to achieve a distinctive and memorable wordmark.
|
| 35 |
+
No decorative graphics, pictorial elements, or non-text visuals should appear in the design—only stylized text is allowed.
|
| 36 |
+
The result should be a clean, timeless, and visually striking text logo.'''
|
| 37 |
)
|
| 38 |
|
| 39 |
def optimize_logo_image(image: Image.Image) -> Image.Image:
|
app/utils/name_generator.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import uuid
|
| 3 |
+
|
| 4 |
+
def generate_brand_name() -> str:
|
| 5 |
+
"""
|
| 6 |
+
Generate a unique brand name for image naming purposes.
|
| 7 |
+
Returns a string combining a UUID to ensure uniqueness.
|
| 8 |
+
"""
|
| 9 |
+
return f"brand_{uuid.uuid4().hex[:8]}"
|