You will build a bot that generates social media posts end-to-end: an LLM writes the caption and hashtags, Stable Diffusion creates a matching image, and a scheduler publishes to your platforms via API. A boutique marketing agency running this for 12 client accounts produces 360 posts per month (one per client per day) with zero manual image sourcing. The entire pipeline runs on a single dedicated GPU server.
Pipeline Architecture
| Stage | Tool | Output |
|---|---|---|
| 1. Content planning | LLaMA 3.1 8B | Topic + angle + tone |
| 2. Copy generation | LLaMA 3.1 8B | Caption + hashtags |
| 3. Image generation | SDXL / Flux | 1024×1024 post image |
| 4. Scheduling | APScheduler + API | Queued posts |
Generating Post Copy
from openai import OpenAI
import json
client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")
def generate_post(brand: dict, topic: str, platform: str) -> dict:
response = client.chat.completions.create(
model="meta-llama/Llama-3.1-8B-Instruct",
messages=[{
"role": "system",
"content": f"""You write social media posts for {brand['name']}.
Brand voice: {brand['voice']}. Industry: {brand['industry']}.
Platform: {platform}. Character limit: {brand.get('char_limit', 280)}.
Return JSON: {{"caption": "", "hashtags": [], "image_prompt": ""}}
The image_prompt should describe a photograph or illustration matching the post."""
}, {"role": "user", "content": f"Write a post about: {topic}"}],
max_tokens=500, temperature=0.8
)
return json.loads(response.choices[0].message.content)
The vLLM server returns structured JSON including an image prompt derived from the post content. Temperature at 0.8 keeps output varied across daily posts.
Generating Post Images
import torch
from diffusers import StableDiffusionXLPipeline
pipe = StableDiffusionXLPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16
).to("cuda")
def generate_image(prompt: str, brand: dict, size=(1024, 1024)):
styled_prompt = f"{prompt}, {brand.get('style', 'modern professional photography')}"
negative = "text, watermark, logo, blurry, low quality, distorted"
image = pipe(styled_prompt, negative_prompt=negative,
width=size[0], height=size[1],
num_inference_steps=30, guidance_scale=7.5).images[0]
return image
Stable Diffusion XL generates images matching each brand’s visual style. Load LoRA weights per client for consistent brand aesthetics across posts.
Scheduling and Posting
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta
import requests
scheduler = BackgroundScheduler()
def queue_posts(brands: list, days_ahead: int = 7):
for brand in brands:
topics = generate_weekly_topics(brand)
for day_offset, topic in enumerate(topics):
post = generate_post(brand, topic, brand["platform"])
image = generate_image(post["image_prompt"], brand)
image_path = save_image(image, brand["name"], day_offset)
post_time = datetime.now() + timedelta(days=day_offset,
hours=brand.get("post_hour", 10))
scheduler.add_job(publish_post, trigger="date",
run_date=post_time,
args=[brand, post, image_path])
def publish_post(brand, post, image_path):
# Platform-specific API calls
if brand["platform"] == "instagram":
upload_to_instagram(brand["token"], post["caption"], image_path)
elif brand["platform"] == "twitter":
upload_to_twitter(brand["token"], post["caption"], image_path)
Brand Voice Configuration
brands = [
{"name": "TechStartup", "voice": "witty, informal, emoji-friendly",
"industry": "SaaS", "platform": "twitter", "char_limit": 280,
"style": "flat illustration, tech aesthetic, blue tones",
"post_hour": 9, "token": "..."},
{"name": "LuxuryTravel", "voice": "elegant, aspirational, descriptive",
"industry": "travel", "platform": "instagram", "char_limit": 2200,
"style": "cinematic photography, golden hour, wide angle",
"post_hour": 11, "token": "..."}
]
Each brand definition controls both text tone and image style. The LLM adapts its writing to match the voice description, while Stable Diffusion applies the visual style. For advanced brand voice tuning, see chatbot hosting for fine-tuning approaches.
Production Deployment
Run content generation in weekly batches: generate all posts on Sunday, review the queue on Monday, and let the scheduler handle daily publishing. Store generated content in a database for audit trails and A/B testing. An RTX 5090 (24 GB) generates a full week of content for 12 brands (84 posts with images) in under two hours. Deploy on private infrastructure to keep client brand assets and API tokens secure. See image generation hosting for GPU benchmarks, GDPR compliance for handling client data, more tutorials, and use cases.
Social Media AI GPU Servers
Generate branded social content at scale with LLM and image generation on dedicated UK GPU infrastructure.
Browse GPU Servers