Skip to content

Conversation

rixitgithub
Copy link

Integrate spaCy NLP for concise study notes with dynamic note cards and pdf export

Overview

This PR introduces a new feature to EduAid that lets users generate concise study notes from their input text, edit those notes on the fly, and download them as a PDF. The feature combines advanced NLP summarization on the backend with a polished, interactive React component on the frontend, positioning EduAid as a complete, user-friendly study platform.

What’s New

  • Short Notes Generation: A new /summarize Flask endpoint processes input text using spaCy to generate a set of concise note cards.
  • Dynamic Note Cards: Each note card contains a header (extracted noun chunk) and a corresponding point (the sentence itself) based on the ranked importance.
  • Editing Capability: Users can easily edit generated notes within the StudyNotes React component.
  • PDF Download: Integrated pdf-lib to allow users to download their study notes as a well-formatted PDF, complete with embedded logo, title, and wrapped text.
  • Improved Error Handling: Enhanced error management on the backend to gracefully handle missing input and unexpected errors.

Backend (Flask API)

Endpoint Setup

  • Route: /summarize (POST)
  • Input: JSON payload with key input_text
  • Error Handling: Returns a 400 error if input is missing; uses try-except blocks to catch and log exceptions.

Text Processing and Summarization

  • Utilizes the spaCy en_core_web_sm model to:
    • Calculate word frequencies (excluding stop words and punctuation)
    • Score sentences based on summed word frequencies
    • Rank sentences and extract them without a fixed cap on the number of cards

Note Card Generation

  • Dynamically creates note cards:
    • Header: Extracted from the first meaningful noun chunk (or a fallback verb/noun, defaulting to "Note")
    • Point: Contains the original sentence, prefixed with a dash for clarity
  • Response Format:
{
  "notes": [
    {"header": "Colonies", "points": ["- The original Thirteen Colonies were administered by Great Britain."]},
    {"header": "Population", "points": ["- The population grew rapidly."]},
    {"header": "Purchase", "points": ["- The Louisiana Purchase doubled the territory."]}
  ]
}

Frontend (React Component - StudyNotes.jsx)

Component Functionality

  • Display: Renders note cards styled with Tailwind CSS in a dark-themed UI. Each card shows the header and a clean list of points.
  • Editing:
    • An "Edit" button toggles edit mode for each card.
    • Users can update the header and individual points.
    • "Save" updates the localStorage and state; "Cancel" reverts changes.
  • PDF Generation:
    • Uses pdf-lib to create an A4 PDF with:
      • An embedded logo (PNG byte array)
      • A title ("EduAid Study Notes")
      • Text wrapping to avoid WinAnsi encoding issues (newlines are stripped)
    • Triggers a download of the PDF file named study_notes.pdf.
  • Navigation: Provides buttons for "Download as PDF," "Back to Input," and "Go to Quiz," ensuring a smooth user workflow.

Bug Fixes Implemented

  • PDF Newline Error: Text is cleaned using a replace function (e.g., .replace(/[\n\r]+/g, " ")) to prevent WinAnsi encoding errors.
  • Card Length Adjustment: Backend logic now ensures each card has one concise point, keeping the content readable.

Demo Video

Watch the demo video to see the feature in action:

add_notes.mp4

Screenshot Table

Screenshot Description Image
Note Cards Display Screenshot 2025-04-07 201355
PDF Preview Screenshot 2025-04-07 201432

Workflow

  1. Input Stage: The user enters text on the main page.
  2. Summarization: The text is sent to the /summarize endpoint, which returns structured note cards.
  3. Editing & Storage: The StudyNotes component displays these cards, allows editing, and saves changes to localStorage.
  4. PDF Download: Users can download the final notes as a PDF, ensuring a shareable and printable format.

Conclusion

This feature significantly enhances the EduAid platform by offering an intuitive way to condense long texts into manageable, editable study notes with a seamless download option. It is a high-value addition that enriches the student learning experience while maintaining a polished and robust design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant