Skip to content

AI Flashcard Generator ๐Ÿง ๐Ÿ“š Convert educational content into Q&A flashcards using LLMs (Zephyr-7B).

Notifications You must be signed in to change notification settings

Deepender25/FlashCard-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  AI Flashcard Generator

Python Framework Model License: MIT

๐Ÿ“˜ A lightweight, LLM-powered tool to convert educational content into flashcards.


๐ŸŽฅ Demo Video

Flashcard.Demo.1.mp4

๐Ÿ–ผ๏ธ UI Screenshots

Screenshot 2025-06-13 205813

Screenshot 2025-06-13 205832

Screenshot 2025-06-13 210126


๐Ÿ“‘ Table of Contents


๐Ÿš€ Project Overview

This tool streamlines the study process by automatically generating flashcards from educational content such as textbook chapters, lecture notes, or articles.

Built with Streamlit and powered by Zephyr-7B-ฮฒ (via Hugging Face), it offers an intuitive UI and delivers clean, structured Q&A flashcards that can be exported to Quizlet or CSV.


โœ… Features

๐Ÿ”น Core Features

  • โœ… Multiple Content Inputs โ€“ Paste text or upload .txt / .pdf files.
  • โœ… LLM-Powered Generation โ€“ Generate a custom number of flashcards using Zephyr-7B.
  • โœ… Interactive UI โ€“ Streamlit-based frontend for simplicity and clarity.
  • โœ… Subject-Specific Context โ€“ Optional subject selection improves relevance.

๐Ÿ”ธ Bonus Features

  • โœ… Quizlet Export โ€“ Download in .txt format (tab-separated).
  • โœ… CSV Export โ€“ Download a .csv file of generated flashcards.
  • โœ… Robust JSON Parsing โ€“ Handles minor LLM output errors for stable performance.

๐Ÿ› ๏ธ Tech Stack

Layer Tools / Libraries
Language Python
UI Framework Streamlit
Model Zephyr-7B-ฮฒ via Hugging Face Inference API
Text Processing PyMuPDF (fitz)
Data Handling pandas
JSON Parsing demjson3
HTTP Requests requests

๐Ÿงฐ Setup and Installation

1. Clone the Repository

git clone https://github.com/Deepender25/FlashCard-Generator.git
cd FlashCard-Generator

2. Create and Activate Virtual Environment

For Unix/macOS:

python3 -m venv venv
source venv/bin/activate

For Windows:

python -m venv venv
venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Get Your Hugging Face API Token

  • Visit huggingface.co/settings/tokens and generate a User Access Token (with write permissions).
  • Youโ€™ll be prompted to paste this token into the Streamlit sidebar during app usage.

โ–ถ๏ธ How to Run

streamlit run app.py
  • Visit the local URL shown (usually http://localhost:8501) to access the app.

๐Ÿงช Sample Execution

๐Ÿ”น Input Text

Photosynthesis is a process used by plants, algae, and certain bacteria to convert light energy into chemical energy...

๐Ÿ”น Sample Flashcards (JSON)

[
  {
    "question": "What are the two stages of photosynthesis?",
    "answer": "The two stages are the light-dependent reactions and the light-independent reactions (Calvin cycle)."
  },
  {
    "question": "Where do the light-dependent reactions occur?",
    "answer": "They occur in the thylakoid membranes of chloroplasts."
  }
]

๐Ÿ”น Export Files

quizlet_import.txt

Where do the light-dependent reactions occur?    They occur in the thylakoid membranes of chloroplasts.

flashcards.csv

question,answer
Where do the light-dependent reactions occur?,They occur in the thylakoid membranes of chloroplasts.

๐Ÿง  Design Decisions & Prompt Engineering

๐Ÿ”ธ Why Zephyr-7B-ฮฒ?

  • Instruction-tuned for Q&A tasks
  • Efficient and open-source
  • Easy integration with Hugging Face Inference API

๐Ÿ”ธ Prompt Engineering Strategy

Prompt used in llm_handler_hf.py:

prompt = f"""<|system|>
You are an expert flashcard creator. Your task is to generate exactly {num_cards} question-answer flashcards based on the provided text.
Your entire response MUST be a single, valid JSON list of objects. Each object must have a "question" key and an "answer" key.
Do not add any introduction, explanation, or any text outside of the main JSON list.
Your response must start with '[' and end with ']'.</s>
<|user|>
Generate flashcards for the following text on the subject of '{subject}':
---
{text}
---</s>
<|assistant|>
"""

๐Ÿ”ธ JSON Cleanup Handling

  • fix_json_format() strips out extra text or missing brackets.
  • Uses demjson3 for lenient parsing.
  • Robust error handling for API failures, timeouts, and decoding issues.

๐Ÿ“ Project Structure

.
โ”œโ”€โ”€ app.py              # Main Streamlit UI
โ”œโ”€โ”€ llm_handler_hf.py   # Hugging Face API & prompt logic
โ”œโ”€โ”€ requirements.txt    # Dependency list
โ”œโ”€โ”€ .gitignore          # Files to ignore in Git
โ”œโ”€โ”€ .env.example        # Example for API token handling
โ””โ”€โ”€ README.md           # You're reading it!

๐Ÿ”ฎ Future Work

  • ๐Ÿ“ Flashcard Editor โ€“ Let users edit flashcards before exporting.
  • ๐Ÿ“ฆ Anki Export โ€“ Add .apkg support via genanki.
  • ๐Ÿง  Topic Clustering โ€“ Group questions by sub-topic or difficulty.
  • ๐Ÿš€ Public Deployment โ€“ Host on Streamlit Cloud or Hugging Face Spaces.
  • ๐ŸŒ Multi-language Support โ€“ Generate flashcards in different languages.

๐Ÿ“„ License

This project is licensed under the MIT License.

About

AI Flashcard Generator ๐Ÿง ๐Ÿ“š Convert educational content into Q&A flashcards using LLMs (Zephyr-7B).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages