Spaces:
Sleeping
Sleeping
Commit ·
c0743bf
1
Parent(s): 302778b
deleted files not in use fo hf
Browse files- config/__init__.py +0 -0
- config/settings.py +0 -21
- services/logo_service.py +0 -118
- services/text_logo_service.py +0 -115
- utils/__init__.py +0 -0
- utils/reach_upload.py +0 -110
- utils/s3_utils.py +0 -89
config/__init__.py
DELETED
|
File without changes
|
config/settings.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
|
| 5 |
-
load_dotenv()
|
| 6 |
-
|
| 7 |
-
class Settings:
|
| 8 |
-
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 9 |
-
if not GEMINI_API_KEY:
|
| 10 |
-
raise ValueError("GEMINI_API_KEY not found in environment variables")
|
| 11 |
-
# AWS credentials not needed as Reach Endpoint being used for storage
|
| 12 |
-
|
| 13 |
-
# AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
|
| 14 |
-
# AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
|
| 15 |
-
# AWS_REGION = os.getenv("AWS_REGION")
|
| 16 |
-
# S3_BUCKET_NAME = os.getenv("S3_BUCKET_NAME")
|
| 17 |
-
UNSPLASH_API_KEY = os.getenv("UNSPLASH_API_KEY")
|
| 18 |
-
# if not all([AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, S3_BUCKET_NAME]):
|
| 19 |
-
# raise ValueError("AWS credentials or S3 bucket name not found in environment variables")
|
| 20 |
-
|
| 21 |
-
settings = Settings()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services/logo_service.py
DELETED
|
@@ -1,118 +0,0 @@
|
|
| 1 |
-
import io
|
| 2 |
-
import time
|
| 3 |
-
import logging
|
| 4 |
-
from typing import Dict, List
|
| 5 |
-
|
| 6 |
-
from google import genai
|
| 7 |
-
from google.genai import types
|
| 8 |
-
from PIL import Image
|
| 9 |
-
|
| 10 |
-
from app.config.settings import settings
|
| 11 |
-
from app.utils.reach_upload import upload_to_reach
|
| 12 |
-
|
| 13 |
-
# Configure the logging module
|
| 14 |
-
logging.basicConfig(level=logging.INFO)
|
| 15 |
-
logger = logging.getLogger(__name__)
|
| 16 |
-
|
| 17 |
-
def get_logo_prompts(
|
| 18 |
-
brand_name: str,
|
| 19 |
-
domain: str,
|
| 20 |
-
primary_color: str,
|
| 21 |
-
secondary_color: str | None = None,
|
| 22 |
-
tertiary_color: str | None = None
|
| 23 |
-
) -> List[str]:
|
| 24 |
-
"""
|
| 25 |
-
Generate a list of prompt strings to feed into the image generation model,
|
| 26 |
-
based on brand name, domain, and color scheme.
|
| 27 |
-
"""
|
| 28 |
-
color_scheme = f"using {primary_color} as the primary color"
|
| 29 |
-
if secondary_color:
|
| 30 |
-
color_scheme += f", {secondary_color} as the secondary color"
|
| 31 |
-
if tertiary_color:
|
| 32 |
-
color_scheme += f", and {tertiary_color} as an accent color"
|
| 33 |
-
|
| 34 |
-
return [
|
| 35 |
-
f"Design a professional and elegant logo for {brand_name}, specializing in {domain}. {color_scheme}. Incorporate a subtle icon or abstract mark with this sophisticated color palette.",
|
| 36 |
-
f"Create a creative and unique logo for {brand_name}, focusing on {domain} solutions. {color_scheme}. Think outside the box with an unexpected symbol or a clever visual metaphor.",
|
| 37 |
-
f"Generate a modern logo for {brand_name}, within the {domain} sector. {color_scheme}. Consider using geometric shapes and clean lines.",
|
| 38 |
-
f"Create a minimal logo for {brand_name}, operating in the {domain} space. {color_scheme}. Focus on simple, memorable design elements."
|
| 39 |
-
]
|
| 40 |
-
|
| 41 |
-
def generate_logos(
|
| 42 |
-
brand_name: str,
|
| 43 |
-
domain: str,
|
| 44 |
-
primary_color: str,
|
| 45 |
-
secondary_color: str | None = None,
|
| 46 |
-
tertiary_color: str | None = None,
|
| 47 |
-
variation_count: int = 4
|
| 48 |
-
) -> Dict[str, List[Dict]]:
|
| 49 |
-
"""
|
| 50 |
-
Generate multiple logo variations using the Google Gemini image generation API,
|
| 51 |
-
save as PNG and ICO formats, and upload to respective endpoints.
|
| 52 |
-
"""
|
| 53 |
-
api_key = settings.GEMINI_API_KEY
|
| 54 |
-
client = genai.Client(api_key=api_key)
|
| 55 |
-
|
| 56 |
-
# Prepare prompts
|
| 57 |
-
prompts = get_logo_prompts(brand_name, domain, primary_color, secondary_color, tertiary_color)[:variation_count]
|
| 58 |
-
logo_results = []
|
| 59 |
-
|
| 60 |
-
logger.info(f"Generating {len(prompts)} logo variations for brand: {brand_name}")
|
| 61 |
-
|
| 62 |
-
for idx, prompt in enumerate(prompts, 1):
|
| 63 |
-
try:
|
| 64 |
-
# Generate content using Gemini image generation model
|
| 65 |
-
logger.info(f"Generating logo {idx} with prompt: {prompt}")
|
| 66 |
-
response = client.models.generate_content(
|
| 67 |
-
model="gemini-2.0-flash-exp-image-generation",
|
| 68 |
-
contents=prompt,
|
| 69 |
-
config=types.GenerateContentConfig(response_modalities=['TEXT', 'IMAGE'])
|
| 70 |
-
)
|
| 71 |
-
|
| 72 |
-
# Iterate through returned content parts to find the image
|
| 73 |
-
for part in response.candidates[0].content.parts:
|
| 74 |
-
if part.inline_data is not None:
|
| 75 |
-
try:
|
| 76 |
-
# Convert image byte data to a PIL Image object
|
| 77 |
-
image_bytes = io.BytesIO(part.inline_data.data)
|
| 78 |
-
image = Image.open(image_bytes)
|
| 79 |
-
|
| 80 |
-
# Save image as PNG
|
| 81 |
-
png_buffer = io.BytesIO()
|
| 82 |
-
image.save(png_buffer, format='PNG')
|
| 83 |
-
png_buffer.seek(0)
|
| 84 |
-
|
| 85 |
-
# Create a 32x32 ICO version of the logo
|
| 86 |
-
ico_buffer = io.BytesIO()
|
| 87 |
-
ico_image = image.resize((32, 32), Image.Resampling.LANCZOS)
|
| 88 |
-
ico_image.save(ico_buffer, format='ICO', sizes=[(32, 32)])
|
| 89 |
-
ico_buffer.seek(0)
|
| 90 |
-
|
| 91 |
-
# Upload PNG to Reach platform
|
| 92 |
-
png_result = upload_to_reach(png_buffer.getvalue(), brand_name, 'png', idx)
|
| 93 |
-
|
| 94 |
-
# Upload ICO to S3
|
| 95 |
-
ico_result = upload_to_reach(ico_buffer.getvalue(), brand_name, 'ico', idx)
|
| 96 |
-
|
| 97 |
-
# Append metadata to the results
|
| 98 |
-
logo_results.append({
|
| 99 |
-
'id': f'logo_{idx}',
|
| 100 |
-
'png_url': png_result['url'],
|
| 101 |
-
'ico_url': ico_result['url'],
|
| 102 |
-
'formats': ['png', 'ico'],
|
| 103 |
-
'name': f'{brand_name}_{idx}'
|
| 104 |
-
})
|
| 105 |
-
|
| 106 |
-
logger.info(f"Logo {idx} processed and uploaded successfully.")
|
| 107 |
-
|
| 108 |
-
except Exception as e:
|
| 109 |
-
logger.error(f"Error processing image {idx}: {str(e)}", exc_info=True)
|
| 110 |
-
|
| 111 |
-
# Sleep to avoid rate limits or overloading API
|
| 112 |
-
time.sleep(1)
|
| 113 |
-
|
| 114 |
-
except Exception as e:
|
| 115 |
-
logger.error(f"Error generating logo {idx}: {str(e)}", exc_info=True)
|
| 116 |
-
|
| 117 |
-
logger.info(f"Finished generating logos. Total successful: {len(logo_results)}")
|
| 118 |
-
return {'logos': logo_results}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services/text_logo_service.py
DELETED
|
@@ -1,115 +0,0 @@
|
|
| 1 |
-
import io
|
| 2 |
-
import time
|
| 3 |
-
from typing import Dict, List
|
| 4 |
-
import logging
|
| 5 |
-
from google import genai
|
| 6 |
-
from google.genai import types
|
| 7 |
-
from PIL import Image
|
| 8 |
-
|
| 9 |
-
from app.config.settings import settings
|
| 10 |
-
from app.utils.reach_upload import upload_to_reach
|
| 11 |
-
|
| 12 |
-
# Set up logger
|
| 13 |
-
logger = logging.getLogger(__name__)
|
| 14 |
-
logging.basicConfig(level=logging.INFO)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def get_text_logo_prompts(brand_name: str, domain: str, primary_color: str, secondary_color: str | None = None, tertiary_color: str | None = None) -> List[str]:
|
| 19 |
-
"""
|
| 20 |
-
Generate multiple text-based logo prompts based on brand and color information.
|
| 21 |
-
"""
|
| 22 |
-
text_color = f"with text in {primary_color}"
|
| 23 |
-
if secondary_color:
|
| 24 |
-
text_color += f" and {secondary_color} accents"
|
| 25 |
-
|
| 26 |
-
background = "white background"
|
| 27 |
-
if tertiary_color:
|
| 28 |
-
background = f"{tertiary_color} background"
|
| 29 |
-
|
| 30 |
-
return [
|
| 31 |
-
f"Create a sophisticated text-only logo for {brand_name}, {text_color} on a {background}. Use elegant typography and modern font styling, without any icons or symbols.",
|
| 32 |
-
f"Design a minimalist text-based logo for {brand_name}, {text_color} on a {background}. Focus on creative letter spacing and font weight variations, avoiding any graphical elements.",
|
| 33 |
-
f"Generate a bold typographic logo for {brand_name}, {text_color} on a {background}. Experiment with unique letter arrangements and text layouts, keeping it icon-free.",
|
| 34 |
-
f"Create a clean text-centric logo for {brand_name}, {text_color} on a {background}. Use professional typography with careful attention to kerning and spacing."
|
| 35 |
-
]
|
| 36 |
-
|
| 37 |
-
def generate_text_logos(
|
| 38 |
-
brand_name: str,
|
| 39 |
-
domain: str,
|
| 40 |
-
primary_color: str,
|
| 41 |
-
secondary_color: str | None = None,
|
| 42 |
-
tertiary_color: str | None = None,
|
| 43 |
-
variation_count: int = 4
|
| 44 |
-
) -> Dict[str, List[Dict]]:
|
| 45 |
-
"""
|
| 46 |
-
Generates text-only logos using Gemini image generation and saves as PNG + ICO formats.
|
| 47 |
-
Uploads PNG to Reach platform and ICO to S3.
|
| 48 |
-
"""
|
| 49 |
-
api_key = settings.GEMINI_API_KEY
|
| 50 |
-
client = genai.Client(api_key=api_key)
|
| 51 |
-
|
| 52 |
-
logger.info(f"Generating text-only logo prompts for brand: {brand_name}")
|
| 53 |
-
prompts = get_text_logo_prompts(brand_name, domain, primary_color, secondary_color, tertiary_color)[:variation_count]
|
| 54 |
-
|
| 55 |
-
logo_results = []
|
| 56 |
-
|
| 57 |
-
for idx, prompt in enumerate(prompts, 1):
|
| 58 |
-
logger.info(f"Generating logo variation {idx} using Gemini model.")
|
| 59 |
-
try:
|
| 60 |
-
response = client.models.generate_content(
|
| 61 |
-
model="gemini-2.0-flash-exp-image-generation",
|
| 62 |
-
contents=prompt,
|
| 63 |
-
config=types.GenerateContentConfig(
|
| 64 |
-
response_modalities=['TEXT', 'IMAGE']
|
| 65 |
-
)
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
# Extract image content from Gemini response
|
| 69 |
-
for part in response.candidates[0].content.parts:
|
| 70 |
-
if part.inline_data is not None:
|
| 71 |
-
try:
|
| 72 |
-
logger.info(f"Processing image data for logo {idx}")
|
| 73 |
-
|
| 74 |
-
# Convert byte data to PIL image
|
| 75 |
-
image_bytes = io.BytesIO(part.inline_data.data)
|
| 76 |
-
image = Image.open(image_bytes)
|
| 77 |
-
|
| 78 |
-
# Save image as PNG
|
| 79 |
-
png_buffer = io.BytesIO()
|
| 80 |
-
image.save(png_buffer, format='PNG')
|
| 81 |
-
png_buffer.seek(0)
|
| 82 |
-
|
| 83 |
-
# Create ICO format for favicon use
|
| 84 |
-
ico_buffer = io.BytesIO()
|
| 85 |
-
ico_image = image.resize((32, 32), Image.Resampling.LANCZOS)
|
| 86 |
-
ico_image.save(ico_buffer, format='ICO', sizes=[(32, 32)])
|
| 87 |
-
ico_buffer.seek(0)
|
| 88 |
-
|
| 89 |
-
# Upload PNG to Reach platform
|
| 90 |
-
png_result = upload_to_reach(png_buffer.getvalue(), brand_name, 'png', idx)
|
| 91 |
-
|
| 92 |
-
# Upload ICO to S3
|
| 93 |
-
ico_result = upload_to_reach(ico_buffer.getvalue(), brand_name, 'ico', idx)
|
| 94 |
-
|
| 95 |
-
# Append result
|
| 96 |
-
logo_results.append({
|
| 97 |
-
'id': f'logo_{idx}',
|
| 98 |
-
'png_url': png_result['url'],
|
| 99 |
-
'ico_url': ico_result['url'],
|
| 100 |
-
'formats': ['png', 'ico'],
|
| 101 |
-
'name': f'{brand_name}_{idx}'
|
| 102 |
-
})
|
| 103 |
-
|
| 104 |
-
logger.info(f"Logo {idx} uploaded successfully.")
|
| 105 |
-
|
| 106 |
-
except Exception as e:
|
| 107 |
-
logger.error(f"Error processing image {idx}: {str(e)}")
|
| 108 |
-
|
| 109 |
-
# Wait 1 second between each variation to avoid rate-limiting
|
| 110 |
-
time.sleep(1)
|
| 111 |
-
|
| 112 |
-
except Exception as e:
|
| 113 |
-
logger.error(f"Error generating logo {idx}: {str(e)}")
|
| 114 |
-
|
| 115 |
-
return {'logos': logo_results}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/__init__.py
DELETED
|
File without changes
|
utils/reach_upload.py
DELETED
|
@@ -1,110 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import time
|
| 3 |
-
from typing import Dict
|
| 4 |
-
import requests
|
| 5 |
-
from io import BytesIO
|
| 6 |
-
import logging
|
| 7 |
-
|
| 8 |
-
logger = logging.getLogger(__name__)
|
| 9 |
-
logger.setLevel(logging.DEBUG)
|
| 10 |
-
|
| 11 |
-
# Add a stream handler if not already added
|
| 12 |
-
if not logger.handlers:
|
| 13 |
-
handler = logging.StreamHandler()
|
| 14 |
-
handler.setLevel(logging.DEBUG)
|
| 15 |
-
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 16 |
-
handler.setFormatter(formatter)
|
| 17 |
-
logger.addHandler(handler)
|
| 18 |
-
|
| 19 |
-
def upload_to_reach(
|
| 20 |
-
image_data: bytes,
|
| 21 |
-
brand_name: str,
|
| 22 |
-
image_format: str,
|
| 23 |
-
index: int,
|
| 24 |
-
file_type: str, # Required parameter
|
| 25 |
-
max_retries: int = 3,
|
| 26 |
-
retry_delay: float = 2.0
|
| 27 |
-
) -> Dict[str, str]:
|
| 28 |
-
"""
|
| 29 |
-
Upload image to Reach Mobile Platform storage with retry logic.
|
| 30 |
-
|
| 31 |
-
Args:
|
| 32 |
-
image_data (bytes): Raw image bytes
|
| 33 |
-
brand_name (str): Brand name for reference
|
| 34 |
-
image_format (str): Image format/extension
|
| 35 |
-
index (int): Index to differentiate multiple uploads
|
| 36 |
-
file_type (str): Type of file to upload (e.g., LOGO, FAV_ICON, etc.)
|
| 37 |
-
max_retries (int): Maximum number of retry attempts
|
| 38 |
-
retry_delay (float): Delay between retries in seconds
|
| 39 |
-
|
| 40 |
-
Returns:
|
| 41 |
-
Dict[str, str]: Metadata dictionary containing URL from Reach API
|
| 42 |
-
|
| 43 |
-
Raises:
|
| 44 |
-
requests.RequestException: If upload fails after all retries
|
| 45 |
-
EnvironmentError: If required environment variables are missing
|
| 46 |
-
"""
|
| 47 |
-
url = os.getenv('REACH_UPLOAD_ENDPOINT')
|
| 48 |
-
auth_key = os.getenv('REACH_AUTH_KEY')
|
| 49 |
-
|
| 50 |
-
if not url:
|
| 51 |
-
raise EnvironmentError("REACH_UPLOAD_ENDPOINT is not defined in environment variables.")
|
| 52 |
-
if not auth_key:
|
| 53 |
-
raise EnvironmentError("REACH_AUTH_KEY is not defined in environment variables.")
|
| 54 |
-
|
| 55 |
-
last_exception = None
|
| 56 |
-
|
| 57 |
-
for attempt in range(max_retries):
|
| 58 |
-
try:
|
| 59 |
-
file_obj = BytesIO(image_data)
|
| 60 |
-
filename = f"{brand_name.replace(' ', '')}_{index}.{image_format.lower()}"
|
| 61 |
-
|
| 62 |
-
files = {
|
| 63 |
-
'file': (filename, file_obj, f'image/{image_format.lower()}')
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
headers = {
|
| 67 |
-
'accept': 'application/json',
|
| 68 |
-
'accept-language': 'en-US,en;q=0.9',
|
| 69 |
-
'authorization': auth_key,
|
| 70 |
-
'sec-ch-ua-platform': 'Windows',
|
| 71 |
-
'x-partner-tenant-id': 'REACH@skyhawk'
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
logger.info(f"Attempting upload of {filename} as {file_type} (attempt {attempt + 1}/{max_retries})")
|
| 75 |
-
|
| 76 |
-
# Ensure file_type is present in the URL
|
| 77 |
-
upload_url = f"{url}?fileType={file_type}"
|
| 78 |
-
|
| 79 |
-
logger.debug(f"Uploading to endpoint: {upload_url}")
|
| 80 |
-
|
| 81 |
-
response = requests.post(
|
| 82 |
-
upload_url,
|
| 83 |
-
files=files,
|
| 84 |
-
headers=headers,
|
| 85 |
-
timeout=30
|
| 86 |
-
)
|
| 87 |
-
|
| 88 |
-
if response.status_code != 200:
|
| 89 |
-
raise requests.HTTPError(f"Upload failed: {response.status_code} {response.text}")
|
| 90 |
-
|
| 91 |
-
response_data = response.json()
|
| 92 |
-
if response_data.get('status') != 'SUCCESS':
|
| 93 |
-
raise requests.HTTPError(f"Upload failed: {response_data}")
|
| 94 |
-
|
| 95 |
-
logger.info(f"Successfully uploaded {filename}")
|
| 96 |
-
return {
|
| 97 |
-
"url": response_data.get('data')
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
except (requests.RequestException, requests.Timeout) as e:
|
| 101 |
-
last_exception = e
|
| 102 |
-
logger.warning(f"Upload attempt {attempt + 1} failed: {str(e)}")
|
| 103 |
-
if attempt < max_retries - 1:
|
| 104 |
-
time.sleep(retry_delay * (attempt + 1)) # Exponential backoff
|
| 105 |
-
continue
|
| 106 |
-
break
|
| 107 |
-
|
| 108 |
-
error_msg = f"❌ Error uploading to Reach platform after {max_retries} attempts: {str(last_exception)}"
|
| 109 |
-
logger.error(error_msg)
|
| 110 |
-
raise requests.RequestException(error_msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/s3_utils.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
# made for adding s3 storage, no longer in need due to reach storage
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
# import uuid
|
| 5 |
-
# from io import BytesIO
|
| 6 |
-
|
| 7 |
-
# import boto3
|
| 8 |
-
# from botocore.exceptions import ClientError
|
| 9 |
-
|
| 10 |
-
# from app.config.settings import settings
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# def get_s3_client():
|
| 14 |
-
|
| 15 |
-
# return boto3.client(
|
| 16 |
-
# "s3",
|
| 17 |
-
# aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
|
| 18 |
-
# aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
|
| 19 |
-
# region_name=settings.AWS_REGION,
|
| 20 |
-
# )
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# def upload_image_to_s3(image_data, brand_name, image_format, index):
|
| 24 |
-
|
| 25 |
-
# try:
|
| 26 |
-
# s3_client = get_s3_client()
|
| 27 |
-
|
| 28 |
-
# unique_id = str(uuid.uuid4())[:8]
|
| 29 |
-
# filename = f"{brand_name.replace(' ', '_')}_{index}_{unique_id}.{image_format}"
|
| 30 |
-
|
| 31 |
-
# s3_client.upload_fileobj(
|
| 32 |
-
# BytesIO(image_data),
|
| 33 |
-
# settings.S3_BUCKET_NAME,
|
| 34 |
-
# filename,
|
| 35 |
-
# ExtraArgs={"ContentType": f"image/{image_format}"},
|
| 36 |
-
# )
|
| 37 |
-
|
| 38 |
-
# url = f"https://{settings.S3_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/{filename}"
|
| 39 |
-
|
| 40 |
-
# return {
|
| 41 |
-
# "id": f"logo_{index}",
|
| 42 |
-
# "url": url,
|
| 43 |
-
# "format": image_format,
|
| 44 |
-
# "name": filename,
|
| 45 |
-
# }
|
| 46 |
-
# except ClientError as e:
|
| 47 |
-
# raise Exception(f"S3 upload error: {str(e)}")
|
| 48 |
-
|
| 49 |
-
# def upload_logo_to_s3(image_data: bytes, brand_name: str, image_format: str, index: int):
|
| 50 |
-
|
| 51 |
-
# try:
|
| 52 |
-
# s3_client = get_s3_client()
|
| 53 |
-
|
| 54 |
-
# unique_id = str(uuid.uuid4())[:8]
|
| 55 |
-
# filename = f"{brand_name.replace(' ', '')}{index}_{unique_id}.{image_format.lower()}"
|
| 56 |
-
|
| 57 |
-
# if image_format.lower() == "svg":
|
| 58 |
-
# extra_args = {
|
| 59 |
-
# "ContentType": "image/svg+xml",
|
| 60 |
-
# "ContentDisposition": "inline",
|
| 61 |
-
# }
|
| 62 |
-
# elif image_format.lower() == "ico":
|
| 63 |
-
# extra_args = {
|
| 64 |
-
# "ContentType": "image/x-icon",
|
| 65 |
-
# "ContentDisposition": "inline",
|
| 66 |
-
# }
|
| 67 |
-
# else:
|
| 68 |
-
# extra_args = {
|
| 69 |
-
# "ContentType": f"image/{image_format.lower()}",
|
| 70 |
-
# }
|
| 71 |
-
|
| 72 |
-
# s3_client.upload_fileobj(
|
| 73 |
-
# BytesIO(image_data),
|
| 74 |
-
# settings.S3_BUCKET_NAME,
|
| 75 |
-
# filename,
|
| 76 |
-
# ExtraArgs=extra_args,
|
| 77 |
-
# )
|
| 78 |
-
|
| 79 |
-
# url = f"https://{settings.S3_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/{filename}"
|
| 80 |
-
|
| 81 |
-
# return {
|
| 82 |
-
# "id": f"logo_{index}",
|
| 83 |
-
# "url": url,
|
| 84 |
-
# "format": image_format,
|
| 85 |
-
# "name": filename,
|
| 86 |
-
# }
|
| 87 |
-
|
| 88 |
-
# except ClientError as e:
|
| 89 |
-
# raise Exception(f"S3 upload error: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|