深夜提醒

现在是深夜,建议您注意休息,不要熬夜哦~

🏮 🏮 🏮

新年快乐

祝君万事如意心想事成!

share-image
中
ESC

Building an AI-Powered Automated Article Cover System: A Complete Walkthrough from DeepSeek to OSS

English 阅读中文版

As a tech blogger, every time I finish an article I fret over finding an illustration. Either I spend time hunting for a suitable image, or I just skip it — but the latter makes the article look monotonous. Recently I built an AI-powered automated article cover-image system that, after I finish writing, generates a cover image matching the content with one click. This article shares the complete technical implementation.

Building an AI-powered automated article cover system

Requirements Analysis

Core Demands

  1. Automation: input an article, automatically output an illustration
  2. Content-relevant: the image should reflect the article’s theme, not be a random picture
  3. Batch processing: support batch generation for historical articles
  4. Auto insertion: after generation, automatically insert it into a suitable position in the article

Technology Selection Considerations

Approach Pros Cons
Search the web for images Free, fast Copyright issues, not necessarily a match
AI generation (Midjourney) High quality Requires Discord, API is inconvenient
DeepSeek + Tongyi Wanxiang Usable in China, low cost Requires combining two services
DALL-E 3 Good results Requires an overseas credit card

I ultimately chose the DeepSeek + Tongyi Wanxiang combination: DeepSeek handles understanding the article and generating the prompt, and Tongyi Wanxiang handles generating the image.

System Architecture

┌─────────────────┐     ┌──────────────┐     ┌─────────────┐
│ Markdown article│────▶│ DeepSeek │────▶│ English prompt │
│ (title + body) │ │ (text understanding)│ │ │
└─────────────────┘ └──────────────┘ └──────┬──────┘
│
┌──────────────────────┘
▼
┌─────────────────┐ ┌──────────────┐ ┌─────────────┐
│ Markdown + image│◀────│ Auto insertion │◀────│ Alibaba Cloud OSS │
│ (updated article)│ │ (specified position)│ │ (CDN acceleration)│
└─────────────────┘ └──────────────┘ └─────────────┘
▲
│
┌──────┴──────┐
│ Tongyi Wanxiang │
│ (image generation)│
└─────────────┘

Workflow:

  1. Parse the article to extract the title and summary
  2. DeepSeek generates a professional English prompt
  3. Tongyi Wanxiang generates the image from the prompt
  4. Upload to Alibaba Cloud OSS
  5. Insert it into the specified position in the article according to the strategy

Core Implementation

1. Article Parsing Module

We need to extract useful information from the Markdown:

def extract_article_content(file_path):
"""Extract the article title and summary"""
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()

# Extract the front matter
front_matter_match = re.match(r'^---\s*\n(.*?)\n---\s*\n', content, re.DOTALL)
front_matter = front_matter_match.group(1)

# Extract the title
title_match = re.search(r'^title:\s*(.+)$', front_matter, re.MULTILINE)
title = title_match.group(1).strip() if title_match else ""

# Extract the body and clean it up
body_content = content[front_matter_match.end():]
# Remove code blocks, image markers, etc.
body_content = re.sub(r'```[\s\S]*?```', '', body_content)
body_content = re.sub(r'!\[([^\]]*)\]\([^\)]+\)', '', body_content)

# Extract the first 500 characters as the summary
summary = body_content.strip()[:500]

return {'title': title, 'summary': summary}

2. DeepSeek Prompt Generation

The key trick: make DeepSeek act as an “AI art prompt engineer”:

system_prompt = """You are a professional AI art prompt engineer. Based on the article content, generate a high-quality English AI art prompt.

Requirements:
1. The prompt must be in English, suitable for Stable Diffusion, Midjourney, DALL-E, etc.
2. The style should be modern, professional, and visually striking
3. Include elements such as scene description, color, lighting, and composition
4. Keep the length to 80-150 words
5. Do not include text, logos, or watermarks"""

user_prompt = f"""Generate a prompt based on the following article:

Title: {title}
Summary: {summary}

Return the English prompt directly, no explanation needed."""

Call example:

def call_deepseek_api(system_prompt, user_prompt):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}

data = {
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
],
"temperature": 0.7,
"max_tokens": 2000
}

response = requests.post(
'https://api.deepseek.com/v1/chat/completions',
json=data, headers=headers
)

return response.json()['choices'][0]['message']['content']

Sample generated prompt:

A dynamic digital illustration of two glowing chat windows floating in a dark cyberspace, one a small widget in the corner and one a large fullscreen interface, connected by a fragile, broken data stream of light particles and binary code…

3. Tongyi Wanxiang Image Generation

Using the synchronous API of the Alibaba Cloud Bailian platform:

def generate_image_with_tongyi(prompt):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {dashscope_key}'
}

data = {
"model": "qwen-image-max", # latest model
"input": {
"messages": [
{"role": "user", "content": [{"text": prompt}]}
]
},
"parameters": {
"size": "1328*1328", # 1:1 square
"prompt_extend": True, # smart rewriting
"watermark": False, # no watermark
"negative_prompt": "low resolution, deformed limbs, oversaturated image..."
}
}

response = requests.post(
'https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation',
json=data, headers=headers
)

