generated from virtuelleakademie/promptly-literate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1,280 additions
and
118 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
_freeze/projects/anki/example/index/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"hash": "693eaafcd014332b4b1220990dbe7fe8", | ||
"result": { | ||
"engine": "jupyter", | ||
"markdown": "---\ntitle: \"Generate Anki flashcards: example code\"\njupyter: python3\nexecute: \n cache: true\n---\n\n::: {#de27807c .cell execution_count=1}\n``` {.python .cell-code}\nimport os\nimport csv\nfrom dotenv import load_dotenv # For loading environment variables\nfrom openai import OpenAI \n\nfrom pydantic import BaseModel, Field\nfrom typing import List\n```\n:::\n\n\n::: {#2c201188 .cell execution_count=2}\n``` {.python .cell-code}\nload_dotenv()\nclient = OpenAI()\n```\n:::\n\n\n::: {#38f58126 .cell execution_count=3}\n``` {.python .cell-code}\nclass AnkiFlashcard(BaseModel):\n \"\"\"\n Model representing a single Anki flashcard with question, answer, and tags.\n \"\"\"\n # Define required fields with descriptions\n question: str = Field(..., description=\"The front side of the flashcard containing the question\")\n answer: str = Field(..., description=\"The back side of the flashcard containing the answer\")\n tags: List[str] = Field(..., description=\"List of tags associated with the flashcard\")\n```\n:::\n\n\n::: {#571a9bda .cell execution_count=4}\n``` {.python .cell-code}\nclass AnkiDeck(BaseModel):\n \"\"\"\n Model representing a complete Anki deck containing multiple flashcards.\n \"\"\"\n # Define required fields with descriptions\n cards: List[AnkiFlashcard] = Field(..., description=\"List of flashcards in the deck\")\n deck_name: str = Field(..., description=\"Name of the Anki deck\")\n```\n:::\n\n\n::: {#93d3c3f9 .cell execution_count=5}\n``` {.python .cell-code}\ndef generate_structured_flashcards(text: str, \n deck_name: str, \n num_cards: int = 5) -> AnkiDeck:\n \"\"\"\n Generate structured flashcards using GPT-4o with enforced Pydantic model output.\n \n Args:\n text (str): The input text to generate flashcards from\n deck_name (str): Name for the Anki deck\n num_cards (int): Number of flashcards to generate (default: 5)\n \n Returns:\n AnkiDeck: A structured deck of flashcards with proper validation\n \n Raises:\n ValueError: If num_cards is less than 1\n \"\"\"\n # Validate input\n if num_cards < 1:\n raise ValueError(\"Number of cards must be at least 1\")\n \n # Make API call with structured output format\n completion = client.beta.chat.completions.parse(\n model=\"gpt-4o\",\n messages=[\n {\n \"role\": \"system\",\n \"content\": f\"\"\"You are an expert at creating Anki flashcards. Your task is to:\n1. Read the provided text\n2. Create {num_cards} Anki flashcards that cover the main concepts\n3. Add relevant tags to each flashcard\n4. Structure the output as an Anki deck with the name \"{deck_name}\".\"\"\"\n },\n {\n \"role\": \"user\",\n \"content\": f\"Please create Anki flashcards for the following text: {text}\"\n }\n ],\n response_format=AnkiDeck,\n )\n \n # Return the parsed response\n return completion.choices[0].message.parsed\n```\n:::\n\n\n\n\n:::{.callout-note collapse=true title=\"`romantic_text`\"}\n## The Romantic Era: Emotion Unleashed (1810-1910)\n\nThe Romantic era represented a dramatic shift in musical aesthetics, prioritizing emotional expression, individualism, and nationalism over the formal constraints of the Classical period. This century-long period saw an unprecedented expansion in the scope, scale, and emotional range of classical music.\n\n### The Romantic Spirit\n\nRomanticism emerged as a reaction against the rationalism of the Enlightenment and the Industrial Revolution. Composers sought to express intense personal emotions, explore supernatural themes, and celebrate national identity through music. This new aesthetic led to the development of program music - compositions that told specific stories or painted musical pictures.\n\n### Expansion of Musical Language\n\nThe Romantic period saw a significant expansion of harmonic language. Composers pushed the boundaries of chromatic harmony, using increasingly complex chord progressions and modulations to distant keys. This development reached its apex in Wagner's \"Tristan und Isolde,\" whose famous \"Tristan chord\" symbolized the dissolution of traditional tonality.\n\n### The Symphony Transformed\n\nThe symphony, inherited from the Classical era, underwent radical transformation. Beethoven's Ninth Symphony, with its unprecedented scale and inclusion of vocal soloists and chorus, set new standards for symphonic composition. Later composers like Berlioz, Mahler, and Bruckner created symphonies of enormous proportions, both in length and orchestral forces.\n\n### New Forms and Genres\n\nThe period saw the emergence of new musical forms suited to Romantic expression. The symphonic poem, developed by Franz Liszt, combined orchestral music with extra-musical narratives. The art song (Lied) reached new heights of sophistication in the hands of Schubert and Schumann, creating perfect unions of poetry and music.\n\n### Nationalism in Music\n\nNational schools of composition emerged as countries sought to express their cultural identity through music. Russian composers like Tchaikovsky and the \"Mighty Five\" incorporated folk melodies and national themes. Similar movements appeared in Bohemia (Smetana, Dvořák), Norway (Grieg), and other European nations.\n\n### The Rise of the Virtuoso\n\nThe Romantic era celebrated individual achievement, leading to the rise of the virtuoso performer. Pianists like Liszt and Chopin composed works of unprecedented technical difficulty, while violinists like Paganini pushed the boundaries of what was possible on their instrument. This emphasis on virtuosity influenced compositional style and public performance practices.\n\n### Wagner and Music Drama\n\nRichard Wagner revolutionized opera through his concept of Gesamtkunstwerk (total artwork), combining music, drama, poetry, and visual arts. His use of leitmotifs - recurring musical themes associated with characters, objects, or ideas - influenced not only opera but also symphonic composition and, later, film music.\n\n### Technical and Social Developments\n\nThe period saw significant developments in instrument construction. The modern piano reached its current form, while brass instruments benefited from the invention of valves. Orchestras grew larger, requiring the emergence of the conductor as an interpreter rather than merely a timekeeper.\n\n### The End of an Era\n\nThe Romantic period gradually gave way to various modern movements. The increasing chromatic harmony of late Romanticism led naturally to the breakdown of traditional tonality in the early 20th century. However, Romantic ideals of emotional expression and individualism continued to influence composers well into the modern era.\n\nThe Romantic era's emphasis on emotional expression, its technical innovations, and its expansion of musical possibilities created a legacy that continues to influence musicians today. The period's great works remain central to the concert repertoire, beloved for their emotional depth and expressive power.\n:::\n\n\n\n::: {#b6f029bd .cell execution_count=8}\n``` {.python .cell-code}\nromantic_deck = generate_structured_flashcards(romantic_text,\n \"Romanticism\", \n num_cards=10)\n```\n:::\n\n\n::: {#a6ec19d9 .cell execution_count=9}\n``` {.python .cell-code}\nromantic_deck\n```\n\n::: {.cell-output .cell-output-display execution_count=52}\n```\nAnkiDeck(cards=[AnkiFlashcard(question='What major shift did the Romantic era represent in musical aesthetics?', answer='The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.', tags=['Romanticism', 'MusicAesthetics']), AnkiFlashcard(question='What is program music and how did it relate to Romanticism?', answer=\"Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\", tags=['Romanticism', 'ProgramMusic']), AnkiFlashcard(question='How did harmonic language expand during the Romantic period?', answer='Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner\\'s \"Tristan chord.\"', tags=['Romanticism', 'HarmonicLanguage']), AnkiFlashcard(question='Which symphony transformed the symphonic form during the Romantic era?', answer=\"Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\", tags=['Romanticism', 'Symphony']), AnkiFlashcard(question='What is a symphonic poem and who developed it?', answer='A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.', tags=['Romanticism', 'MusicalForms']), AnkiFlashcard(question='Which regions developed national schools of composition during the Romantic era?', answer='National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.', tags=['Romanticism', 'Nationalism']), AnkiFlashcard(question='Who were some notable virtuoso performers during the Romantic era?', answer='Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.', tags=['Romanticism', 'Virtuosos']), AnkiFlashcard(question='What concept did Wagner introduce in opera, and how did it influence other genres?', answer='Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.', tags=['Romanticism', 'Opera']), AnkiFlashcard(question='How did instrument construction and orchestra management change during the Romantic period?', answer='Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.', tags=['Romanticism', 'Instrumentation']), AnkiFlashcard(question='How did the Romantic era influence later musical movements?', answer='The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.', tags=['Romanticism', 'ModernInfluence'])], deck_name='Romanticism')\n```\n:::\n:::\n\n\n::: {#ae689ec1 .cell execution_count=10}\n``` {.python .cell-code}\nprint(romantic_deck.model_dump_json())\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n{\"cards\":[{\"question\":\"What major shift did the Romantic era represent in musical aesthetics?\",\"answer\":\"The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.\",\"tags\":[\"Romanticism\",\"MusicAesthetics\"]},{\"question\":\"What is program music and how did it relate to Romanticism?\",\"answer\":\"Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\",\"tags\":[\"Romanticism\",\"ProgramMusic\"]},{\"question\":\"How did harmonic language expand during the Romantic period?\",\"answer\":\"Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner's \\\"Tristan chord.\\\"\",\"tags\":[\"Romanticism\",\"HarmonicLanguage\"]},{\"question\":\"Which symphony transformed the symphonic form during the Romantic era?\",\"answer\":\"Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\",\"tags\":[\"Romanticism\",\"Symphony\"]},{\"question\":\"What is a symphonic poem and who developed it?\",\"answer\":\"A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.\",\"tags\":[\"Romanticism\",\"MusicalForms\"]},{\"question\":\"Which regions developed national schools of composition during the Romantic era?\",\"answer\":\"National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.\",\"tags\":[\"Romanticism\",\"Nationalism\"]},{\"question\":\"Who were some notable virtuoso performers during the Romantic era?\",\"answer\":\"Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.\",\"tags\":[\"Romanticism\",\"Virtuosos\"]},{\"question\":\"What concept did Wagner introduce in opera, and how did it influence other genres?\",\"answer\":\"Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.\",\"tags\":[\"Romanticism\",\"Opera\"]},{\"question\":\"How did instrument construction and orchestra management change during the Romantic period?\",\"answer\":\"Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.\",\"tags\":[\"Romanticism\",\"Instrumentation\"]},{\"question\":\"How did the Romantic era influence later musical movements?\",\"answer\":\"The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.\",\"tags\":[\"Romanticism\",\"ModernInfluence\"]}],\"deck_name\":\"Romanticism\"}\n```\n:::\n:::\n\n\n::: {#0098c8a5 .cell execution_count=11}\n``` {.python .cell-code}\nfor card in romantic_deck.cards:\n print(f\"Question: {card.question}\")\n print(f\"Answer: {card.answer}\")\n print(f\"Tags: {', '.join(card.tags)}\")\n print(\"-\" * 20)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nQuestion: What major shift did the Romantic era represent in musical aesthetics?\nAnswer: The Romantic era represented a shift towards prioritizing emotional expression, individualism, and nationalism, moving away from the formal constraints of the Classical period.\nTags: Romanticism, MusicAesthetics\n--------------------\nQuestion: What is program music and how did it relate to Romanticism?\nAnswer: Program music is a type of composition that tells specific stories or paints musical pictures, aligned with Romanticism's emphasis on emotional expression and supernatural themes.\nTags: Romanticism, ProgramMusic\n--------------------\nQuestion: How did harmonic language expand during the Romantic period?\nAnswer: Composers expanded harmonic language by pushing boundaries of chromatic harmony, using complex chord progressions and modulations, exemplified by Wagner's \"Tristan chord.\"\nTags: Romanticism, HarmonicLanguage\n--------------------\nQuestion: Which symphony transformed the symphonic form during the Romantic era?\nAnswer: Beethoven's Ninth Symphony transformed the symphonic form with its unprecedented scale and inclusion of vocal soloists and chorus.\nTags: Romanticism, Symphony\n--------------------\nQuestion: What is a symphonic poem and who developed it?\nAnswer: A symphonic poem is an orchestral work that combines music with extra-musical narratives, developed by Franz Liszt.\nTags: Romanticism, MusicalForms\n--------------------\nQuestion: Which regions developed national schools of composition during the Romantic era?\nAnswer: National schools of composition emerged in Russia, Bohemia, Norway, and other European nations, often incorporating folk melodies and national themes.\nTags: Romanticism, Nationalism\n--------------------\nQuestion: Who were some notable virtuoso performers during the Romantic era?\nAnswer: Notable virtuoso performers included pianists like Liszt and Chopin, and violinists like Paganini, known for their technical achievements.\nTags: Romanticism, Virtuosos\n--------------------\nQuestion: What concept did Wagner introduce in opera, and how did it influence other genres?\nAnswer: Wagner introduced the concept of Gesamtkunstwerk (total artwork) and leitmotifs, influencing opera, symphonic composition, and film music.\nTags: Romanticism, Opera\n--------------------\nQuestion: How did instrument construction and orchestra management change during the Romantic period?\nAnswer: Instruments like the piano and brass instruments evolved; orchestras grew larger, making conductors interpreters rather than merely timekeepers.\nTags: Romanticism, Instrumentation\n--------------------\nQuestion: How did the Romantic era influence later musical movements?\nAnswer: The breakdown of traditional tonality led to modern movements, but Romantic ideals of emotional expression and individualism continued influencing composers.\nTags: Romanticism, ModernInfluence\n--------------------\n```\n:::\n:::\n\n\n::: {#66b0e2e0 .cell execution_count=12}\n``` {.python .cell-code}\nos.makedirs('assets/flashcards', exist_ok=True)\n\n# Export flashcards to CSV file\nwith open('assets/flashcards/romantic-flashcards.csv', \n 'w', \n newline='',\n encoding='utf-8') as csvfile:\n writer = csv.writer(csvfile)\n # Write header row\n writer.writerow(['Question', 'Answer', 'Tags'])\n # Write each flashcard as a row in the CSV\n for card in romantic_deck.cards:\n writer.writerow([card.question, card.answer, ', '.join(card.tags)])\n```\n:::\n\n\n", | ||
"supporting": [ | ||
"index_files" | ||
], | ||
"filters": [], | ||
"includes": {} | ||
} | ||
} |
Oops, something went wrong.