優化早安圖生成 Prompt

#1
Files changed (1) hide show
  1. image_generator.py +50 -22
image_generator.py CHANGED
@@ -22,13 +22,16 @@ DEFAULT_HEIGHT = 1024
22
 
23
  # 預設的俗俗早安圖問候語,當 Gemini API 金鑰未提供時作為 Fallback 備用
24
  PRESET_GREETINGS = [
25
- "早安!祝您平安喜樂,順心如意,認同請分享!",
26
- "早安!日出東方蓮花朵朵,健康長壽是最大的福氣!",
27
- "早安!世界最美的是人情最珍貴的是健康,祝天天開心!",
28
- "早安!笑口常開,福氣自來,祝您福慧雙修,福滿乾坤!",
29
- "早安!每一都是新起點,祝天天開心福氣滿滿!",
30
- "早安!知足常樂天天開心,願幸福常伴您左右!",
31
- "早安!健康是無價之寶平安是最大的福氣,認同請分享!"
 
 
 
32
  ]
33
 
34
  # 頂部大字 Banner 的預設選用標題
@@ -129,11 +132,21 @@ def generate_text_with_gemini(api_key, query):
129
  model = genai.GenerativeModel('gemini-2.5-flash')
130
 
131
  prompt = (
132
- f"請針對「{query}」寫一句非常俗氣、好笑、帶有強烈台灣「長輩圖」荒謬感的中文早安問候語。數在20字以內。\n"
133
- f"範例:\n"
134
- f"- 「早安!吸貓一口,福氣雙倍!認同請分享」\n"
135
- f"- 「早安!日出東方,蓮花盛開,祝您天天平安喜樂,認同請分享」\n"
136
- f"請直接回傳這句中文問候語本身,不要有任何多餘的解釋標點符號或引號。"
 
 
 
 
 
 
 
 
 
 
137
  )
138
  response = model.generate_content(prompt)
139
  text = response.text.strip().replace('"', '').replace('「', '').replace('」', '')
@@ -147,10 +160,14 @@ def expand_prompt_with_gemini(api_key, query):
147
  query_en = translate_to_english(query)
148
 
149
  default_expanded = (
150
- f"A detailed colorful digital illustration of {query_en} placed in the center, "
151
- f"set against a kitsch traditional Chinese 'Good Morning' greeting card background with a large blooming pink lotus flower on a pond, "
152
- f"a bright golden sunrise with radiant sun rays in a clear blue sky, extremely vibrant and oversaturated neon colors, "
153
- f"retro 1990s clip art and digital painting style, high resolution."
 
 
 
 
154
  )
155
 
156
  if not api_key:
@@ -163,12 +180,23 @@ def expand_prompt_with_gemini(api_key, query):
163
  model = genai.GenerativeModel('gemini-2.5-flash')
164
 
165
  prompt = (
166
- f"Please translate the Chinese phrase '{query}' into English, and expand it into a detailed image generation prompt. "
167
- f"The prompt MUST put a beautiful detailed '{query_en}' in the center of the image as the main subject. "
168
- f"The background of the image MUST be a classic kitsch 'Good Morning Card' style (Taiwanese traditional elder style) "
169
- f"featuring: a large blooming pink lotus flower on a pond, glowing sunrise background with bright rays of light, "
170
- f"extremely vibrant and oversaturated neon colors, and retro 90s digital clip-art aesthetic. "
171
- f"Only return the final English prompt, without any explanations or quotes."
 
 
 
 
 
 
 
 
 
 
 
172
  )
173
  response = model.generate_content(prompt)
174
  expanded = response.text.strip().replace('"', '').replace('「', '').replace('」', '')
 
22
 
23
  # 預設的俗俗早安圖問候語,當 Gemini API 金鑰未提供時作為 Fallback 備用
24
  PRESET_GREETINGS = [
25
+ "早安!今天也要假裝系統正常!",
26
+ "早安!人生卡住時請先重!",
27
+ "早安!努力不一定成功但會很累!",
28
+ "早安!腦袋尚未請多包涵!",
29
+ "早安!天的你,比昨天更像待機中!",
30
+ "早安!不要放棄反正也沒人接住你!",
31
+ "早安!上課像登入失敗但人要有光!",
32
+ "早安!作業不會寫,太陽還是會升起!",
33
+ "早安!群組安靜不是冷漠,是大家都沒電!",
34
+ "早安!願你今天的 Wi-Fi 比人生穩定!"
35
  ]
