Spaces:
Sleeping
Sleeping
Upload text_logo_service.py
Browse files
app/services/text_logo_service.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from google import genai
|
| 2 |
+
from google.genai import types
|
| 3 |
+
import time
|
| 4 |
+
from typing import List, Dict
|
| 5 |
+
from app.config.settings import settings
|
| 6 |
+
from app.utils.s3_utils import upload_image_to_s3
|
| 7 |
+
|
| 8 |
+
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]:
|
| 9 |
+
color_scheme = f"using {primary_color} as the primary color"
|
| 10 |
+
if secondary_color:
|
| 11 |
+
color_scheme += f", {secondary_color} as the secondary color"
|
| 12 |
+
if tertiary_color:
|
| 13 |
+
color_scheme += f", and {tertiary_color} as an accent color"
|
| 14 |
+
|
| 15 |
+
return [
|
| 16 |
+
f"Create a sophisticated text-only vector logo in SVG format for {brand_name}. {color_scheme}. Use elegant typography and modern font styling, without any icons or symbols.",
|
| 17 |
+
f"Design a minimalist text-based vector logo in SVG format for {brand_name}. {color_scheme}. Focus on creative letter spacing and font weight variations, avoiding any graphical elements.",
|
| 18 |
+
f"Generate a bold typographic vector logo in SVG format for {brand_name}. {color_scheme}. Experiment with unique letter arrangements and text layouts, keeping it icon-free.",
|
| 19 |
+
f"Create a clean text-centric vector logo in SVG format for {brand_name}. {color_scheme}. Use professional typography with careful attention to kerning and spacing.",
|
| 20 |
+
f"Design a contemporary text-only vector logo in SVG format for {brand_name}. {color_scheme}. Focus on sleek letterforms and modern font styling without additional graphics."
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
def generate_text_logos(brand_name: str, domain: str, primary_color: str, secondary_color: str | None = None, tertiary_color: str | None = None, variation_count: int = 5) -> List[Dict]:
|
| 24 |
+
api_key = settings.GEMINI_API_KEY
|
| 25 |
+
client = genai.Client(api_key=api_key)
|
| 26 |
+
prompts = get_text_logo_prompts(brand_name, domain, primary_color, secondary_color, tertiary_color)[:variation_count]
|
| 27 |
+
|
| 28 |
+
logo_results = []
|
| 29 |
+
|
| 30 |
+
for idx, prompt in enumerate(prompts, 1):
|
| 31 |
+
try:
|
| 32 |
+
response = client.models.generate_content(
|
| 33 |
+
model="gemini-2.0-flash-exp-image-generation",
|
| 34 |
+
contents=prompt,
|
| 35 |
+
config=types.GenerateContentConfig(
|
| 36 |
+
response_modalities=['TEXT', 'IMAGE']
|
| 37 |
+
)
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
for part in response.candidates[0].content.parts:
|
| 41 |
+
if part.inline_data is not None:
|
| 42 |
+
try:
|
| 43 |
+
mime_type = part.inline_data.mime_type
|
| 44 |
+
image_data = part.inline_data.data
|
| 45 |
+
|
| 46 |
+
image_format = "png"
|
| 47 |
+
if "jpeg" in mime_type or "jpg" in mime_type:
|
| 48 |
+
image_format = "jpeg"
|
| 49 |
+
elif "png" in mime_type:
|
| 50 |
+
image_format = "png"
|
| 51 |
+
elif "webp" in mime_type:
|
| 52 |
+
image_format = "webp"
|
| 53 |
+
|
| 54 |
+
logo_result = upload_image_to_s3(image_data, brand_name, image_format, f"text_{idx}")
|
| 55 |
+
logo_results.append(logo_result)
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"Error processing image {idx}: {str(e)}")
|
| 59 |
+
|
| 60 |
+
time.sleep(1)
|
| 61 |
+
|
| 62 |
+
except Exception as e:
|
| 63 |
+
print(f"Error generating logo {idx}: {str(e)}")
|
| 64 |
+
|
| 65 |
+
return logo_results
|