# Synchronous return, no polling needed
image_url = response.json()['output']['choices'][0]['message']['content'][0]['image']
return download_image(image_url)

4. Smart Insertion Strategy

Instead of simply putting the image at the top, it’s inserted intelligently based on the article structure:

def find_insert_position(content, strategy="after_second_paragraph"):
"""Find the image insertion position"""

if strategy == "after_second_paragraph":
# Skip the front matter
if content.startswith('---'):
fm_end = content.find('---', 3)
content_after_fm = content[fm_end + 3:]

# Extract the paragraphs
paragraphs = []
for line in content_after_fm.split('\n'):
if line.strip() and not line.startswith('#'):
paragraphs.append(line)
elif paragraphs:
break

# Insert after the second paragraph
if len(paragraphs) >= 2:
second_para = paragraphs[1]
pos = content.find(second_para)
return pos + len(second_para)

elif strategy == "after_first_h2":
# Insert after the first ## heading
match = re.search(r'\n##\s+.+\n', content)
if match:
return match.end()

Sample insertion result:

---
title: My Article
---

This is the first paragraph, usually the introduction.

This is the second paragraph, explaining the content in more detail.

![My Article](https://file.awen.me/xxx.png?e=2106345600&st=p_kUObTCP4ddMgIkhFcWzg) <-- inserted here

## Problem Analysis

Here is the body content...

Pitfall Log

Pitfall 1: Kimi API 401 Error

I first wanted to use Kimi to generate the prompt, but got a 401 after configuring the Key. Investigation revealed:

# Test on the server
curl https://api.moonshot.cn/v1/models \
-H "Authorization: Bearer sk-kimi-xxx"
# returns {"error":{"message":"Invalid Authentication"}}

Cause: The Kimi Key configured in OpenClaw may have an IP whitelist restriction, so it only works on his machine.

Solution: Switch to DeepSeek — also domestic, also easy to use.

Pitfall 2: OSS Upload Timeout

# The ossutil command timed out after 120 seconds
subprocess.run(cmd, timeout=120) # timeout!

Solution: Switch to the Python SDK (oss2), which supports streaming uploads:

import oss2
auth = oss2.Auth(access_key_id, access_key_secret)
bucket = oss2.Bucket(auth, endpoint, bucket_name)
bucket.put_object_from_file(oss_key, local_file)

Pitfall 3: Image 404

After generation, the image URL returned 404. Checking revealed:

# Wrong: the file wasn't effective immediately after being uploaded to OSS
# Right: wait for the upload to finish before verifying
bucket.put_object_from_file(oss_key, local_file)
assert bucket.object_exists(oss_key) # verify existence

How to Use

Command-line Usage

# Generate a cover image for the latest article
npm run gen-cover:latest

# Specify an article
python3 tools/auto_insert_cover.py source/_posts/2026/03/article.md --model deepseek

# Specify the insertion position
python3 tools/auto_insert_cover.py source/_posts/2026/03/article.md \
--strategy after_first_h2

Git Automatic Integration

I configured a Git pre-commit hook, so it automatically checks when you commit an article:

git add source/_posts/2026/03/my-article.md
git commit -m "post: add new article"
# Automatically triggers: check cover image → generate → insert → add to the commit

Cost Analysis

Service Cost Description
DeepSeek ¥0.001/1k tokens about ¥0.01 per article
Tongyi Wanxiang ¥0.12/image per generated image
OSS storage ¥0.12/GB/month negligible
Total about ¥0.13/article much cheaper than a cup of milk tea

Final Result

The workflow for writing an article now:

  1. hexo new "Article Title" to create the article
  2. Write the content
  3. npm run gen-cover:latest to generate the illustration with one click
  4. git commit && git push to deploy automatically

The illustration is strongly related to the article content. For example, this article’s illustration:

AI-generated cover image

Perfectly captures the theme of “chat windows in sync.”

Code Repository

The complete code is open-sourced:

  • tools/auto_insert_cover.py - main script
  • tools/generate_image_prompt.py - prompt generation
  • tools/generate_article_image.py - image generation and upload

Just configure your own DeepSeek and Alibaba Cloud keys and you can use it.


Summary: Through the DeepSeek + Tongyi Wanxiang combination, I achieved low-cost, high-quality AI-automated illustrations. The whole process, from article parsing to image insertion, is fully automatic, greatly improving writing efficiency. If you’re a Hexo user too, you can use this solution directly.

文章作者:阿文
文章链接: https://www.awen.me/post/75b892ec.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿文的博客!
本文于 2026-03-04 08:00 发布,已超过半年(227天),请注意甄别内容是否已过期。

评论

0 条评论
😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️✋ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐⛎ ♈♉♊ ♋♌♍ ♎♏♐ ♑♒♓ 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘❌⭕ 🛑⛔📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭❗ ❕❓❔ ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️✅ 🈯💹❇️ ✳️❎🌐 💠Ⓜ️🌀 💤🏧🚾 ♿🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️
加载中...

留言反馈

😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️✋ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐⛎ ♈♉♊ ♋♌♍ ♎♏♐ ♑♒♓ 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘❌⭕ 🛑⛔📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭❗ ❕❓❔ ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️✅ 🈯💹❇️ ✳️❎🌐 💠Ⓜ️🌀 💤🏧🚾 ♿🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️