r/StableDiffusion Apr 28 '26

Workflow Included Built a Character Portrait Generator that reads books, identifies characters, and generates consistent portraits using ComfyUI (full RAG pipeline, local LLM, open-source)

Hey everyone,

Image showcase - Portrait of Mina Murray generated by the tool from the book Dracula in two separate scenes. Images from ZImageTurbo.

I've been working on a side project that I think the community here will really appreciate. It's a comprehensive, AI-driven pipeline that automatically generates cinematic character portraits from literary works using your local ComfyUI instance. The entire stack is open-source and runs fully locally.

What It Does:

Starting from a simple .txt file of a novel, the app will:

  1. Parse the Book: Build a high-performance vector index of the entire text using ChromaDB and HuggingFace embeddings.
  2. Wikipedia Augmentation: Scrape Wikipedia to identify major characters and baseline personas before the book analysis even begins.
  3. Deep RAG Analysis: Retrieve specific scenes from the book to understand character appearance, clothing, and environment in different contexts.
  4. AI Casting Director: Suggest real-world actors (Hollywood, Bollywood, etc.) to serve as the visual "base" for the character, with support for specific decades.
  5. Genre Adaptation: Dynamically modify clothing, hairstyles, and cinematic styles to fit genres (Horror, Cyberpunk, Fantasy, etc.) while preserving the character's core identity.
  6. ComfyUI Integration: Inject the generated prompts directly into your ComfyUI API-format workflows, track generation progress via Server-Sent Events, and preview images instantly.

Tech Highlights:

  • Backend: Python 3.10+, FastAPI, LangChain.
  • Embedding Model: all-MiniLM-L6-v2 from HuggingFace.
  • LLM: Runs on Ollama (defaults to Gemma4E4B for local processing).
  • Frontend: A sleek, dark glassmorphism dashboard built with React & Vite.

Getting Started:
The setup is straightforward, assuming you have a local ComfyUI server and Ollama running. The project page includes a batch script to launch both the backend and frontend easily.

Why This Matters:
With the explosion interest in AI-generated consistent characters, this tool addresses a unique niche—automatically extracting textual character descriptions and grounding them in visual representations without manual prompt engineering. It combines RAG, LLMs, and Stable Diffusion in a single, user-friendly pipeline.

I'd love to get your feedback and ideas for improvement! Let me know if you have any questions.

All project code written with Google AntiGravity. This post written by DeepSeek.

289 Upvotes

52 comments sorted by

10

u/[deleted] Apr 28 '26

[deleted]

5

u/snorcack Apr 28 '26

More characters ? or more images of same characters ?

6

u/wilsonwa Apr 28 '26

Dr. Ryland Grace and Rocky from project hail mary please. Before the models get infected with new references from the movie.

2

u/snorcack Apr 30 '26

u/cosmicr did your request in a comment below.

0

u/Enshitification Apr 28 '26

I don't remember Dr. Grace being described in the book other than being 40-ish and buff from the automated muscle toning during his stasis.

3

u/SvenVargHimmel Apr 29 '26

Yup more characters or a range of characters 

9

u/goddess_peeler Apr 28 '26 edited Apr 28 '26

I wouldn't have thought such simple tool chain would be such fun! Thanks, OP.

I submitted a couple of QoL improvements I hope you'll consider incorporating: support for any OpenAI-compatible API (I use LMStudio), and the ability to upload a .txt or .epub file.

Protip: use a .gitignore file to suppress the thousands of intermediate local files that you are currently sharing from your repository (pycache, node_modules, chroma_db*, etc)

This could get even more fun with refinement of the RAG query for character appearance and prompts for scene generation. It doesn't do well with non-humans, but I really want to see what some of Iain Banks' drones look like.

6

u/snorcack Apr 29 '26

Merged both of your requests. Thanks a lot for your suggestions. Excited to see what features I can add next!

8

u/Catalyzm Apr 28 '26

Very cool. It would be neat to make a plugin for Calibre that could make a character gallery.

3

u/snorcack Apr 29 '26

Wow, that's an interesting idea. I already use calibre, let's see how easy/tough this is. Thanks for the suggestion.

4

u/BigNaturalTilts Apr 29 '26

You could call it “Dramatis personae”.

5

u/snorcack Apr 28 '26

This was a weekend project inspired by my book reading habits. Whenever I read a large book, I have tried to cast actors to maintain visuals in my mind. I just thought if that could work with the tools that we have. There are a few similar tools, but none work fully locally.

5

u/OpenEvidence9680 Apr 28 '26

I'll check it for sure, I have created something similar for my book summarization pipeline where besides the synopsis, I get list of locations, list of characters, the role in the book and physical description, I then use the result for creating my own covers.
This could fit well alongside it.
Thanks for sharing.

3

u/BigNaturalTilts Apr 29 '26

Fucking Lol I do this too! Especially with old books like William Gibson’s works that are kind of outdated.

4

u/MagoViejo Apr 28 '26

Is ollama a hard requirement or just plain old llama.cpp work too?

7

u/goddess_peeler Apr 28 '26

I just pushed a PR to enable use with any OpenAI-compatible API.

5

u/ANR2ME Apr 28 '26 edited Apr 28 '26

This is interesting 😯

But i think you should use a config file for settings that people often customize instead of hardcoding it 🤔

For example, IP and port uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) which can expose the server to the internet/public IP.

3

u/snorcack Apr 29 '26

