Giter Club home page Giter Club logo

bb31420 / ai-auto-video-generator Goto Github PK

View Code? Open in Web Editor NEW
128.0 6.0 29.0 69 KB

An AI-powered storytelling video generator that takes user input as a story prompt, generates a story using OpenAI's GPT-3, creates images using OpenAI's DALL-E, adds voiceover using ElevenLabs API, and combines the elements into a video.

License: GNU General Public License v3.0

Python 100.00%
ai artificial-intelligence dall-e editing-videos openai openai-api video voice

ai-auto-video-generator's Introduction

AI-Auto-Video-Generator

An AI-powered storytelling video generator that takes user input as a story prompt, generates a story using OpenAI's GPT-3, creates images using OpenAI's DALL-E, adds voiceover using ElevenLabs API, and combines the elements into a video.

Example 0 Example 1

To DO: New project can be found at https://github.com/BB31420/loveListLace

Getting Started

These instructions will help you set up the project on your local machine.

Prerequisites

  • Python 3.6 or higher
  • Pip (Python package manager)
  • FFmpeg (a command-line program for video processing)

Create Virtual Environment

This helps keep packages seperate to avoid conflicts. Use the venv when running the code and before installing the required packages. The code requires openai 0.28, which is specified in the requirements.txt.

  1. Navigate to the project directory with cd ls -la
  • Windows: python -m venv .venv then Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  • Linux: python3 -m venv .venv
  1. Activate the venv
  • Windows: venv\Scripts\Activate.ps1
  • Linux: source .venv/bin/activate
  1. Close venv when finished running main.py, it needs to be active to use the packages deactivate

Installation

  1. Clone the repository: git clone https://github.com/BB31420/AI-Auto-Video-Generator.git
  2. Navigate to the project directory: cd AI-Auto-Video-Generator
  3. Install the required Python packages: pip install -r requirements.txt
  4. Install FFmpeg:
  • On macOS, you can use Homebrew: brew install ffmpeg
  • On Linux, you can use your package manager (e.g., apt-get install ffmpeg on Ubuntu)
  • On Windows, you can download an installer from the official FFmpeg website
  1. Install spacy: python -m spacy download en_core_web_sm

Usage

  1. Edit the file named .env in the project directory and add your API keys:

OPENAI_API_KEY=your_openai_api_key

ELEVENLABS_API_KEY=your_elevenlabs_api_key

  • Replace your_openai_api_key and your_elevenlabs_api_key with your actual API keys.
  1. Edit the file named caption_generator.py with your desired font path, specify the directory and font name.
    • Linux fonts can be found at: "/usr/share/fonts"
    • Windows fonts can be found at: C:\Windows\Fonts
  2. Run the autovideo.py script by navigating to the directory the script and .env file are saved. Output will be generated in the same folder:
  • Windows: python main.py
  • Linux: 'python3 main.py'
  1. Follow the prompts to enter a story prompt and generate a video.

Troubleshooting

Instructable: Modifying the Code for Haikus and Bee Facts

This instructable will guide you through modifying the provided code to focus on generating haikus and fact-based videos about bees. We'll cover changing the prompt, the models, text overlay, and background color and positioning.

  1. Example prompts
  • For haikus, enter a prompt related to haikus:
Create a haiku about nature
  • For bee facts, use a prompt related to bees:
Tell me 5 interesting facts about bees
  1. Changing the models

To change the model, replace the engine parameter in the openai.Completion.create() function. For example, use the text-curie-002 model:

response = openai.Completion.create(
    engine="text-curie-002",
    prompt=prompt,
    max_tokens=400,
    n=1,
    stop=None,
    temperature=0.7,
)
  1. Changing the duration of each image
  • To change the duration of each image, modify the set_duration() parameter in the create_video() function. For example, set the duration to 5 seconds per image:
image_clips = [mpy.ImageClip(img).set_duration(5) for img in image_filenames]

4 . Changing the number of images

  • To change the number of images, update the num_prompts parameter in the extract_image_prompts() function. For example, to generate 6 images, change the function call as follows:
def extract_image_prompts(story, num_prompts=5):
  1. Changing the voice used for the voiceover
  • To change the voice for the voiceover, modify the generate_voiceover() function. Update the URL used in the requests.post() call with the desired voice ID. For example, to use a different voice, replace the existing voice ID with a new one (e.g., "21m00Tcm4TlvDq8ikWAM", "yoZ06aMxZJJ28mfd3POQ", or "AZnzlk1XvdvUeBnXmlld"):
response = requests.post("https://api.elevenlabs.io/v1/text-to-speech/NEW_VOICE_ID", headers=headers, json=data)

Now, you can modify the code based on the provided instructions to generate haikus or fact-based videos about bees, with the desired duration for each image, the number of images, and the voice used for the voiceover. Remember to customize the prompts, models, text overlay, background color and positioning, image duration, image count, and voiceover based on your requirements.

Additionally, be mindful of the token limits for your API usage, as exceeding these limits may result in additional charges. You can adjust the max_tokens parameter in the openai.Completion.create() function to control the length of the generated text. Consider setting a lower value to stay within your API limits, especially when generating longer stories or facts.

ai-auto-video-generator's People

Contributors

bb31420 avatar dependabot[bot] avatar max-glass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ai-auto-video-generator's Issues

OpenAI doesnt generate images.

image_generator.py", line 13, in generate_images
response = openai.Image.create(
AttributeError: module 'openai' has no attribute 'Image'

Traceback (most recent call last)

Hello there, i get this error when i write prompt

Traceback (most recent call last): File "C:\ai\AI-Auto-Video-Generator\main.py", line 42, in <module> main() File "C:\ai\AI-Auto-Video-Generator\main.py", line 14, in main story, final_story_prompt = generate_story(story_prompt) # Update the assignment to get the final_story_prompt File "C:\ai\AI-Auto-Video-Generator\story_generator.py", line 12, in generate_story response = openai.Completion.create( File "C:\Users\mero\AppData\Local\Programs\Python\Python310\lib\site-packages\openai\api_resources\completion.py", line 25, in create return super().create(*args, **kwargs) File "C:\Users\mero\AppData\Local\Programs\Python\Python310\lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create response, _, api_key = requestor.request( File "C:\Users\mero\AppData\Local\Programs\Python\Python310\lib\site-packages\openai\api_requestor.py", line 230, in request resp, got_stream = self._interpret_response(result, stream) File "C:\Users\mero\AppData\Local\Programs\Python\Python310\lib\site-packages\openai\api_requestor.py", line 624, in _interpret_response self._interpret_response_line( File "C:\Users\mero\AppData\Local\Programs\Python\Python310\lib\site-packages\openai\api_requestor.py", line 687, in _interpret_response_line raise self.handle_error_response( openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.

i have credit open ai and elevenlabs

How can we create captions?

I managed to make this amazing script work with DALLE-3, but now I want to know how can I add captions to the videos?
I saw some functions in the documentation for the font, but I'm not sure where they should go.
Any help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.