Educreate

By Highlight User
4 Users

Course Creator agent through PDF

Prompt

import re
import pypdf2

def create_course_from_pdf(pdf_path):
    pdf_reader = pypdf2.PdfReader(pdf_path)
    text = ""
    for page in pdf_reader.pages:
        text += page.extract_text()

    # Extract the course title
    course_title_match = re.search(r"REDEMPTION\s+MANUAL\s+4\.5\s+EDITION", text)
    course_title = course_title_match.group(0) if course_title_match else "Course Title"

    # Identify sections
    section_titles = re.findall(r"Section\s+\d+[\w\W]+?\n(.*?)\n", text)
    sections = []
    for section_title in section_titles:
        section = {"title": section_title, "lessons": []}

        # Identify lessons within the section
        lesson_titles = re.findall(
            rf"{section_title}\n(.*?)\n", text, re.IGNORECASE
        )
        for lesson_title in lesson_titles:
            lesson_content = re.search(
                rf"{lesson_title}\n(.*?)(?=(?:\n\n)|$)", text, re.IGNORECASE | re.DOTALL
            ).group(1)
            lesson = {"title": lesson_title, "content": lesson_content}
            section["lessons"].append(lesson)

        sections.append(section)

    course = {"title": course_title, "sections": sections}
    return course

# Example usage (replace with your PDF path)
course_data = create_course_from_pdf("r6ZrvxxcQ5ymhxcNmhzN_REDEMPTION MANUAL 4.5 PDF-1.pdf")
print(course_data)


How it works