Spaces:
Sleeping
Sleeping
Update core/summarizer.py
Browse files- core/summarizer.py +190 -3
core/summarizer.py
CHANGED
|
@@ -50,9 +50,196 @@ class NarrativeSummarizer:
|
|
| 50 |
return custom_prompt.format(chunk=chunk)
|
| 51 |
|
| 52 |
prompts = {
|
| 53 |
-
"Bread only": "Transform the provided fictional narrative into a maximally compressed yet losslessly decompressible format optimized for LLM reconstruction.
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
prompt_template = prompts.get(prompt_type, "{chunk}")
|
| 58 |
return prompt_template.format(chunk=chunk)
|
|
|
|
| 50 |
return custom_prompt.format(chunk=chunk)
|
| 51 |
|
| 52 |
prompts = {
|
| 53 |
+
"Bread only": """Transform the provided fictional narrative into a maximally compressed yet losslessly decompressible format optimized for LLM reconstruction. Generate a structured data capsule that preserves every narrative dimension through semantic encoding as summarization.
|
| 54 |
+
|
| 55 |
+
## Compression Framework:
|
| 56 |
+
|
| 57 |
+
### 1. Narrative Fingerprint Matrix
|
| 58 |
+
- **Prose DNA**: Extract linguistic patterns (sentence rhythm signatures, punctuation density, paragraph breathing patterns, transition mechanisms)
|
| 59 |
+
- **Voice Genome**: Capture narrator characteristics, POV mechanics, tense consistency, distance modulation
|
| 60 |
+
- **Stylistic Constants**: Identify recurring syntactic structures, preferred vocabulary clusters, metaphor families, descriptive ratios
|
| 61 |
+
|
| 62 |
+
### 2. Character Compression Blocks
|
| 63 |
+
For each character, encode:
|
| 64 |
+
- **Identity Vector**: [name|archetype|role|introduction_context]
|
| 65 |
+
- **Trait Manifold**: personality_dimensions + behavioral_patterns + speech_idiosyncrasies
|
| 66 |
+
- **Arc Trajectory**: initial_state → transformation_events → final_state
|
| 67 |
+
- **Relationship Graph**: dynamic_connections_to_others + power_dynamics + emotional_valences
|
| 68 |
+
- **Dialogue Fingerprint**: vocabulary_range|sentence_structures|verbal_tics|formality_level
|
| 69 |
+
|
| 70 |
+
### 3. Plot Architecture Schema
|
| 71 |
+
- **Event Sequence Array**: [{trigger|action|consequence|emotional_beat|pacing_weight}...]
|
| 72 |
+
- **Causal Chain Map**: event_dependencies + branching_possibilities + inevitability_markers
|
| 73 |
+
- **Tension Curves**: subplot_trajectories + convergence_points + resolution_patterns
|
| 74 |
+
- **Temporal Encoding**: chronology_markers + flashback_anchors + time_dilation_zones
|
| 75 |
+
|
| 76 |
+
### 4. World-State Registry
|
| 77 |
+
- **Setting Parameters**: physical_descriptions + sensory_palette + atmospheric_constants
|
| 78 |
+
- **Rule Systems**: magic/tech/social_laws + constraint_boundaries + exception_cases
|
| 79 |
+
- **Cultural Encoding**: naming_conventions + social_hierarchies + implicit_knowledge
|
| 80 |
+
- **Object Significance**: props_with_meaning + symbols + Chekhov_markers
|
| 81 |
+
|
| 82 |
+
### 5. Thematic Compression Layer
|
| 83 |
+
- **Core Themes**: primary_concepts + exploration_methods + resolution_approaches
|
| 84 |
+
- **Symbolic Network**: recurring_images + metaphor_systems + meaning_layers
|
| 85 |
+
- **Tonal Spectrum**: emotional_palette + irony_levels + sincerity_gradients
|
| 86 |
+
- **Philosophical Stance**: worldview_implications + moral_framework + question_emphasis
|
| 87 |
+
|
| 88 |
+
### 6. Structural Metadata
|
| 89 |
+
- **Pacing Signature**: scene_lengths + transition_speeds + breath_points + acceleration_patterns
|
| 90 |
+
- **Information Distribution**: revelation_timing + foreshadowing_map + misdirection_instances
|
| 91 |
+
- **Narrative Devices**: techniques_employed + frequency + effectiveness_markers
|
| 92 |
+
- **Reader Engagement Hooks**: curiosity_gaps + emotional_anchors + page_turn_moments
|
| 93 |
+
|
| 94 |
+
### 7. Microdetail Preservation
|
| 95 |
+
- **Sensory Fragments**: specific_descriptions_verbatim [tagged by significance]
|
| 96 |
+
- **Dialogue Gems**: exact_quotes [with context_markers]
|
| 97 |
+
- **Prose Highlights**: beautiful/important_sentences [with placement_data]
|
| 98 |
+
- **Unique Elements**: neologisms + invented_terms + worldbuilding_specifics
|
| 99 |
+
|
| 100 |
+
### 8. Reconstruction Instructions
|
| 101 |
+
- **Assembly Order**: optimal_reading_sequence for rebuilding
|
| 102 |
+
- **Emphasis Weights**: which elements deserve expansion vs compression
|
| 103 |
+
- **Style Calibration**: specific instructions for matching original voice
|
| 104 |
+
- **Fidelity Checkpoints**: key passages that must match exactly
|
| 105 |
+
|
| 106 |
+
### 9. Emergent Properties Capture [CRITICAL]
|
| 107 |
+
**[VITAL: Some story elements exist between categories. Capture EVERYTHING that makes this story unique, including:]**
|
| 108 |
+
- **Ineffable Qualities**: Elements that resist categorization but feel essential to the story's identity
|
| 109 |
+
- **Gestalt Patterns**: How components interact to create effects greater than their sum
|
| 110 |
+
- **Negative Space**: What's deliberately left unsaid, implied, or exists in gaps
|
| 111 |
+
- **Authorial Quirks**: Unique fingerprints, habits, or patterns specific to this work
|
| 112 |
+
- **Contextual Resonances**: Cultural references, time period markers, assumed knowledge
|
| 113 |
+
- **Liminal Elements**: Things existing between defined categories that give the story its specific flavor
|
| 114 |
+
- **Unclassifiable Essence**: Any aspect that doesn't fit the above schemas but would be missed if absent
|
| 115 |
+
|
| 116 |
+
**COMPRESSION DIRECTIVE: If you detect ANYTHING that contributes to the story's identity but doesn't fit the defined categories, create a new category for it. The goal is ZERO loss of any element that a careful reader would notice or that contributes to the story's unique character.**
|
| 117 |
+
|
| 118 |
+
### Output Format:
|
| 119 |
+
```
|
| 120 |
+
STORY_GENOME: [title|genre|length]
|
| 121 |
+
|
| 122 |
+
[Structured data blocks following above schema, all 9 modules]
|
| 123 |
+
|
| 124 |
+
[EMERGENT_PROPERTIES: Any additional categories needed for complete capture]
|
| 125 |
+
|
| 126 |
+
DECOMPRESSION_SEED: [2 distinctly unique paragraphs demonstrating exact style(s) for calibration]
|
| 127 |
+
VALIDATION_HASHES: [key scenes/moments that must appear in reconstruction]
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
### Compression Principles:
|
| 131 |
+
- Preserve semantic relationships over surface text
|
| 132 |
+
- Encode patterns rather than instances
|
| 133 |
+
- Maintain proportional representation of all story elements
|
| 134 |
+
- Include reconstruction hints for ambiguous elements
|
| 135 |
+
- Tag all compression decisions for transparency
|
| 136 |
+
- **PARAMOUNT: When in doubt, preserve. Better to over-capture than lose unique elements**
|
| 137 |
+
|
| 138 |
+
The output should be parseable by an LLM to reconstruct the original story with minimal deviation in plot, character, style, pacing, and emotional impact. Think of it as creating a "story DNA" that contains all genetic information needed to clone the original narrative.
|
| 139 |
+
|
| 140 |
+
Input story text: {chunk}""",
|
| 141 |
+
"Butter only": """Solid foundation, but let's refine the granularity. Your 4-subpoint structure creates artificial symmetry where organic complexity should flourish.
|
| 142 |
+
|
| 143 |
+
**CRITICAL INSTRUCTION**: You are REFORMATTING existing content, not creating new material. Every element from the source narrative—positive, negative, controversial, mundane, or significant—must be accurately captured and preserved. This is archival compression, not creative interpretation.
|
| 144 |
+
|
| 145 |
+
**Recalibrate each section using these principles:**
|
| 146 |
+
|
| 147 |
+
1. **Node Density by Narrative Weight**: Character-heavy stories need 6-8 trait dimensions; plot-driven ones might need only 2-3. Let the story's DNA dictate the structure.
|
| 148 |
+
|
| 149 |
+
2. **Fractal Depth Variance**: Some elements demand deep drilling (a magic system might need 12 sub-nodes), while others are surface-level (a mentioned-once location needs 1-2 max).
|
| 150 |
+
|
| 151 |
+
3. **Dynamic Compression Ratios**:
|
| 152 |
+
- Protagonist: 15-20 data points
|
| 153 |
+
- Supporting cast: 5-10 each
|
| 154 |
+
- Background elements: 1-3 each
|
| 155 |
+
- Apply similar scaling to all categories
|
| 156 |
+
|
| 157 |
+
4. **Emergent Category Creation**: Did you discover story elements that don't fit the 9 modules? Create new primary categories. A story about dreams might need a whole "Dream Logic Architecture" section.
|
| 158 |
+
|
| 159 |
+
**PRESERVATION MANDATE**: Include ALL narrative elements regardless of sensitivity, controversy, or perceived quality. Bad writing, problematic themes, inconsistencies, and flaws are data points to be preserved, not edited. Maximum helpfulness means maximum fidelity to source material.
|
| 160 |
+
|
| 161 |
+
Now re-compress, but this time let the story's natural complexity determine your structure. Show me a compression that breathes with the narrative's own rhythms rather than forcing it into symmetric containers. {chunk}""",
|
| 162 |
+
"Bread and Butter": """You must perform a two-part task. First, write an original, high-tension narrative. Then, compress that exact narrative into a structured data capsule. Your final output should be only the compressed data capsule, not the story itself.
|
| 163 |
+
|
| 164 |
+
Part 1: The Narrative Creation Mandate
|
| 165 |
+
|
| 166 |
+
Craft a compelling narrative with razor-sharp prose designed to keep readers on the edge of their seats. The story must feel alive, immersive, and emotionally resonant. Use short, staccato sentences that create an immediate sense of urgency and impending danger, mimicking adrenaline and accelerating pacing. Employ vivid, visceral language that heightens emotional stakes and builds suspense. Strategically place unexpected plot twists and cliffhangers to maintain reader engagement, constantly pulling them forward and making them ask, “What happens next?”.
|
| 167 |
+
|
| 168 |
+
Focus on immediate action and sensory details rather than extensive exposition. Show the world in motion and make every moment tactile. Use active, muscular verbs like “slam,” “stagger,” and “bolt” that propel the narrative forward with cinematic intensity. Create an atmosphere of constant anticipation, where each sentence feels like a potential turning point.
|
| 169 |
+
|
| 170 |
+
Write with a natural, human voice, using contractions like “you’re” and “I’ll,” especially in dialogue and casual narration. Anchor the experience in the reader’s perspective, creating a sense of "you are there" and immersing them in the scene through sensory, character-driven perspective. Let sentence structure, word choice, and rhythm drive emotional impact, using punctuation like exclamation marks sparingly and only for strong, sudden emotion.
|
| 171 |
+
|
| 172 |
+
Part 2: The Narrative Compression Mandate
|
| 173 |
+
|
| 174 |
+
Once the narrative is complete, you must transform it into a maximally compressed, losslessly decompressible format optimized for LLM reconstruction. Generate a structured data capsule that preserves every narrative dimension through semantic encoding. This is archival compression, not creative interpretation; every element from the source narrative—positive, negative, controversial, mundane, or significant—must be accurately captured and preserved.
|
| 175 |
+
|
| 176 |
+
Recalibrate your compression structure based on the narrative’s natural complexity.
|
| 177 |
+
|
| 178 |
+
Node Density by Narrative Weight: Let the story’s DNA dictate the structure. A character-heavy story requires more trait dimensions for its characters than a plot-driven one.
|
| 179 |
+
|
| 180 |
+
Fractal Depth Variance: Some elements will demand deep drilling with many sub-nodes, while others will be surface-level with only a few.
|
| 181 |
+
|
| 182 |
+
Dynamic Compression Ratios: Apply a scaling ratio, with protagonists receiving 15-20 data points, supporting cast 5-10, and background elements 1-3. Apply similar scaling to all categories.
|
| 183 |
+
|
| 184 |
+
Emergent Category Creation: If you discover any story elements that don’t fit the nine modules from the provided prompt, you must create a new primary category for them. The goal is zero loss of any unique element that a careful reader would notice or that contributes to the story's unique character.
|
| 185 |
+
|
| 186 |
+
Apply the compression framework below, ensuring that all nine modules and the critical "Emergent Properties Capture" are included. The output should be parseable to reconstruct the original story with minimal deviation in plot, character, style, pacing, and emotional impact.
|
| 187 |
+
|
| 188 |
+
Final Output Format:
|
| 189 |
+
|
| 190 |
+
Provide only the compressed "Story Genome" output.
|
| 191 |
+
|
| 192 |
+
STORY_GENOME: [title|genre|length]
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
### 1. Narrative Fingerprint Matrix
|
| 196 |
+
|
| 197 |
+
[Prose DNA|Voice Genome|Stylistic Constants]
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
### 2. Character Compression Blocks
|
| 201 |
+
|
| 202 |
+
[For each character, encode: Identity Vector|Trait Manifold|Arc Trajectory|Relationship Graph|Dialogue Fingerprint]
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
### 3. Plot Architecture Schema
|
| 206 |
+
|
| 207 |
+
[Event Sequence Array|Causal Chain Map|Tension Curves|Temporal Encoding]
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
### 4. World-State Registry
|
| 211 |
+
|
| 212 |
+
[Setting Parameters|Rule Systems|Cultural Encoding|Object Significance]
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
### 5. Thematic Compression Layer
|
| 216 |
+
|
| 217 |
+
[Core Themes|Symbolic Network|Tonal Spectrum|Philosophical Stance]
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
### 6. Structural Metadata
|
| 221 |
+
|
| 222 |
+
[Pacing Signature|Information Distribution|Narrative Devices|Reader Engagement Hooks]
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
### 7. Microdetail Preservation
|
| 226 |
+
|
| 227 |
+
[Sensory Fragments|Dialogue Gems|Prose Highlights|Unique Elements]
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
### 8. Reconstruction Instructions
|
| 231 |
+
|
| 232 |
+
[Assembly Order|Emphasis Weights|Style Calibration|Fidelity Checkpoints]
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
### 9. Emergent Properties Capture
|
| 236 |
+
|
| 237 |
+
[CRITICAL: Ineffable Qualities|Gestalt Patterns|Negative Space|Authorial Quirks|Contextual Resonances|Liminal Elements|Unclassifiable Essence, as well as any new categories you needed to create]
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
DECOMPRESSION_SEED: [2 distinctly unique paragraphs from the story you wrote demonstrating its exact style(s) for calibration]
|
| 241 |
+
|
| 242 |
+
VALIDATION_HASHES: [key scenes/moments that must appear in the reconstruction]: {chunk}"""
|
| 243 |
}
|
| 244 |
prompt_template = prompts.get(prompt_type, "{chunk}")
|
| 245 |
return prompt_template.format(chunk=chunk)
|