Transform classic stories into new genres using AI โ preserving narrative essence while reimagining setting, characters, and style.
Built by Hemant Sudarshan
Takes any classic story and systematically transforms it into a completely different genre:
Cinderella โ Space Opera (fairy godmother โ AI hologram mentor)
Tortoise & Hare โ Cyberpunk (race โ data heist competition)
Icarus โ Post-Apocalyptic (wax wings โ makeshift glider)
๐ก The system is demonstrated on Cinderella, Icarus, and Tortoise & Hare as examples, but is designed to generalize to any public-domain work โ Shakespeare, Greek myths, folk tales, or classic literature.
Not just "rewriting" โ the system analyzes narrative structure, maps elements systematically, and generates with adaptive pacing control.
# Install
pip install -r requirements.txt
python -c "import nltk; nltk.download('vader_lexicon')"
# Configure (add your OpenRouter API key)
cp .env.example .env
# Transform!
python run.py \
--source examples/tortoise_hare.txt \
--title "The Tortoise and the Hare" \
--genre cyberpunk \
--beats 3 \
--output output/story.txtOutput: 800-1000 word story in ~60 seconds
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ ANALYZE โ โ โ MAP โ โ โ GENERATE โ โ โ ASSEMBLE โ โ โ OUTPUT โ
โ โ โ โ โ (loop) โ โ โ โ โ
โ Extract: โ โ Translate: โ โ Per beat: โ โ Combine: โ โ Final: โ
โ โข Characters โ โ โข Names โ โ โข Context โ โ โข Scenes โ โ โข Story โ
โ โข Themes โ โ โข Locations โ โ โข NTI check โ โ โข Formatting โ โ โข Metrics โ
โ โข Conflicts โ โ โข Objects โ โ โข Pacing โ โ โข Metadata โ โ โ
โ โข Beats โ โ โข Concepts โ โ โข State โ โ โ โ โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
| Source | Cyberpunk Equivalent | Preserved Function |
|---|---|---|
| Hare | Blitz โ elite speed-hacker with neural overclocking | Overconfident protagonist |
| Tortoise | Shell โ methodical old-school coder | Underestimated underdog |
| Race | Data heist competition on the Grid | Central conflict/challenge |
| Nap | Neural cooldown (overclocked brain forces shutdown) | Hubris leading to downfall |
The Problem: LLMs generate creative text but struggle with consistent pacing โ stories often feel flat or peak too early.
The Solution: Quantitative tension measurement with adaptive feedback:
NTI = (1 - certainty) ร (1 - sentiment)
High NTI = uncertain outcome + negative emotion โ TENSION
Low NTI = clear outcome + positive emotion โ RESOLUTION
How it works:
- Generate scene
- Calculate actual NTI using sentiment analysis
- Compare to target (based on Save the Cat beat structure)
- Adjust next scene's pacing hints
Target Tension Curve (Save the Cat):
2.0 | โ
โ Climax
| โ
1.5 | โ
โ
โ Midpoint
| โ
โ
1.0 | โ
โ
|โ
โ
0.5 | โ
โ Resolution
+----------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12
BEATS
| Story | Target Genre | Words | Avg NTI | Status |
|---|---|---|---|---|
| Cinderella | Space Opera | 932 | 0.60 | โ |
| Tortoise & Hare | Cyberpunk | 874 | 0.63 | โ |
| Icarus | Post-Apocalyptic | 940 | 1.33 | โ |
100% success rate across all test transformations
| Genre | Aesthetic | Example Elements |
|---|---|---|
cyberpunk |
Neon-lit tech dystopia | Neural jacks, megacorps, data heists |
space_opera |
Epic galactic adventure | Starships, alien councils, hyperspace |
victorian_gothic |
Fog-shrouded horror | Gas lamps, sรฉances, dark secrets |
post_apocalyptic |
Survival in ruins | Scavengers, wasteland, lost tech |
mythic_fantasy |
Legendary tales | Ancient magic, prophecies, quests |
narrative-transformer/
โโโ llm_client.py # Centralized LLM client (retry logic, JSON mode)
โโโ analyzer.py # Phase 1: Source analysis
โโโ mapper.py # Phase 2: World mapping
โโโ generator.py # Phase 3: Scene generation
โโโ tension.py # NTI calculator & pacing controller
โโโ transformer.py # Main orchestrator
โโโ config.py # Genre templates & settings
โโโ models.py # Data structures
โโโ run.py # CLI interface
โโโ run_tests.py # Test suite (3 stories)
โ
โโโ examples/ # Sample inputs
โ โโโ cinderella.txt
โ โโโ tortoise_hare.txt
โ โโโ icarus.txt
โ โโโ SAMPLE_TRANSFORMATION.md # Intermediate data example
โ
โโโ output/ # Generated stories
โ
โโโ SOLUTION.md # Technical documentation
โโโ APPROACH.md # Design decisions & alternatives
from transformer import NarrativeTransformer
transformer = NarrativeTransformer()
story, metadata = transformer.transform(
source_text="Your story here...",
source_title="My Story",
target_genre="cyberpunk",
num_beats=5
)
print(story)
print(f"Words: {metadata['word_count']}")
print(f"Tension: {metadata['avg_tension']:.2f}")Create .env file:
# OpenRouter (recommended)
OPENAI_API_KEY=sk-or-v1-your-key
OPENAI_BASE_URL=https://openrouter.ai/api/v1
DEFAULT_MODEL=openai/gpt-3.5-turbo
# Settings
TEMPERATURE=0.7
MAX_TOKENS=2000| Decision | Why |
|---|---|
| Context-based (not RAG) | 2-3 pages fit in context; simpler, faster, debuggable |
| Beat-by-beat generation | Enables state tracking + pacing control |
| Save the Cat structure | Industry-standard framework with clear targets |
| Quantitative NTI | Measurable quality โ feedback loop |
| Centralized LLM client | Retry logic, JSON mode, consistent interface |
See APPROACH.md for full analysis of alternatives considered.
| Metric | Value |
|---|---|
| Generation time (3 beats) | ~30-60 seconds |
| API calls per transformation | 10-15 |
| Output length | 800-1000 words |
| Retry resilience | 3 attempts + exponential backoff |
- SOLUTION.md โ Full technical walkthrough with architecture diagrams
- APPROACH.md โ Design rationale, alternatives, challenges
- examples/SAMPLE_TRANSFORMATION.md โ Intermediate transformation data
Core Features:
- Multi-POV support (scenes from different character perspectives)
- Interactive mode (approve/edit at each stage)
- Novel-length optimization
- Style transfer from example texts
Optional Extensions (for contributors):
- Streamlit UI โ Web interface with live progress and tension visualization
- MLOps Integration โ Experiment tracking (MLflow/W&B), cost monitoring, A/B testing
- GitHub Actions CI โ Automated testing on every push
- REST API โ FastAPI endpoint for programmatic access
- Docker โ Containerized deployment
MIT License โ See LICENSE for details.
๐ง The Narrative Tension Index โ quantitative pacing control for AI-generated stories
Built as a demonstration of system design, prompt engineering, and creative AI applications.