| __pycache__ | ||
| data | ||
| app.py | ||
| character_extractor.py | ||
| character_manager.py | ||
| config.py | ||
| document_processor.py | ||
| example_manuscript.txt | ||
| install.sh | ||
| PROJECT_SUMMARY.md | ||
| rag_engine.py | ||
| README.md | ||
| requirements.txt | ||
| run.sh | ||
| run_venv.sh | ||
| setup.py | ||
📚 Character Conversation Studio
A powerful local application that allows authors and writers to have immersive conversations with characters from their manuscripts using state-of-the-art local Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG).
✨ Features
- 🤖 Automatic Character Extraction: AI automatically identifies characters and their personality traits from your manuscript
- 💬 Character Conversations: Chat with your fictional characters as if they were real people
- 🧠 RAG-Powered Memory: Characters remember context from your entire manuscript
- 🔒 Privacy First: Everything runs locally - your manuscripts never leave your machine
- 📖 Multi-Format Support: Import TXT, DOCX, and PDF manuscripts
- 👤 Smart Character Profiles: AI-extracted personality traits, roles, and relationships
- 💾 Persistent Conversations: Chat history is saved and maintained
- 🎯 Context-Aware Responses: Characters respond based on relevant manuscript content
- 🔄 Real-Time Processing: Fast embedding generation and similarity search
- 📊 Character Analysis: Detailed character insights including relationships and key quotes
🏗️ Architecture
This application implements a sophisticated RAG (Retrieval-Augmented Generation) pipeline:
- Document Ingestion: Manuscripts are processed and chunked into manageable pieces
- Embedding Generation: Text chunks are converted to vector embeddings using sentence transformers
- Vector Storage: Embeddings are stored in ChromaDB for fast similarity search
- Context Retrieval: When you ask a character a question, relevant manuscript chunks are retrieved
- Response Generation: Local LLM generates character responses using retrieved context and character profiles
🛠️ Prerequisites
1. Install Ollama
macOS/Linux:
curl -fsSL https://ollama.ai/install.sh | sh
Windows: Download from ollama.ai
2. Start Ollama Server
ollama serve --port 11435
3. Install a Language Model
# Recommended model for character conversations
ollama pull llama3.1:8b
# Alternative models you can try:
ollama pull mistral:7b
ollama pull gemma2:9b
🚀 Installation
Quick Installation (Recommended)
- Clone or download this repository
git clone <repository-url>
cd character-conversation-studio
- Run the installation script
./install.sh
- Run the application
./run_venv.sh
Manual Installation
- Clone or download this repository
git clone <repository-url>
cd character-conversation-studio
- Create a virtual environment
python3 -m venv venv
source venv/bin/activate
- Install Python dependencies
pip install -r requirements.txt
- Run the application
streamlit run app.py
- Open your browser to
http://localhost:8501
🤖 Automatic Character Extraction
One of the most powerful features of this application is automatic character extraction. When you upload a manuscript, the AI analyzes your text and automatically identifies characters along with their personality traits, roles, and relationships.
How It Works
- Character Detection: Uses Named Entity Recognition (NER) and pattern matching to identify character names
- Validation: Filters out false positives by analyzing dialogue patterns and action descriptions
- Trait Analysis: Local LLM analyzes character passages to extract personality traits and behaviors
- Role Identification: Determines each character's occupation, title, or position in the story
- Relationship Mapping: Identifies connections between characters based on co-occurrence patterns
- Quote Extraction: Finds notable dialogue and quotes from each character
What You Get
For each detected character:
- ✅ Name: Primary character identifier
- ✅ Role: Job, title, or position (e.g., "village blacksmith", "court wizard")
- ✅ Personality Traits: Behavioral patterns and characteristics
- ✅ Relationships: Connections to other characters
- ✅ Key Quotes: Memorable dialogue from the character
- ✅ Confidence Score: AI's certainty about the extraction accuracy
Benefits
- Time Saving: No need to manually create each character profile
- Comprehensive Analysis: AI may catch details you missed
- Consistent Personalities: Traits are extracted from actual text evidence
- Ready to Chat: Characters are immediately available for conversations
- Review & Edit: You can still review and modify any auto-extracted character
📋 Usage Guide
Step 1: Import Your Manuscript
- Navigate to "📖 Manuscript Manager"
- Upload your manuscript file (TXT, DOCX, or PDF)
- Give it a title and click "📥 Process Manuscript"
- Wait for processing to complete (this creates embeddings, stores them in the vector database, and automatically extracts characters)
Step 2: Review Auto-Extracted Characters
- After manuscript processing, automatically detected characters will be displayed
- Review each character's:
- Extracted Role: AI-identified role/occupation
- Personality Traits: AI-analyzed behavioral patterns
- Relationships: Detected connections to other characters
- Key Quotes: Notable dialogue from the character
- Confidence Score: How accurate the extraction likely is
- Click "✅ Import [Character Name]" for characters you want to chat with
- Or click "📥 Import All Characters" to add them all at once
Alternative: Manual Character Creation
- Go to "👤 Character Manager"
- Use "➕ Create New Character Manually" if you want to add custom characters
- Fill in character details manually if the AI missed someone or for custom characters
Step 3: Start Conversations
- Navigate to "💬 Character Chat"
- Select your character from the dropdown
- Start typing questions or prompts
- Enjoy natural conversations with your character!
💡 Example Interactions
You: "Arion, how did you feel when you discovered the truth about your father?"
Arion: "The revelation struck me like a blade to the heart, dear author. For years, I had carried the weight of believing him a coward who fled from battle. To learn that he died protecting our village... it changed everything. The anger I harbored turned to shame, and the shame to a fierce determination to honor his memory."
You: "What drives you to continue your quest despite the dangers?"
Arion: "The faces of those who depend on me, the memory of my father's sacrifice, and perhaps... perhaps the hope that I might finally prove myself worthy of the name I bear. Each step forward is both burden and blessing."
🔧 Configuration
Model Settings
You can modify the LLM settings in config.py:
DEFAULT_LLM_MODEL: Change the Ollama model usedTEMPERATURE: Adjust response creativity (0.0-1.0)MAX_TOKENS: Maximum response length
RAG Settings
CHUNK_SIZE: Size of text chunks for processingMAX_RETRIEVED_CHUNKS: Number of relevant chunks to retrieveSIMILARITY_THRESHOLD: Minimum similarity for chunk relevance
📁 Project Structure
character-conversation-studio/
├── app.py # Main Streamlit application
├── config.py # Configuration settings
├── document_processor.py # Manuscript processing and text extraction
├── character_manager.py # Character profiles and conversation management
├── rag_engine.py # Core RAG implementation
├── requirements.txt # Python dependencies
├── README.md # This file
└── data/ # Created automatically
├── manuscripts/ # Processed manuscript info
├── characters/ # Character profiles and chat history
└── vector_db/ # ChromaDB vector storage
🔍 Troubleshooting
"RAG engine not initialized"
- Ensure all dependencies are installed:
pip install -r requirements.txt - Check that Ollama is running:
ollama serve
"No models found"
- Install at least one model:
ollama pull llama3.1:8b - Verify installation:
ollama list
"Ollama connection failed"
- Make sure Ollama server is running on port 11434
- Check firewall settings if necessary
Slow responses
- Try a smaller model like
mistral:7b - Reduce
MAX_RETRIEVED_CHUNKSin config.py - Ensure you have adequate RAM/VRAM
🎨 Customization
Custom Prompt Templates
Modify the CHARACTER_PROMPT_TEMPLATE in config.py to change how characters respond:
CHARACTER_PROMPT_TEMPLATE = """
Your custom prompt here...
Character: {character_name}
Context: {retrieved_context}
Question: {user_question}
"""
Adding New File Formats
Extend document_processor.py to support additional file formats by adding new extraction methods.
🚧 Known Limitations
- Character responses depend on the quality of the local LLM
- Very large manuscripts (>100MB) may take significant time to process
- Character consistency may vary based on the model used
- Requires substantial RAM for larger models (8GB+ recommended)
🔮 Future Enhancements
- Character Voice Training: Fine-tune models on specific character dialogue
- Multi-Character Conversations: Support group conversations between characters
- Export Options: Export conversations as scripts or dialogue files
- Enhanced Character Analysis: Improved emotion detection and character arc analysis
- Character Relationship Graphs: Visual relationship mapping between characters
- Cloud Sync: Optional cloud backup for character profiles
🤝 Contributing
This is an open-source project. Contributions are welcome! Please feel free to:
- Report bugs and issues
- Suggest new features
- Submit pull requests
- Improve documentation
📄 License
This project is released under the MIT License. See LICENSE file for details.
🙏 Acknowledgments
- Ollama - For making local LLM deployment accessible
- LangChain - For RAG framework and document processing
- ChromaDB - For efficient vector storage
- Streamlit - For the beautiful web interface
- Sentence Transformers - For high-quality embeddings
Happy writing! May your characters come alive through conversation. 📚✨