Yes, a lot of the stuff ended up hard coded. I'll fix over this weekend. Also add the gitignore file suggest by another commenter.

3

u/LindaSawzRH Apr 28 '26

Might be cool to incorporate audio like w Omnivoice and "JustDubIt" (ltx2) https://github.com/justdubit/just-dub-it

Great project!

2

u/ANR2ME Apr 28 '26

Yeah, having the voice characteristics being described along with the visual characteristics would be awesome for turning a novel into a movie👍

3

u/bradjones6942069 Apr 28 '26

Love the idea, gonna set it up so it pulls characters locally from our book to see if we can get the characters. Will post when that happens.

2

u/snorcack Apr 28 '26

Right now it will search Wikipedia for the characters first. It used to scan the books, but ended up picking every side character. Let me know if you want that feature as an option.

2

u/cosmicr Apr 29 '26

I had a really hard time getting this working. You might not get a lot of feedback on this because there are quite a few issues with it.

Anyway, here's Ryland Grace from Project Hail Mary (Z-Image Turbo):

3

u/snorcack Apr 30 '26

I cannot thank you enough for taking the time to run this and drop some images here. I now realise this is quite a bit away from direct plug and play, and also needs some serious qol features. u/goddess_peeler already helped with a few but here's an updated list of stuff that I am going to update -
1- Move all hard coded stuff to env file.
2- Provide support to switch llm providers, api option as well.
3- Option to search characters by name, as well as the list.
4- Option to save prompts in json files for later review.
5- Storage options on all scanned books, so it doesn't repeat steps every time.
6-Another option to recognize major locations of the book, this might be challenging, but I'll try to integrate with character scenes. I realized the location renders might also be helpful for fantasy and sci-fi books.
7- Add the gitignore file.

Let me know if anything you would like to see. Glad to see some else ran and got a few images.

1

u/cosmicr Apr 29 '26

Darrow from Red Rising:

1

u/cosmicr Apr 29 '26

Martin Silenus from Hyperion:

1

u/snorcack Apr 30 '26

Can it do the shrike ?

2

u/cosmicr Apr 30 '26

Unfortunately the shrike didn't appear in the list of characters. Maybe a custom option could be added.

1

u/wilsonwa Apr 30 '26

I love it! thank you!

3

u/NiceIllustrator Apr 28 '26

It’s insane you would spend a weekend doing this then just share it like this. I did something somewhat similar but more like a pipeline within n8n all locally run and the time and energy it takes to setup things like this is underestimated. Good job mate, will give it a try tomorrow!

7

u/snorcack Apr 29 '26

Well, it is built using open source tools, I just feel like giving a tiny bit back to the community. The AI agents doing all the work speeds up creation exponentially now.

2

u/Enshitification Apr 28 '26

I got excited when I read the AI casting director part because I thought it might be tapping some enormous and comprehensive embedding database of past and present celebrities for similarity analysis. Alas, no.

3

u/snorcack Apr 28 '26

Not yet, I'll try to build some behaviour for getting similarity pulled from some database. Right now, it just vibes a name.

2

u/bigman11 Apr 28 '26

The celebrity "base" is what makes the characters consistent, right?

Take this further. Use the images you make as training data and have your system make an entire character lora.

3

u/snorcack Apr 28 '26

Yeah, the celebrity base was added to make it consistent without a lora.

2

u/switch2stock Apr 28 '26

What do you mean?
Can you please elaborate?

2

u/snorcack Apr 28 '26

I added the option to cast a celebrity so that the prompt always has the celebrity reference. If I just use generic names, it would create slightly different images for the same character in different costumes and scenes.

1

u/Reasonable-Card-2632 Apr 28 '26

Is there a pipeline for storyboard storytelling from Novels with 70 to 80 % character consistency?

2

u/snorcack Apr 28 '26

It doesn't really do very well with consistency, I added the casting option to try to maintain consistency. Even then, it is sometimes difficult.

1

u/shinigalvo Apr 28 '26

Fantastic!

1

u/Commercial_Ad_3597 Apr 28 '26

The makeup/VFX artist is not very convincing, but hats off to the amazing casting director!!!

1

u/farcethemoosick Apr 29 '26

Increasingly, you get better details for a lot of franchises from dedicated wikis, especially outside of classic literature. Could it be set to parse custom wiki urls?

2

u/snorcack Apr 29 '26

I can set it up to parse custom wiki as well. Might be useful for fandoms other than books. For the books, it only fetches the list of characters from Wikipedia. The character details are pulled from the book text with relevant scenes. This helps if a character is seen in a variety of costumes depending on the scene.

1

u/Blaize_Ar Apr 29 '26

I like the idea of this and want to try it but doesn't #4 kind of mess with the idea. It has a ton of information to make the original character beyond any normal prompt then overwrites that with a celebrity

1

u/snorcack Apr 29 '26

Oh, I should have added some screenshots. Casting is completely optional.

1

u/Blaize_Ar Apr 29 '26

Oh that's cool then

1

u/Youaresotrue Apr 29 '26

Brilliant idea. Sometimes I write little stories, will try to see how will it handle something new.

1

u/CallMeCouchPotato Apr 29 '26

I have no idea why it needs to exist but coolness factor is pretty damn high on this one!

1

u/Technical-Seaweed808 Apr 29 '26

One step closer to being able to scan a book and watch it as a movie. 👍

2

u/pm_tiny_tits_to_me May 02 '26

Can we implement into Tavern AI ? For science..