utkarsh134 commited on
Commit
2ab05b5
·
verified ·
1 Parent(s): cf9d16f

Update app/services/text_logo_service.py

Browse files
Files changed (1) hide show
  1. app/services/text_logo_service.py +64 -65
app/services/text_logo_service.py CHANGED
@@ -1,65 +1,64 @@
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
 
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
+ ]
21
+
22
+ 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 = 4) -> List[Dict]:
23
+ api_key = settings.GEMINI_API_KEY
24
+ client = genai.Client(api_key=api_key)
25
+ prompts = get_text_logo_prompts(brand_name, domain, primary_color, secondary_color, tertiary_color)[:variation_count]
26
+
27
+ logo_results = []
28
+
29
+ for idx, prompt in enumerate(prompts, 1):
30
+ try:
31
+ response = client.models.generate_content(
32
+ model="gemini-2.0-flash-exp-image-generation",
33
+ contents=prompt,
34
+ config=types.GenerateContentConfig(
35
+ response_modalities=['TEXT', 'IMAGE']
36
+ )
37
+ )
38
+
39
+ for part in response.candidates[0].content.parts:
40
+ if part.inline_data is not None:
41
+ try:
42
+ mime_type = part.inline_data.mime_type
43
+ image_data = part.inline_data.data
44
+
45
+ image_format = "png"
46
+ if "jpeg" in mime_type or "jpg" in mime_type:
47
+ image_format = "jpeg"
48
+ elif "png" in mime_type:
49
+ image_format = "png"
50
+ elif "webp" in mime_type:
51
+ image_format = "webp"
52
+
53
+ logo_result = upload_image_to_s3(image_data, brand_name, image_format, f"text_{idx}")
54
+ logo_results.append(logo_result)
55
+
56
+ except Exception as e:
57
+ print(f"Error processing image {idx}: {str(e)}")
58
+
59
+ time.sleep(1)
60
+
61
+ except Exception as e:
62
+ print(f"Error generating logo {idx}: {str(e)}")
63
+
64
+ return logo_results