Skip to content

Instantly share code, notes, and snippets.

@dli7319
Last active September 14, 2023 02:17
Show Gist options
  • Select an option

  • Save dli7319/e85d38fdd2e46eab279ad05e34db2835 to your computer and use it in GitHub Desktop.

Select an option

Save dli7319/e85d38fdd2e46eab279ad05e34db2835 to your computer and use it in GitHub Desktop.
Anki Card Creation Aeneid
Arma virumque canō, Trōiae quī prīmus ab ōrīs
Ītaliam, fātō profugus, Lāvīniaque vēnit
lītora, multum ille et terrīs iactātus et altō
vī superum saevae memorem Iūnōnis ob īram;
multa quoque et bellō passus, dum conderet urbem,
inferretque deōs Latiō, genus unde Latīnum,
Albānīque patrēs, atque altae moenia Rōmae.
Mūsa, mihī causās memorā, quō nūmine laesō,
quidve dolēns, rēgīna deum tot volvere cāsūs
īnsīgnem pietāte virum, tot adīre labōrēs
impulerit. Tantaene animīs caelestibus īrae?
import openai
import genanki
import tqdm
# openai.api_key = 'API_KEY'
with open("aen1.txt") as f:
aeneid = f.readlines()
aeneid = [x.strip() for x in aeneid if x.strip() != ""]
my_model = genanki.Model(
2074335081,
'Simple Model',
fields=[
{'name': 'Question'},
{'name': 'Answer'},
],
templates=[
{
'name': 'Card 1',
'qfmt': '{{Question}}',
'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
},
])
my_deck = genanki.Deck(
2064781937,
'Aeneid')
for line in tqdm.tqdm(aeneid[:5]):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Translate the following latin paragraph: Athēniēnsēs autem omnēs, et advenæ hospitēs, ad nihil aliud vacābant nisi aut dīcere aut audīre aliquid nōvī." },
{"role": "assistant", "content": "Now all the Athenians, and strangers that were there, employed themselves in nothing else, but either in telling or in hearing some new thing."},
{"role": "user", "content": f"Translate the following latin paragraph: {line}"}
]
)
translation = response['choices'][0]['message']['content']
# print("Translation:", translation)
my_note = genanki.Note(
model=my_model,
fields=[line, translation])
my_deck.add_note(my_note)
genanki.Package(my_deck).write_to_file('aeneid.apkg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment