Gemma3 簡單製作長輩圖/Meme Generator part 1
The Meme Generator supports Traditional Chinese using Gemma3 - part 1
剛好接下來幾個公開行程會玩/介紹一下 Imagen and Gemini/Gemma,就先拿這個當簡單的示範囉。
請直接參考這個 repo https://github.com/jimmyliao/genai-gdg (幫忙點個 ⭐️ 吧 )底下的 Notebook: https://github.com/jimmyliao/genai-gdg/blob/main/gemma/%5BGemma_3%5DMeme_Generator.ipynb
使用 Gemma3: gemma3-4b-it
中文字型: NotoSans_TC_Regular
流程大約是這樣:
從 HuggingFace 下載 Gemma3
自訂 generate_meme ,並透過 gemma3-4b-it 的 tool declaration 載入
chatbot = gm.text.ChatSampler(
model=model,
params=params,
multi_turn=False,
tokenizer=tokenizer,
)
prompt = f"""<start_of_image>
If you decide to invoke any of the function(s), it should be wrapped with ```tool_code```.
You have access to the following tools.
* `generate_meme(image, top_text, middle_text, bottom_text)`: Generate a meme with the given parameters
Based on the background, "{prompt_background}", make a funny meme with this. "{imagefile}. The top_text should be traditional chinese language instead."
"""
result = chatbot.chat(prompt=prompt, images=image)
function response 結果透過 textwrap 在圖片上面加上文字
Credit by: Juyeong Ji (GitHub: @bebechien), original ipynb: https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/%5BGemma_3%5DMeme_Generator.ipynb
請幫忙在 repo 點個 ⭐️ 吧 https://github.com/jimmyliao/genai-gdg 🙇♂️