This project is a web-based application built with Streamlit that leverages Hugging Face's Large Language Models (LLMs) to automatically generate question-answer flashcards from provided text or PDF documents. It's designed to assist students and educators in creating study materials quickly and efficiently.
- Flexible Input: Upload PDF files or plain text documents, or paste content directly into the application.
- AI-Powered Q&A Generation: Utilizes a T5-based model for question generation and a DistilBERT model for extractive question answering to create relevant flashcards.
- Customizable Output: Specify the desired number of flashcards to generate.
- Visually Appealing Interface: Interactive flashcards displayed in a grid with dynamic color schemes.
- Difficulty Indication: Each flashcard features a diagonally tilted strip in the top-right corner indicating a simulated difficulty level (Easy, Medium, Hard) with distinct colors.
- Export Functionality: Download generated flashcards as a CSV file for offline use or integration with other tools.
- Local Execution: Runs entirely locally, leveraging your machine's resources (CPU or GPU).
Follow these steps to set up and run the Flashcard Generator on your local machine.
- Python 3.8+
pip
(Python package installer)
-
Clone the repository:
git clone [https://github.com/ShubhamKukreti07/Flashcard-Generator.git](https://github.com/ShubhamKukreti07/Flashcard-Generator.git) cd Flashcard-Generator
-
Create a virtual environment (recommended):
python -m venv venv
-
Activate the virtual environment:
- On Windows:
.\venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install the required dependencies:
pip install -r requirements.txt
This will install Streamlit, PyPDF2, Transformers, PyTorch, and SentencePiece.
Once the setup is complete, you can run the Streamlit application.
-
Start the Streamlit application: Ensure your virtual environment is active.
streamlit run app.py
This command will open the application in your default web browser (usually at
http://localhost:8501
). -
Interact with the application:
- Choose Input Method: Select either "Upload File" to upload a PDF or
.txt
document, or "Paste Text" to directly input your content. - Adjust Number of Flashcards: Use the slider to specify how many flashcards you want to generate.
- Generate Flashcards: Click the "Generate Flashcards " button. The application will process your content and display the generated Q&A pairs.
- Review Difficulty: Observe the colored strips on each flashcard indicating its simulated difficulty.
- White Strip: Easy Question
- Yellow Strip: Medium Question
- Black Strip: Hard Question (Note: Difficulty is currently simulated for demonstration purposes.)
- Export: Use the "Download Flashcards as CSV ⬇" button to save your generated flashcards.
- Choose Input Method: Select either "Upload File" to upload a PDF or
Flashcard-Generator
- app.py : Main Streamlit application file
- llm_model.py : Contains the QAGenerator class for LLM interactions
- requirements.txt : Lists all Python dependencies
- utils.py : Utility functions for text extraction and preprocessing
- README.md : This README file
- Streamlit: For building the interactive web application.
- Hugging Face Transformers: For leveraging pre-trained LLMs for Question Generation (
valhalla/t5-base-qg-hl
) and Question Answering (distilbert-base-uncased-distilled-squad
). - PyTorch: The underlying deep learning framework used by the models.
- PyPDF2: For extracting text from PDF documents.
- Pandas: For easy handling and export of data to CSV.