Spaces:
Runtime error
Runtime error
優化早安圖生成 Prompt
#1
by anna666anna - opened
- 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 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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('」', '')
|