36
 
37
  # 頂部大字 Banner 的預設選用標題
 
132
  model = genai.GenerativeModel('gemini-2.5-flash')
133
 
134
  prompt = (
135
+ f"請針對「{query}」寫一句繁體中文早安圖文字。\n"
136
+ f"風格要求台灣長輩圖、荒謬、38、假勵志、欠吐槽、適合群組聊天。\n"
137
+ f"語氣要像一個很有自信但其實很荒謬的早安機器人。\n"
138
+ f"字數限制:12 到 22 字。\n"
139
+ f"內容方向:可以嘲諷抽象人生早八、上班、作業、拖延、群組沉默、機器人自己\n"
140
+ f"安全限制:不可攻擊特定真人、族群、性別、外貌、疾病、政治立場或宗教。\n"
141
+ f"不要髒話,不要人身攻擊,不要太黑暗。\n"
142
+ f"要讓群組成員看了想回:『這什麼鬼啦』。\n"
143
+ f"範例:\n"
144
+ f"- 早安,今天也要假裝系統正常\n"
145
+ f"- 早安,努力不一定成功但很耗電\n"
146
+ f"- 早安,人生卡住請重新整理\n"
147
+ f"- 早安,腦袋離線也是一種生活\n"
148
+ f"- 早安,群組沒人講話我先亂講\n"
149
+ f"請只回傳一句中文早安文字,不要解釋,不要加引號。"
150
  )
151
  response = model.generate_content(prompt)
152
  text = response.text.strip().replace('"', '').replace('「', '').replace('」', '')
 
160
  query_en = translate_to_english(query)
161
 
162
  default_expanded = (
163
+ f"A funny, absurd, and slightly stupid Taiwanese good morning meme image featuring {query_en} as the main subject, "
164
+ f"placed clearly in the center of the image. "
165
+ f"The image should look like an over-the-top Taiwanese elder-style morning greeting card mixed with chaotic internet meme humor. "
166
+ f"Use extremely colorful flowers, dramatic golden sunrise, sparkles, glowing clouds, rainbow decorations, fake inspirational poster energy, "
167
+ f"retro 1990s digital clip-art aesthetics, and an exaggerated ridiculous composition. "
168
+ f"The mood should be harmless, silly, flamboyant, awkwardly cheerful, and easy for group chat members to roast. "
169
+ f"No readable text inside the image, because Traditional Chinese text will be added later by the program. "
170
+ f"High resolution, colorful, detailed, humorous, meme-like, absurd, ridiculous."
171
  )
172
 
173
  if not api_key:
 
180
  model = genai.GenerativeModel('gemini-2.5-flash')
181
 
182
  prompt = (
183
+ f"Please translate the Chinese phrase '{query}' into English, "
184
+ f"then expand it into a detailed image generation prompt for a funny, absurd Taiwanese good morning meme image.\n\n"
185
+ f"Creative direction:\n"
186
+ f"The image should feel like a chaotic Taiwanese elder-style good morning card, "
187
+ f"but upgraded into a ridiculous internet meme that group chat members would want to roast.\n\n"
188
+ f"Requirements:\n"
189
+ f"1. The main subject must clearly be related to: '{query_en}'.\n"
190
+ f"2. Make the scene visually absurd, silly, flamboyant, and overly confident in a stupid way.\n"
191
+ f"3. Combine Taiwanese elder-style good morning card aesthetics with meme humor: "
192
+ f"dramatic sunrise, glowing clouds, lotus flowers, sparkles, rainbow decorations, "
193
+ f"oversaturated colors, retro 1990s clip-art, fake inspirational poster style, and chaotic composition.\n"
194
+ f"4. The image should look harmless, funny, awkwardly cheerful, and easy to roast in a group chat.\n"
195
+ f"5. Add one ridiculous visual gag related to the subject, such as the subject acting too serious, "
196
+ f"posing heroically, failing confidently, or doing something meaningless with great determination.\n"
197
+ f"6. Do not include real public figures, political symbols, hate symbols, violence, sexual content, horror, or offensive stereotypes.\n"
198
+ f"7. Do not generate readable text inside the image, because Traditional Chinese text will be added later by the program.\n\n"
199
+ f"Only return the final English image prompt. Do not include explanations, labels, or quotation marks."
200
  )
201
  response = model.generate_content(prompt)
202
  expanded = response.text.strip().replace('"', '').replace('「', '').replace('」', '')