Update app.py
Browse files1580 unmodified lines15811582158315841585158615871588158915901591159225 unmodified lines16181619162016211622162316241625162616271580 unmodified linesif not vocab_list:gr.Warning("No flashcards to export. Generate or import a deck first!")return gr.update(visible=False)os.makedirs(LOG_DIR, exist_ok=True)path = os.path.join(LOG_DIR, "flashcards_export.json")export_data = [{k: v for k, v in item.items() if k != 'audio_uri'} for item in vocab_list]with open(path, "w", encoding="utf-8") as f:json.dump(export_data, f, ensure_ascii=False, indent=2)return gr.update(value=path, visible=True)def export_anki_file_fn(vocab_list):25 unmodified linesitem.get('transliteration', ''),item.get('explanation', ''),]))os.makedirs(LOG_DIR, exist_ok=True)path = os.path.join(LOG_DIR, "flashcards_export.apkg")genanki.Package(deck).write_to_file(path)return gr.update(value=path, visible=True)def import_deck_fn(json_file, anki_file):1580 unmodified lines15811582158315841585158615871588158915901591159215931594159525 unmodified lines162116221623162416251626162716281629163016311632163316341580 unmodified linesif not vocab_list:gr.Warning("No flashcards to export. Generate or import a deck first!")return gr.update(visible=False)export_data = [{k: v for k, v in item.items() if k != 'audio_uri'} for item in vocab_list]# Create a unique temporary filetemp_fd, temp_path = tempfile.mkstemp(suffix=".json", prefix="flashcards_export_")with os.fdopen(temp_fd, "w", encoding="utf-8") as f:json.dump(export_data, f, ensure_ascii=False, indent=2)return gr.update(value=temp_path, visible=True)def export_anki_file_fn(vocab_list):25 unmodified linesitem.get('transliteration', ''),item.get('explanation', ''),]))]))# Create a unique temporary filetemp_fd, temp_path = tempfile.mkstemp(suffix=".apkg", prefix="flashcards_export_")os.close(temp_fd) # Close it so genanki can write to itgenanki.Package(deck).write_to_file(temp_path)return gr.update(value=temp_path, visible=True)def import_deck_fn(json_file, anki_file):
app.py+15-8