Crafty: Developer Documentation

Welcome developers! This comprehensive documentation guides you through integrating Crafty into your applications

API Reference

Work in Progress...

ReadMe

Installation

    conda create --name crafty python=3.11

    conda activate crafty

    pip install -r requirements.txt

install MacTex or TeX Live

    # e.g. on macOS or Linux

    brew install --cask mactex

install ffmpeg

    # e.g. on macOS or Linux

    brew install ffmpeg

Once installed, you can set the

IMAGEIO_FFMPEG_EXE

environment variable as indicated in your script. This variable points to the FFmpeg executable, which is typically

/usr/local/bin/ffmpeg

on macOS, but the provided script suggests a Homebrew-specific path under

/opt/homebrew/bin/ffmpeg

. Verify the correct path using:

    which ffmpeg

Then update the environment variable accordingly in your Python script or set it in your shell profile:

    export IMAGEIO_FFMPEG_EXE=$(which ffmpeg)

    os.environ["IMAGEIO_FFMPEG_EXE"] = "/opt/homebrew/bin/ffmpeg"

Install OpenLimit

The latest version of openlimit is not available on pypi, and the version on pypi doesn't compatible with Python 3.11+

If you need to install the latest version. Execute the following commands anywhere in your workspace to install openlimit.

    git clone https://github.com/shobrook/openlimit.git

    cd openlimit

    pip install .

Set OPENAI_API_KEY

    cd "<project_dir>"

    # Should replace sk-xxx to a real openai api key

    echo "OPENAI_API_KEY=sk-xxx" > .env

CLI Commands

Crafty provides 2 main commands:

create

and

step

Create

The

create

command is used to create a new course video from given topic. To use the

create

command, simply type:

    python Crafty/cli.py create --topic "I would like to learn about ..."

The

create

command has several optional parameters that can be used to customize the behavior of the command. Here's a brief description of each:

  • --temperature <float>

    : This parameter sets the temperature for the basic and advanced model. The default value is 0.

  • --creative_temperature <float>

    : This parameter sets the temperature for the creative model. The default value is 0.5.

  • --slides_template_file <str>

    : This parameter sets the temperature for the creative model. The default value is 0.5.

  • --slides_style <str>

    : This parameter specifies the style of the slides. It should only be used if a template file is not provided. The default value is ‘simple’.

  • --content_slide_pages <int>

    : This parameter sets the number of pages to generate for content slides. The default value is 30.

  • --parallel_processing

    : This flag indicates whether to use parallel processing in the generation. It does not require a value. If used, it sets the value to True.

  • --advanced_model

    : This flag indicates whether to use the advanced model for note expansion. It does not require a value. If used, it sets the value to True.

  • --sections_per_chapter <int>

    : This parameter sets the number of sections per chapter. The default value is 20.

  • --max_note_expansion_words <int>

    : This parameter sets the maximum number of words for note expansion. The default value is 500.

These parameters can be used as follows:

    python Crafty/cli.py create --topic <topic> --temperature <float> --creative_temperature <float> --slides_template_file...

Replace

<topic>

,

<float>

,

<str>

, and

<int>

with the actual values you want to use. If you want to use the

--parallel_processing

or

--advanced_model

flags, simply include them in the command without a value.

Step

The

step

command is used to execute a specific step in the course creation process. The steps should be executed in the following order:

  1. chapter

  2. section

  3. note

  4. slide

  5. script

  6. voice

  7. video

Here's how to use each step:

Chapter

You should always start with chapter command to create meta data and chapters for a given learning topic.

    python Crafty/cli.py step chapter --topic <topic>

After the first step, each step will prompt you the next step to execute in the console. Please follow the instructions to continue.

Section

Start from second step, you are going to provide the course_id instead of topic to continue using existing materials.

    python Crafty/cli.py step section --course_id <course_id> --sections_per_chapter 20

--sections_per_chapter

is the number of sections you want to create for each chapter. The default value is 20.

Note

To generate notes for the sections of a course, use the

note

step. Starting from notes step, you must use

--chapter

to specify which chapter you want to generate.

    python Crafty/cli.py step note --course_id <course_id> --max_note_expansion_words 500 --chapter 0

--max_note_expansion_words

is the maximum number of words to expand the notes. The default value is 500.


--chapter

is the chapter index to generate notes for. The chapter number start from 0.

Here

is an example of notes generation for a course with 3 chapters

Slide

To create slides for the notes of a course, use the

slide

step.

    python Crafty/cli.py step slide --course_id <course_id> --slides_template_file 3 --content_slide_pages 30 --chapter 0

--slides_template_file

is the template file to use for generating slides. The default value is 3.


--content_slide_pages

is the number of pages to generate for content slides. The default value is 30.

Script

To create scripts for the slides of a course, use the

script

step.

    python Crafty/cli.py step script --course_id <course_id> --chapter 0

Voice

To generate voice for reading the scripts of a course, use the

voice

step.

    python Crafty/cli.py step voice --course_id <course_id> --chapter 0

Video

Finally, to create videos from the voices and slides of a course, use the

video

step.

    python Crafty/cli.py step video --course_id <course_id> --chapter 0

Time Consuming and Cost

At present, the total time required to generate a script for a chapter video using GPT4 is about 30-40 minutes, and the total time required to generate a script using GPT3.5 is about 10-15 minutes. Among them, the latex generation of ppt takes 2-3 minutes, the script generation of GPT3.5 takes 1-2 minutes, the script generation of GPT4 takes 15-20 minutes, and the voice generation of a 5-6 minute video takes 1-2 minutes. Video synthesis and processing are greatly affected by computer performance and video length, and it is roughly estimated to be about 10-20 minutes. In terms of cost, if GPT4 is used throughout the process to pursue quality, the final video of 16-17 minutes will cost 1.1-1.2 dollars. If GPT3.5 is used for script generation, the video length will be shortened to 5-6 minutes, and the cost will drop to 40-50 cents. If the image generation link is removed, the cost will drop to 30-35 cents. If the voice generation link is removed, the cost will drop to 10-20 cents (mainly from GPT generating slides).

.