diff --git a/.database/template_asset_db.json b/.database/template_asset_db.json
new file mode 100644
index 0000000000000000000000000000000000000000..65cb47a669739e4f502fd6af8292dc096ae331d1
--- /dev/null
+++ b/.database/template_asset_db.json
@@ -0,0 +1,47 @@
+{
+ "asset_collection": {
+ "1": {
+ "_id": "local_assets",
+ "white_reddit_template": {
+ "path": "public/white_reddit_template.png",
+ "type": "image",
+ "ts": "2023-07-03 19:41:55",
+ "required": true
+ },
+ "subscribe-animation": {
+ "path": "public/subscribe-animation.mp4",
+ "type": "video",
+ "ts": "2023-07-03 21:37:53",
+ "required": true
+ }
+ },
+ "2": {
+ "_id": "remote_assets",
+ "Music joakim karud dreams": {
+ "type": "background music",
+ "url": "https://www.youtube.com/watch?v=p56gqDhUYbU",
+ "ts": "2023-07-05 04:35:03"
+ },
+ "Music dj quads": {
+ "type": "background music",
+ "url": "https://www.youtube.com/watch?v=uUu1NcSHg2E",
+ "ts": "2023-07-05 05:03:44"
+ },
+ "Car race gameplay": {
+ "type": "background video",
+ "url": "https://www.youtube.com/watch?v=gBsJA8tCeyc",
+ "ts": "2023-07-04 23:07:44"
+ },
+ "Minecraft jumping circuit": {
+ "url": "https://www.youtube.com/watch?v=Pt5_GSKIWQM",
+ "type": "background video",
+ "ts": "2023-07-07 04:13:36"
+ },
+ "Ski gameplay": {
+ "url": "https://www.youtube.com/watch?v=8ao1NAOVKTU",
+ "type": "background video",
+ "ts": "2023-07-07 04:54:16"
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/.gitattributes b/.gitattributes
index a6344aac8c09253b3b630fb776ae94478aa0275b..161e1f3607497571a037166c4a8e5eae42d55725 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,35 +1,36 @@
-*.7z filter=lfs diff=lfs merge=lfs -text
-*.arrow filter=lfs diff=lfs merge=lfs -text
-*.bin filter=lfs diff=lfs merge=lfs -text
-*.bz2 filter=lfs diff=lfs merge=lfs -text
-*.ckpt filter=lfs diff=lfs merge=lfs -text
-*.ftz filter=lfs diff=lfs merge=lfs -text
-*.gz filter=lfs diff=lfs merge=lfs -text
-*.h5 filter=lfs diff=lfs merge=lfs -text
-*.joblib filter=lfs diff=lfs merge=lfs -text
-*.lfs.* filter=lfs diff=lfs merge=lfs -text
-*.mlmodel filter=lfs diff=lfs merge=lfs -text
-*.model filter=lfs diff=lfs merge=lfs -text
-*.msgpack filter=lfs diff=lfs merge=lfs -text
-*.npy filter=lfs diff=lfs merge=lfs -text
-*.npz filter=lfs diff=lfs merge=lfs -text
-*.onnx filter=lfs diff=lfs merge=lfs -text
-*.ot filter=lfs diff=lfs merge=lfs -text
-*.parquet filter=lfs diff=lfs merge=lfs -text
-*.pb filter=lfs diff=lfs merge=lfs -text
-*.pickle filter=lfs diff=lfs merge=lfs -text
-*.pkl filter=lfs diff=lfs merge=lfs -text
-*.pt filter=lfs diff=lfs merge=lfs -text
-*.pth filter=lfs diff=lfs merge=lfs -text
-*.rar filter=lfs diff=lfs merge=lfs -text
-*.safetensors filter=lfs diff=lfs merge=lfs -text
-saved_model/**/* filter=lfs diff=lfs merge=lfs -text
-*.tar.* filter=lfs diff=lfs merge=lfs -text
-*.tar filter=lfs diff=lfs merge=lfs -text
-*.tflite filter=lfs diff=lfs merge=lfs -text
-*.tgz filter=lfs diff=lfs merge=lfs -text
-*.wasm filter=lfs diff=lfs merge=lfs -text
-*.xz filter=lfs diff=lfs merge=lfs -text
-*.zip filter=lfs diff=lfs merge=lfs -text
-*.zst filter=lfs diff=lfs merge=lfs -text
-*tfevents* filter=lfs diff=lfs merge=lfs -text
+*.7z filter=lfs diff=lfs merge=lfs -text
+*.arrow filter=lfs diff=lfs merge=lfs -text
+*.bin filter=lfs diff=lfs merge=lfs -text
+*.bz2 filter=lfs diff=lfs merge=lfs -text
+*.ckpt filter=lfs diff=lfs merge=lfs -text
+*.ftz filter=lfs diff=lfs merge=lfs -text
+*.gz filter=lfs diff=lfs merge=lfs -text
+*.h5 filter=lfs diff=lfs merge=lfs -text
+*.joblib filter=lfs diff=lfs merge=lfs -text
+*.lfs.* filter=lfs diff=lfs merge=lfs -text
+*.mlmodel filter=lfs diff=lfs merge=lfs -text
+*.model filter=lfs diff=lfs merge=lfs -text
+*.msgpack filter=lfs diff=lfs merge=lfs -text
+*.npy filter=lfs diff=lfs merge=lfs -text
+*.npz filter=lfs diff=lfs merge=lfs -text
+*.onnx filter=lfs diff=lfs merge=lfs -text
+*.ot filter=lfs diff=lfs merge=lfs -text
+*.parquet filter=lfs diff=lfs merge=lfs -text
+*.pb filter=lfs diff=lfs merge=lfs -text
+*.pickle filter=lfs diff=lfs merge=lfs -text
+*.pkl filter=lfs diff=lfs merge=lfs -text
+*.pt filter=lfs diff=lfs merge=lfs -text
+*.pth filter=lfs diff=lfs merge=lfs -text
+*.rar filter=lfs diff=lfs merge=lfs -text
+*.safetensors filter=lfs diff=lfs merge=lfs -text
+saved_model/**/* filter=lfs diff=lfs merge=lfs -text
+*.tar.* filter=lfs diff=lfs merge=lfs -text
+*.tar filter=lfs diff=lfs merge=lfs -text
+*.tflite filter=lfs diff=lfs merge=lfs -text
+*.tgz filter=lfs diff=lfs merge=lfs -text
+*.wasm filter=lfs diff=lfs merge=lfs -text
+*.xz filter=lfs diff=lfs merge=lfs -text
+*.zip filter=lfs diff=lfs merge=lfs -text
+*.zst filter=lfs diff=lfs merge=lfs -text
+*tfevents* filter=lfs diff=lfs merge=lfs -text
+public/subscribe-animation.mp4 filter=lfs diff=lfs merge=lfs -text
diff --git a/.github/CHANGE_LOG.md b/.github/CHANGE_LOG.md
new file mode 100644
index 0000000000000000000000000000000000000000..f7d290b9301a867916a0ac839cf93aa668a8510f
--- /dev/null
+++ b/.github/CHANGE_LOG.md
@@ -0,0 +1,34 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+## [Unreleased]
+
+
+
+Upcoming changes.
+
+### Added
+
+### Changed
+
+### Removed
+
+## [0.0.1] - YYYY-MM-DD
+
+Initial Release.
+
+### Added
+
+- What was added.
+
+
+
+[Unreleased]: /
+[0.0.1]: /v0.0.1
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 0000000000000000000000000000000000000000..764cb4b21daad996dc7572ee4135e14965542b4e
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,6 @@
+# These owners will be the default owners for everything in
+# the repo. Unless a later match takes precedence,
+# @USER will be requested for
+# review when someone opens a pull request.
+# if you want to add more owners just write it after the demo user @DemoUser
+* @RayVentura
diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000000000000000000000000000000000000..41dd9ebee5f0bf8835f1a46ba9c429eebe9693ef
--- /dev/null
+++ b/.github/CODE_OF_CONDUCT.md
@@ -0,0 +1,127 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+We as members, contributors, and leaders pledge to make participation in our
+community a harassment-free experience for everyone, regardless of age, body
+size, visible or invisible disability, ethnicity, sex characteristics, gender
+identity and expression, level of experience, education, socio-economic status,
+nationality, personal appearance, race, religion, or sexual identity
+and orientation.
+
+We pledge to act and interact in ways that contribute to an open, welcoming,
+diverse, inclusive, and healthy community.
+
+## Our Standards
+
+Examples of behavior that contributes to a positive environment for our
+community include:
+
+* Demonstrating empathy and kindness toward other people
+* Being respectful of differing opinions, viewpoints, and experiences
+* Giving and gracefully accepting constructive feedback
+* Accepting responsibility and apologizing to those affected by our mistakes,
+ and learning from the experience
+* Focusing on what is best not just for us as individuals, but for the
+ overall community
+
+Examples of unacceptable behavior include:
+
+* The use of sexualized language or imagery, and sexual attention or
+ advances of any kind
+* Trolling, insulting or derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or email
+ address, without their explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+## Enforcement Responsibilities
+
+Community leaders are responsible for clarifying and enforcing our standards of
+acceptable behavior and will take appropriate and fair corrective action in
+response to any behavior that they deem inappropriate, threatening, offensive,
+or harmful.
+
+Community leaders have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are
+not aligned to this Code of Conduct, and will communicate reasons for moderation
+decisions when appropriate.
+
+## Scope
+
+This Code of Conduct applies within all community spaces, and also applies when
+an individual is officially representing the community in public spaces.
+Examples of representing our community include using an official e-mail address,
+posting via an official social media account, or acting as an appointed
+representative at an online or offline event.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported to the community leaders responsible for enforcement.
+All complaints will be reviewed and investigated promptly and fairly.
+
+All community leaders are obligated to respect the privacy and security of the
+reporter of any incident.
+
+## Enforcement Guidelines
+
+Community leaders will follow these Community Impact Guidelines in determining
+the consequences for any action they deem in violation of this Code of Conduct:
+
+### 1. Correction
+
+**Community Impact**: Use of inappropriate language or other behavior deemed
+unprofessional or unwelcome in the community.
+
+**Consequence**: A private, written warning from community leaders, providing
+clarity around the nature of the violation and an explanation of why the
+behavior was inappropriate. A public apology may be requested.
+
+### 2. Warning
+
+**Community Impact**: A violation through a single incident or series
+of actions.
+
+**Consequence**: A warning with consequences for continued behavior. No
+interaction with the people involved, including unsolicited interaction with
+those enforcing the Code of Conduct, for a specified period of time. This
+includes avoiding interactions in community spaces as well as external channels
+like social media. Violating these terms may lead to a temporary or
+permanent ban.
+
+### 3. Temporary Ban
+
+**Community Impact**: A serious violation of community standards, including
+sustained inappropriate behavior.
+
+**Consequence**: A temporary ban from any sort of interaction or public
+communication with the community for a specified period of time. No public or
+private interaction with the people involved, including unsolicited interaction
+with those enforcing the Code of Conduct, is allowed during this period.
+Violating these terms may lead to a permanent ban.
+
+### 4. Permanent Ban
+
+**Community Impact**: Demonstrating a pattern of violation of community
+standards, including sustained inappropriate behavior, harassment of an
+individual, or aggression toward or disparagement of classes of individuals.
+
+**Consequence**: A permanent ban from any sort of public interaction within
+the community.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage],
+version 2.0, available at
+https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
+
+Community Impact Guidelines were inspired by [Mozilla's code of conduct
+enforcement ladder](https://github.com/mozilla/diversity).
+
+[homepage]: https://www.contributor-covenant.org
+
+For answers to common questions about this code of conduct, see the FAQ at
+https://www.contributor-covenant.org/faq. Translations are available at
+https://www.contributor-covenant.org/translations.
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
new file mode 100644
index 0000000000000000000000000000000000000000..c7d8cb08601d59626c957e1cd2635b650a3c22cb
--- /dev/null
+++ b/.github/CONTRIBUTING.md
@@ -0,0 +1,21 @@
+๐๐ป๐
+
+## Contributing
+
+There are many exciting ways to contribute to ShortGPT, our AI automated content creation framework. ๐
+
+See below for everything you can do and the processes to follow for each contribution method. Note that no matter how you contribute, your participation is governed by our โจ[Code of Conduct](CODE_OF_CONDUCT.md)โจ.
+
+## ๐ ๏ธ Make changes to the code or docs
+
+- ๐ด Fork the project,
+- ๐ก make your changes,
+- ๐ and send a pull request! ๐
+
+Make sure you read and follow the instructions in the [pull request template](pull_request_template.md). And note that all participation in this project (including code submissions) is governed by our โจ[Code of Conduct](CODE_OF_CONDUCT.md)โจ.
+
+## ๐๐ Submit bug reports or feature requests
+
+Just use the GitHub issue tracker to submit your bug reports and feature requests. We appreciate your feedback! ๐๐ง
+
+Let's make ShortGPT even better together! ๐โค๏ธ
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..e8413309f90de60ff9d5cbc3618c5128579378d7
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yaml
@@ -0,0 +1,99 @@
+name: ๐ Bug Report
+description: File a bug report
+title: '๐ [Bug]: '
+labels: ['bug']
+
+body:
+ - type: markdown
+ attributes:
+ value: |
+ Thanks for taking the time to fill out this bug report!
+
+ - type: textarea
+ id: what-happened
+ attributes:
+ label: What happened?
+ description: Describe the issue here.
+ placeholder: Tell us what you see!
+ validations:
+ required: true
+
+ - type: dropdown
+ id: browsers
+ attributes:
+ label: What type of browser are you seeing the problem on?
+ multiple: true
+ options:
+ - Firefox
+ - Chrome
+ - Safari
+ - Microsoft Edge
+ validations:
+ required: true
+
+ - type: dropdown
+ id: operating-systems
+ attributes:
+ label: What type of Operating System are you seeing the problem on?
+ multiple: true
+ options:
+ - Linux
+ - Windows
+ - Mac
+ - Google Colab
+ - Other
+ validations:
+ required: true
+
+ - type: input
+ id: python-version
+ attributes:
+ label: Python Version
+ description: What version of Python are you using?
+ placeholder: e.g. Python 3.9.0
+ validations:
+ required: true
+
+ - type: input
+ id: application-version
+ attributes:
+ label: Application Version
+ description: What version of the application are you using?
+ placeholder: e.g. v1.2.3
+ validations:
+ required: true
+
+ - type: textarea
+ id: expected-behavior
+ attributes:
+ label: Expected Behavior
+ description: What did you expect to happen?
+ placeholder: What did you expect?
+ validations:
+ required: true
+
+ - type: textarea
+ id: error-message
+ attributes:
+ label: Error Message
+ description: What error message did you receive?
+ placeholder:
+ render: shell
+ validations:
+ required: false
+
+ - type: textarea
+ id: logs
+ attributes:
+ label: Code to produce this issue.
+ description: Please copy and paste any relevant code to re-produce this issue.
+ render: shell
+
+ - type: textarea
+ id: screenshots-assets
+ attributes:
+ label: Screenshots/Assets/Relevant links
+ description: If applicable, add screenshots, assets or any relevant links that can help understand the issue.
+ placeholder: Provide any relevant material here
+ validations:
+ required: false
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..fe657909ba96c5d0ed20db04a5541d2be61b4519
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.yaml
@@ -0,0 +1,36 @@
+name: โจ Feature request
+description: Suggest an feature / idea for this project
+title: 'โจ [Feature Request / Suggestion]: '
+labels: ['feature']
+body:
+ - type: markdown
+ attributes:
+ value: |
+ We appreciate your feedback on how to improve this project. Please be sure to include as much details & any resources if possible!
+
+ - type: textarea
+ id: Suggestion
+ attributes:
+ label: Suggestion / Feature Request
+ description: Describe the feature(s) you would like to see added.
+ placeholder: Tell us your suggestion
+ validations:
+ required: true
+
+ - type: textarea
+ id: why-usage
+ attributes:
+ label: Why would this be useful?
+ description: Describe why this feature would be useful.
+ placeholder: Tell us why this would be useful to have this feature
+ validations:
+ required: false
+
+ - type: textarea
+ id: screenshots-assets
+ attributes:
+ label: Screenshots/Assets/Relevant links
+ description: If applicable, add screenshots, assets or any relevant links that can help understand the issue.
+ placeholder: Provide any relevant material here
+ validations:
+ required: false
diff --git a/.github/ISSUE_TEMPLATE/question.yaml b/.github/ISSUE_TEMPLATE/question.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..4a9e200746bf94c7c567118b361f21ebea3b466f
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/question.yaml
@@ -0,0 +1,17 @@
+name: โ Question
+description: Ask a question about this project
+title: 'โ [Question]: '
+labels: ['question']
+body:
+ - type: markdown
+ attributes:
+ value: |
+ We appreciate your interest in this project. Please be sure to include as much detail & context about your question as possible!
+
+ - type: textarea
+ id: Question
+ attributes:
+ label: Your Question
+ description: Describe your question in detail.
+ validations:
+ required: true
diff --git a/.github/SECURITY.md b/.github/SECURITY.md
new file mode 100644
index 0000000000000000000000000000000000000000..65963721b3c314a2d30eef9d95272c123d10f05c
--- /dev/null
+++ b/.github/SECURITY.md
@@ -0,0 +1,28 @@
+# Security Policy
+
+## Supported Versions
+
+| Version | Supported |
+| ------- | ------------------ |
+| 0.0.x | :x: |
+
+## ๐๏ธ Reporting a Vulnerability
+
+If you have identified a security vulnerability in system or product please `RayVentura` with your findings. We strongly recommend using our `PGP key` to prevent this information from falling into the wrong hands.
+
+### Disclosure Policy
+
+Upon receipt of a security report the following steps will be taken:
+
+- Acknowledge your report within 48 hours, and provide a further more detailed update within 48 hours.
+- Confirm the problem and determine the affected versions
+- Keep you informed of the progress towards resolving the problem and notify you when the vulnerability has been fixed.
+- Audit code to find any potential similar problems.
+- Prepare fixes for all releases still under maintenance. These fixes will be released as fast as possible.
+- Handle your report with strict confidentiality, and not pass on your personal details to third parties without your permission.
+
+Whilst the issue is under investigation
+
+- **Do** provide as much information as possible.
+- **Do not** exploit of the vulnerability or problem you have discovered.
+- **Do not** reveal the problem to others until it has been resolved.
diff --git a/.github/config.yml b/.github/config.yml
new file mode 100644
index 0000000000000000000000000000000000000000..85ffb1fa4c7dfe18eec56195c2a81547f7d7ce1a
--- /dev/null
+++ b/.github/config.yml
@@ -0,0 +1,21 @@
+# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome
+
+# Comment to be posted to on first time issues
+newIssueWelcomeComment: >
+ Thanks for opening your first issue! Reports like these help improve the project!
+
+# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
+
+# Comment to be posted to on PRs from first time contributors in your repository
+newPRWelcomeComment: >
+ Thanks for opening this pull request!
+
+# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
+
+# Comment to be posted to on pull requests merged by a first time user
+firstPRMergeComment: >
+ Congrats on merging your first pull request!
+
+# The keyword to find for Todo Bot issue
+todo:
+ keyword: '@todo'
diff --git a/.github/issue_label_bot.yaml b/.github/issue_label_bot.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..b83d27f89823d3fed596a4df48a9e6505baa5f83
--- /dev/null
+++ b/.github/issue_label_bot.yaml
@@ -0,0 +1,4 @@
+label-alias:
+ bug: 'Type: Bug'
+ feature_request: 'Type: Feature'
+ question: 'Type: Question'
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000000000000000000000000000000000000..6215721d4d2237599677f9e1d6049982c8fb8eef
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,30 @@
+## Proposed changes
+
+Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. ๐๐ง
+
+## Types of changes
+
+What types of changes does your code introduce to this project?
+_Put an `x` in the boxes that apply_ ๐๐
+
+- [ ] Bugfix (non-breaking change which fixes an issue) ๐
+- [ ] New feature (non-breaking change which adds functionality) โจ
+- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) ๐ฅ
+- [ ] Documentation Update (if none of the other choices apply) ๐
+
+## Checklist
+
+_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ โ
+
+- [ ] I have read the CONTRIBUTING.md ๐
+- [ ] I have added tests that prove my fix is effective or that my feature works โ โ๏ธ
+- [ ] I have added necessary documentation (if appropriate) ๐
+
+## Further comments
+
+If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... ๐กโ
+
+
+## References and related issues (e.g. #1234)
+
+N/A ๐
diff --git a/.github/settings.yml b/.github/settings.yml
new file mode 100644
index 0000000000000000000000000000000000000000..ee268bb0b6ad307bdc7c3dc7a9b9918845d64357
--- /dev/null
+++ b/.github/settings.yml
@@ -0,0 +1,190 @@
+repository:
+ # See https://developer.github.com/v3/repos/#edit for all available settings.
+
+ # The name of the repository. Changing this will rename the repository
+ #name: repo-name
+
+ # A short description of the repository that will show up on GitHub
+ #description: description of repo
+
+ # A URL with more information about the repository
+ #homepage: https://example.github.io/
+
+ # A comma-separated list of topics to set on the repository
+ #topics: project, template, project-template
+
+ # Either `true` to make the repository private, or `false` to make it public.
+ #private: false
+
+ # Either `true` to enable issues for this repository, `false` to disable them.
+ has_issues: true
+
+ # Either `true` to enable the wiki for this repository, `false` to disable it.
+ has_wiki: true
+
+ # Either `true` to enable downloads for this repository, `false` to disable them.
+ #has_downloads: true
+
+ # Updates the default branch for this repository.
+ default_branch: stable
+
+ # Either `true` to allow squash-merging pull requests, or `false` to prevent
+ # squash-merging.
+ #allow_squash_merge: true
+
+ # Either `true` to allow merging pull requests with a merge commit, or `false`
+ # to prevent merging pull requests with merge commits.
+ #allow_merge_commit: true
+
+ # Either `true` to allow rebase-merging pull requests, or `false` to prevent
+ # rebase-merging.
+ #allow_rebase_merge: true
+
+# Labels: define labels for Issues and Pull Requests
+labels:
+ - name: 'Type: Bug'
+ color: e80c0c
+ description: Something isn't working as expected.
+
+ - name: 'Type: Enhancement'
+ color: 54b2ff
+ description: Suggest an improvement for an existing feature.
+
+ - name: 'Type: Feature'
+ color: 54b2ff
+ description: Suggest a new feature.
+
+ - name: 'Type: Security'
+ color: fbff00
+ description: A problem or enhancement related to a security issue.
+
+ - name: 'Type: Question'
+ color: 9309ab
+ description: Request for information.
+
+ - name: 'Type: Test'
+ color: ce54e3
+ description: A problem or enhancement related to a test.
+
+ - name: 'Status: Awaiting Review'
+ color: 24d15d
+ description: Ready for review.
+
+ - name: 'Status: WIP'
+ color: 07b340
+ description: Currently being worked on.
+
+ - name: 'Status: Waiting'
+ color: 38C968
+ description: Waiting on something else to be ready.
+
+ - name: 'Status: Stale'
+ color: 66b38a
+ description: Has had no activity for some time.
+
+ - name: 'Duplicate'
+ color: EB862D
+ description: Duplicate of another issue.
+
+ - name: 'Invalid'
+ color: faef50
+ description: This issue doesn't seem right.
+
+ - name: 'Priority: High +'
+ color: ff008c
+ description: Task is considered higher-priority.
+
+ - name: 'Priority: Low -'
+ color: 690a34
+ description: Task is considered lower-priority.
+
+ - name: 'Documentation'
+ color: 2fbceb
+ description: An issue/change with the documentation.
+
+ - name: "Won't fix"
+ color: C8D9E6
+ description: Reported issue is working as intended.
+
+ - name: '3rd party issue'
+ color: e88707
+ description: This issue might be caused by a 3rd party script/package/other reasons
+
+ - name: 'Os: Windows'
+ color: AEB1C2
+ description: Is Windows-specific
+
+ - name: 'Os: Mac'
+ color: AEB1C2
+ description: Is Mac-specific
+
+ - name: 'Os: Linux'
+ color: AEB1C2
+ description: Is Linux-specific
+
+ - name: 'Os: Google Colab'
+ color: AEB1C2
+ description: Is Google Colab-specific
+#
+#
+# # Collaborators: give specific users access to this repository.
+# # See https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator for available options
+# collaborators:
+# # - username: bkeepers
+# # permission: push
+# # - username: hubot
+# # permission: pull
+
+# # Note: `permission` is only valid on organization-owned repositories.
+# # The permission to grant the collaborator. Can be one of:
+# # * `pull` - can pull, but not push to or administer this repository.
+# # * `push` - can pull and push, but not administer this repository.
+# # * `admin` - can pull, push and administer this repository.
+# # * `maintain` - Recommended for project managers who need to manage the repository without access to sensitive or destructive actions.
+# # * `triage` - Recommended for contributors who need to proactively manage issues and pull requests without write access.
+
+# # See https://developer.github.com/v3/teams/#add-or-update-team-repository for available options
+# teams:
+# - name: core
+# # The permission to grant the team. Can be one of:
+# # * `pull` - can pull, but not push to or administer this repository.
+# # * `push` - can pull and push, but not administer this repository.
+# # * `admin` - can pull, push and administer this repository.
+# # * `maintain` - Recommended for project managers who need to manage the repository without access to sensitive or destructive actions.
+# # * `triage` - Recommended for contributors who need to proactively manage issues and pull requests without write access.
+# permission: admin
+# - name: docs
+# permission: push
+
+# branches:
+# - name: master
+# # https://developer.github.com/v3/repos/branches/#update-branch-protection
+# # Branch Protection settings. Set to null to disable
+# protection:
+# # Required. Require at least one approving review on a pull request, before merging. Set to null to disable.
+# required_pull_request_reviews:
+# # The number of approvals required. (1-6)
+# required_approving_review_count: 1
+# # Dismiss approved reviews automatically when a new commit is pushed.
+# dismiss_stale_reviews: true
+# # Blocks merge until code owners have reviewed.
+# require_code_owner_reviews: true
+# # Specify which users and teams can dismiss pull request reviews. Pass an empty dismissal_restrictions object to disable. User and team dismissal_restrictions are only available for organization-owned repositories. Omit this parameter for personal repositories.
+# dismissal_restrictions:
+# users: []
+# teams: []
+# # Required. Require status checks to pass before merging. Set to null to disable
+# required_status_checks:
+# # Required. Require branches to be up to date before merging.
+# strict: true
+# # Required. The list of status checks to require in order to merge into this branch
+# contexts: []
+# # Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable.
+# enforce_admins: true
+# # Prevent merge commits from being pushed to matching branches
+# required_linear_history: true
+# # Required. Restrict who can push to this branch. Team and user restrictions are only available for organization-owned repositories. Set to null to disable.
+# restrictions:
+# apps: []
+# users: []
+# teams: []
diff --git a/.github/workflows/generate_release-changelog.yaml b/.github/workflows/generate_release-changelog.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..a2018aae85a037c44f156068578d74207bc4d7be
--- /dev/null
+++ b/.github/workflows/generate_release-changelog.yaml
@@ -0,0 +1,33 @@
+name: Create Release
+
+on:
+ push:
+ tags:
+ - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
+
+jobs:
+ build:
+ name: Create Release
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Changelog
+ uses: Bullrich/generate-release-changelog@master
+ id: Changelog
+ env:
+ REPO: ${{ github.repository }}
+ - name: Create Release
+ id: create_release
+ uses: actions/create-release@latest
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
+ with:
+ tag_name: ${{ github.ref }}
+ release_name: Release ${{ github.ref }}
+ body: |
+ ${{ steps.Changelog.outputs.changelog }}
+ draft: false
+ prerelease: false
diff --git a/.github/workflows/update_space.yml b/.github/workflows/update_space.yml
new file mode 100644
index 0000000000000000000000000000000000000000..adca9a32ebffde11876dff7010391ee8997c618f
--- /dev/null
+++ b/.github/workflows/update_space.yml
@@ -0,0 +1,28 @@
+name: Run Python script
+
+on:
+ push:
+ branches:
+ - main
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+
+ - name: Set up Python
+ uses: actions/setup-python@v2
+ with:
+ python-version: '3.9'
+
+ - name: Install Gradio
+ run: python -m pip install gradio
+
+ - name: Log in to Hugging Face
+ run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
+
+ - name: Deploy to Spaces
+ run: gradio deploy
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..0e80d4b21be9df217a3bbcecdf6feb671469f269
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,28 @@
+!*.py
+!*.json
+!*.yaml
+!*.template
+*.pyc
+**/__pycache__/
+test.py
+public/*
+!public/white_reddit_template.png
+!public/subscribe-animation.mp4
+z_doc/*
+z_other/*
+videos/*
+.logs/
+.editing_assets/*
+.database/api_db.json
+.database/content_db.json
+.database/asset_db.json
+flagged/
+.vscode
+.env
+ShortGPT.egg-info
+dist
+build
+setup
+test.ipynb
+.venv/
+MANIFEST.in
\ No newline at end of file
diff --git a/CHANGES.txt b/CHANGES.txt
new file mode 100644
index 0000000000000000000000000000000000000000..97c07f402a18d55106dbc16cfc73f62e810745ce
--- /dev/null
+++ b/CHANGES.txt
@@ -0,0 +1,14 @@
+# CHANGES
+
+## Version 0.1.2
+- Improving logs in content engines
+## Version 0.1.1
+- Adding AssetType in AssetDatabase
+- Adding ApiProvider in api_db
+- Fixing pip libary missing editing_framework module, prompt_template module
+## Version 0.1.0
+- Fixing the AssetDatabase when it's empty
+## Version 0.0.2
+- Implemented the content_translation_engine; a multilingual video dubbing content engine. The source can be found at shortGPT/engine/content_translation_engine.py.
+- Implemented the new EdgeTTS voice module; it can be found at shortgpt/audio/edge_voice_module.
+- Added documentation which can be found under docs/.
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..81e54d84f0f343c082b2cfb4568745fb889dc0a1
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,35 @@
+ShortGPT License
+
+Depending on the type of your legal entity, you are granted permission to use ShortGPT for your project. Individuals and small companies are allowed to use ShortGPT to create videos for free (even commercial), while a company license is required for for-profit organizations of a certain size. This two-tier system was designed to ensure funding for this project while still allowing the source code to be available and the program to be free for most. Read below for the exact terms of use.
+
+ Free license
+ Company license
+
+Free license
+
+Copyright ยฉ 2023 ShortGPT
+Eligibility
+
+You are eligible to use ShortGPT for free if you are:
+
+ an individual
+ a for-profit organization with a gross revenue up to 314 159$ a year.
+ a non-profit or not-for-profit organization
+ evaluating whether ShortGPT is a good fit, and are not yet using it in a commercial way
+
+Allowed use cases
+
+Permission is hereby granted, free of charge, to any person eligible for the "Free license", to use the software non-commercially or commercially for the purpose of creating videos and images and to modify the software to their own liking, for the purpose of fulfilling their custom use case or to contribute bug fixes or improvements back to ShortGPT.
+Disallowed use cases
+
+It is not allowed to copy or modify ShortGPT code for the purpose of selling, renting, licensing, relicensing, or sublicensing your own derivate of ShortGPT.
+Warranty notice
+
+The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
+Support
+
+Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
+Company license
+
+You are required to obtain a company license to use ShortGPT if you are not within the group of entities eligible for a free license. This license will enable you to use ShortGPT for the allowed use cases specified in the free license, and give you access to prioritized support.
+We will deduct 10% of the revenue generated from ShortGPT as part of the payment for the company license.
diff --git a/README.md b/README.md
index 69d6d6d087322114f173659fb3cd9d19385792b4..4655ef2e9c3a7e9335123cefa5e406f0f378a8fb 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,203 @@
---
-title: SHORTgpt
-emoji: ๐
-colorFrom: blue
-colorTo: gray
+title: sHORTgpt
+app_file: runShortGPTColab.py
sdk: gradio
-sdk_version: 4.37.2
-app_file: app.py
-pinned: false
-license: apache-2.0
+sdk_version: 3.38.0
---
+# ๐๐ฌ ShortGPT
+[![](https://dcbadge.vercel.app/api/server/uERx39ru3R?compact=true&style=flat)](https://discord.gg/uERx39ru3R)
+[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/rayventurahq.svg?style=social&label=Follow%20%40RayVentura)](https://twitter.com/RayVenturaHQ)
+[![GitHub star chart](https://img.shields.io/github/stars/rayventura/shortgpt?style=social)](https://star-history.com/#rayventura/shortgpt)
+
-Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
+
+โก Automating video and short content creation with AI โก
+
+
+## ๐ฅ Showcase ([Full video on YouTube](https://youtu.be/hpoSHq-ER8U))
+
+https://github.com/RayVentura/ShortGPT/assets/121462835/a802faad-0fd7-4fcb-aa82-6365c27ea5fe
+## ๐ฅ Voice Dubbing
+
+
+https://github.com/RayVentura/ShortGPT/assets/121462835/06f51b2d-f8b1-4a23-b299-55e0e18902ef
+
+## ๐ Show Your Support
+We hope you find ShortGPT helpful! If you do, let us know by giving us a star โญ on the repo. It's easy, just click on the 'Star' button at the top right of the page. Your support means a lot to us and keeps us motivated to improve and expand ShortGPT. Thank you and happy content creating! ๐
+
+[![GitHub star chart](https://img.shields.io/github/stars/rayventura/shortgpt?style=social)](https://github.com/RayVentura/ShortGPT/stargazers)
+## ๐ ๏ธ How it works
+![alt text](https://github.com/RayVentura/ShortGPT/assets/121462835/fcee74d4-f856-4481-949f-244558bf3bfa)
+## ๐ Introduction to ShortGPT
+ShortGPT is a powerful framework for automating content creation. It simplifies video creation, footage sourcing, voiceover synthesis, and editing tasks.
+
+- ๐๏ธ **Automated editing framework**: Streamlines the video creation process with an LLM oriented video editing language.
+
+- ๐ **Scripts and Prompts**: Provides ready-to-use scripts and prompts for various LLM automated editing processes.
+
+- ๐ฃ๏ธ **Voiceover / Content Creation**: Supports multiple languages including English ๐บ๐ธ, Spanish ๐ช๐ธ, Arabic ๐ฆ๐ช, French ๐ซ๐ท, Polish ๐ต๐ฑ, German ๐ฉ๐ช, Italian ๐ฎ๐น, and Portuguese ๐ต๐น.
+
+- ๐ **Caption Generation**: Automates the generation of video captions.
+
+- ๐๐ฅ **Asset Sourcing**: Sources images and video footage from the internet, connecting with the web and Pexels API as necessary.
+
+- ๐ง **Memory and persistency**: Ensures long-term persistency of automated editing variables with TinyDB.
+
+## ๐ Quick Start: Run ShortGPT on Google Colab (https://colab.research.google.com/drive/1_2UKdpF6lqxCqWaAcZb3rwMVQqtbisdE?usp=sharing)
+
+If you prefer not to install the prerequisites on your local system, you can use the Google Colab notebook. This option is free and requires no installation setup.
+
+1. Click on the link to the Google Colab notebook: [https://colab.research.google.com/drive/1_2UKdpF6lqxCqWaAcZb3rwMVQqtbisdE?usp=sharing](https://colab.research.google.com/drive/1_2UKdpF6lqxCqWaAcZb3rwMVQqtbisdE?usp=sharing)
+
+2. Once you're in the notebook, simply run the cells in order from top to bottom. You can do this by clicking on each cell and pressing the 'Play' button, or by using the keyboard . Enjoy using ShortGPT!
+
+# Instructions for running shortGPT
+This guide provides step-by-step instructions for installing ImageMagick and FFmpeg on your system, which are both required to do automated editing. Once installed, you can proceed to run `runShortGPT.py` successfully.
+
+## Prerequisites
+Before you begin, ensure that you have the following prerequisites installed on your system:
+- Python 3.x
+- Pip (Python package installer)
+
+## Installation Steps
+Follow the instructions below to install ImageMagick, FFmpeg, and clone the shortGPT repository:
+
+### Step 1: Install ImageMagick
+1. For `Windows` download the installer from the official ImageMagick website and follow the installation instructions.
+
+ [https://imagemagick.org/script/download.php](https://imagemagick.org/script/download.php)
+
+2. For Ubuntu/Debian-based systems, use the command:
+ ```
+ sudo apt-get install imagemagick
+ ```
+ Then run the following command to fix a moviepy Imagemagick policy.xml incompatibility problem:
+ ```
+ !sed -i '/
+
+
+
+
diff --git a/assets/img/logo.png b/assets/img/logo.png
new file mode 100644
index 0000000000000000000000000000000000000000..2e3fe972f835803544dcef0277218f9933543b71
Binary files /dev/null and b/assets/img/logo.png differ
diff --git a/docs/.gitignore b/docs/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..b2d6de30624f651a6c584d4faefafceac6302be1
--- /dev/null
+++ b/docs/.gitignore
@@ -0,0 +1,20 @@
+# Dependencies
+/node_modules
+
+# Production
+/build
+
+# Generated files
+.docusaurus
+.cache-loader
+
+# Misc
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
diff --git a/docs/README.md b/docs/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..be5090f1f1046ade93dceb3363eaeef18158a8a6
--- /dev/null
+++ b/docs/README.md
@@ -0,0 +1,10 @@
+# ShortGPT Documentation
+# Installation
+
+1. `yarn install` in the root of this repository (two level above this directory).
+1. In this directory, do `yarn start`.
+1. A browser window will open up, pointing to the docs.
+
+# Deployment
+
+Vercel handles the deployment of this website.
diff --git a/docs/babel.config.js b/docs/babel.config.js
new file mode 100644
index 0000000000000000000000000000000000000000..e00595dae7d69190e2a9d07202616c2ea932e487
--- /dev/null
+++ b/docs/babel.config.js
@@ -0,0 +1,3 @@
+module.exports = {
+ presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
+};
diff --git a/docs/docs/how-to-install.mdx b/docs/docs/how-to-install.mdx
new file mode 100644
index 0000000000000000000000000000000000000000..9ed52268073b2dfaf5ecc8dbedbe83912730a8e1
--- /dev/null
+++ b/docs/docs/how-to-install.mdx
@@ -0,0 +1,121 @@
+---
+title: Step-by-Step Guide to Installing ShortGPT
+sidebar_label: Installation Guide
+---
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+# Launching Your ShortGPT Experience
+
+This guide will walk you through the process of setting up your machine to run the **ShortGPT** library. The setup requires two key components, ImageMagick and FFmpeg. Follow the steps below to get these dependencies installed.
+
+## Before You Begin
+
+Make sure you have the following installed on your machine:
+
+- Python 3.x
+- Pip (Python package installer)
+
+## Installation Process
+
+Here are the steps to install ImageMagick, FFmpeg, and the ShortGPT library.
+
+
+
+
+### Step 1: Install ImageMagick
+
+ImageMagick is a crucial component for ShortGPT. Download the installer from the official ImageMagick website. Click on the link below to get started.
+
+> **[๐ Download ImageMagick Here ๐](https://imagemagick.org/script/download.php)**
+
+After downloading, follow the installation instructions provided on the website.
+
+### Step 2: Install FFmpeg (Essential for ShortGPT)
+
+FFmpeg is another key component for ShortGPT. Download the FFmpeg binaries from the link below:
+
+> **[๐ Download FFmpeg Here (click on
+FFmpeg_Full.msi ) ๐](https://github.com/icedterminal/ffmpeg-installer/releases/tag/6.0.0.20230306)**
+
+The download will include ffmpeg and ffprobe and will add it to your path. Follow the installation instructions as guided.
+
+Step 3: Install ShortGPT Library
+
+- Open a terminal or command prompt.
+- Execute the following command:
+
+```bash
+pip install --upgrade shortgpt
+```
+
+
+
+
+
+
+
+### Step 1: Install ImageMagick
+
+Run the command below in your command line:
+
+```bash
+brew install imagemagick
+```
+
+### Step 2: Install FFmpeg (Essential for ShortGPT)
+
+Run the command below in your command line:
+
+```bash
+brew install ffmpeg
+```
+
+
+Step 3: Install ShortGPT Library
+
+- Open a terminal or command prompt.
+- Execute the following command:
+
+```bash
+pip install --upgrade shortgpt
+```
+
+
+
+
+
+
+
+### Step 1: Install ImageMagick
+
+Execute the following command:
+
+```bash
+sudo apt-get install imagemagick
+```
+
+### Step 2: Install FFmpeg
+
+Execute the following command:
+
+```bash
+sudo apt-get install ffmpeg
+```
+
+
+Step 3: Install ShortGPT Library
+
+- Open a terminal or command prompt.
+- Execute the following command:
+
+```bash
+pip install --upgrade shortgpt
+```
+
+
+
+
+
+
+And there you have it! Your machine is now ready to run ShortGPT. Dive into the world of automated video content creation with ShortGPT!
\ No newline at end of file
diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js
new file mode 100644
index 0000000000000000000000000000000000000000..fa089dcb4d5db25b8114d2f455523d3a3c12631f
--- /dev/null
+++ b/docs/docusaurus.config.js
@@ -0,0 +1,135 @@
+/* eslint-disable @typescript-eslint/no-var-requires */
+const darkCodeTheme = require('prism-react-renderer/themes/dracula');
+const lightCodeTheme = require('prism-react-renderer/themes/github');
+
+// With JSDoc @type annotations, IDEs can provide config autocompletion
+/** @type {import('@docusaurus/types').DocusaurusConfig} */
+(
+ module.exports = {
+ title: 'ShortGPT',
+ tagline:
+ 'Open-Source Framework for AI content automation',
+ url: 'https://dev.shortgpt.ai',
+ baseUrl: '/',
+ favicon: 'img/favicon.ico',
+ organizationName: 'RayVentura',
+ projectName: 'ShortGPT',
+ onBrokenLinks: 'throw',
+ onBrokenMarkdownLinks: 'throw',
+ presets: [
+ [
+ '@docusaurus/preset-classic',
+ /** @type {import('@docusaurus/preset-classic').Options} */
+ ({
+ docs: {
+ path: 'docs',
+ sidebarPath: 'sidebars.js',
+ editUrl:
+ 'https://github.com/RayVentura/ShortGPT/edit/stable/docs/',
+ versions: {
+ current: {
+ label: 'current',
+ },
+ },
+ lastVersion: 'current',
+ showLastUpdateAuthor: true,
+ showLastUpdateTime: true,
+ },
+ theme: {
+ customCss: require.resolve('./src/css/custom.css'),
+ },
+ }),
+ ],
+ ],
+ plugins: ['tailwind-loader'],
+ themeConfig:
+ /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
+ ({
+
+ navbar: {
+ hideOnScroll: true,
+ logo: {
+ alt: 'ShortGPT',
+ src: 'img/logo.png',
+ },
+ items: [
+ // left
+ {
+ label: 'Docs',
+ to: 'docs/how-to-install',
+ position: 'right',
+ },
+ // right
+ {
+ type: 'docsVersionDropdown',
+ position: 'right',
+ },
+ {
+ href: 'https://github.com/RayVentura/ShortGPT',
+ position: 'right',
+ className: 'header-github-link',
+ },
+ ],
+ },
+ colorMode: {
+ defaultMode: 'light',
+ disableSwitch: false,
+ respectPrefersColorScheme: true,
+ },
+ announcementBar: {
+ content:
+ 'โญ๏ธ If you like ShortGPT, give it a star on GitHub! โญ๏ธ',
+ },
+ footer: {
+ links: [
+ {
+ title: 'Docs',
+ items: [
+ {
+ label: 'Getting Started',
+ to: 'docs/how-to-install',
+ },
+
+ ],
+ },
+ {
+ title: 'ShortGPT',
+ items: [
+ {
+ label: 'Issues',
+ to: 'https://github.com/RayVentura/ShortGPT/issues',
+ },
+ ],
+ },
+ {
+ title: 'Community',
+ items: [
+ {
+ label: 'Discord',
+ to: 'https://discord.com/invite/bRTacwYrfX',
+ },
+ ],
+ },
+ {
+ title: 'Social',
+ items: [
+ {
+ label: 'GitHub',
+ to: 'https://github.com/RayVentura/ShortGPT',
+ },
+ {
+ label: 'Twitter',
+ to: 'https://twitter.com/RayVenturaHQ',
+ },
+ ],
+ },
+ ],
+ copyright: `ShortGPT ${new Date().getFullYear()}`,
+ },
+ prism: {
+ theme: lightCodeTheme,
+ darkTheme: darkCodeTheme,
+ },
+ }),
+ }
+);
diff --git a/docs/package.json b/docs/package.json
new file mode 100644
index 0000000000000000000000000000000000000000..ea2beddca061df1a8cb90dfb43d8b8ee65500f59
--- /dev/null
+++ b/docs/package.json
@@ -0,0 +1,51 @@
+{
+ "name": "shortgpt-documentation",
+ "version": "3.5.1",
+ "private": true,
+ "scripts": {
+ "build:clean": "rm -rf dist build .docusaurus node_modules",
+ "docusaurus": "docusaurus",
+ "start": "docusaurus start",
+ "build": "docusaurus build",
+ "swizzle": "docusaurus swizzle",
+ "deploy": "docusaurus deploy",
+ "clear": "docusaurus clear",
+ "serve": "docusaurus serve",
+ "write-translations": "docusaurus write-translations",
+ "write-heading-ids": "docusaurus write-heading-ids"
+ },
+ "dependencies": {
+ "@algolia/ui-library": "9.10.2",
+ "@docsearch/react": "3.5.1",
+ "@docusaurus/core": "2.4.1",
+ "@docusaurus/preset-classic": "2.4.1",
+ "@mdx-js/react": "^1.6.22",
+ "clsx": "^1.1.1",
+ "file-loader": "6.2.0",
+ "my-loaders": "file:plugins/my-loaders",
+ "postcss": "8.4.25",
+ "postcss-import": "15.0.0",
+ "postcss-preset-env": "7.8.2",
+ "prism-react-renderer": "1.2.1",
+ "react": "^18.2.0",
+ "react-dom": "^18.2.0",
+ "tailwind-loader": "file:plugins/tailwind-loader",
+ "url-loader": "4.1.1"
+ },
+ "devDependencies": {
+ "postcss-loader": "6.2.1",
+ "tailwindcss": "npm:@tailwindcss/postcss7-compat"
+ },
+ "browserslist": {
+ "production": [
+ ">0.5%",
+ "not dead",
+ "not op_mini all"
+ ],
+ "development": [
+ "last 1 chrome version",
+ "last 1 firefox version",
+ "last 1 safari version"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/docs/plugins/my-loaders/index.js b/docs/plugins/my-loaders/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..4f397dd79e2be1582a7ac922a47e611b2b762f9a
--- /dev/null
+++ b/docs/plugins/my-loaders/index.js
@@ -0,0 +1,18 @@
+module.exports = function () {
+ return {
+ name: 'loaders',
+ configureWebpack() {
+ return {
+ module: {
+ rules: [
+ {
+ test: /\.(gif|png|jpe?g|svg)$/i,
+ exclude: /\.(mdx?)$/i,
+ use: ['file-loader', { loader: 'image-webpack-loader' }],
+ },
+ ],
+ },
+ };
+ },
+ };
+};
diff --git a/docs/plugins/tailwind-loader/index.js b/docs/plugins/tailwind-loader/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..8cb190285d9357b73385c1547ddf8b06fb217084
--- /dev/null
+++ b/docs/plugins/tailwind-loader/index.js
@@ -0,0 +1,19 @@
+/* eslint-disable @typescript-eslint/no-var-requires */
+module.exports = function () {
+ return {
+ name: 'postcss-tailwindcss-loader',
+ configurePostCss(postcssOptions) {
+ postcssOptions.plugins.push(
+ require('postcss-import'),
+ require('tailwindcss'),
+ require('postcss-preset-env')({
+ autoprefixer: {
+ flexbox: 'no-2009',
+ },
+ stage: 4,
+ })
+ );
+ return postcssOptions;
+ },
+ };
+};
diff --git a/docs/sidebars.js b/docs/sidebars.js
new file mode 100644
index 0000000000000000000000000000000000000000..066da902f34420b0e21772e857bc3abf7418e8ae
--- /dev/null
+++ b/docs/sidebars.js
@@ -0,0 +1,20 @@
+/**
+ * Creating a sidebar enables you to:
+ * - create an ordered group of docs
+ * - render a sidebar for each doc of that group
+ * - provide next/previous navigation.
+ *
+ * The sidebars can be generated from the filesystem, or explicitly defined here.
+ *
+ * Create as many sidebars as you want.
+ */
+
+module.exports = {
+ docs: [
+ {
+ type: 'category',
+ label: 'Introduction',
+ items: ['how-to-install'],
+ },
+ ],
+};
diff --git a/docs/src/components/Home.js b/docs/src/components/Home.js
new file mode 100644
index 0000000000000000000000000000000000000000..4ecee8ec384f04e857eb269c6c6a386b192e3891
--- /dev/null
+++ b/docs/src/components/Home.js
@@ -0,0 +1,356 @@
+import { Hero } from '@algolia/ui-library';
+import { useColorMode } from '@docusaurus/theme-common';
+import { useBaseUrlUtils } from '@docusaurus/useBaseUrl';
+import React from 'react';
+import { Link } from 'react-router-dom';
+
+function Home() {
+ const { withBaseUrl } = useBaseUrlUtils();
+ const { colorMode } = useColorMode();
+
+ React.useEffect(() => {
+ if (colorMode === 'dark') {
+ document.querySelector('html').classList.add('dark');
+ } else {
+ document.querySelector('html').classList.remove('dark');
+ }
+ }, [colorMode]);
+
+ function Header() {
+ return (
+
+
+
+ ๐๐ฌ SHORTGPT
+
+
+ Opensource AI Content Automation Framework
+
+ >
+ }
+ background="cubes"
+ cta={[
+
+ Get started
+
+ ]}
+ />
+ );
+ }
+
+ function Description() {
+ return (
+ <>
+ {/* Description */}
+
+
+
+
+ Automating video and short content creation with AI
+
+
+ ShortGPT is a powerful framework for automating content creation. It simplifies video creation, footage sourcing, voiceover synthesis, and editing tasks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Automated editing framework
+
+
+ ShortGPT streamlines the video creation process with an LLM oriented video editing language, making it easier to automate editing tasks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Voiceover / Content Creation
+
+
+ ShortGPT supports multiple languages for voiceover synthesis, making it easy to create content in various languages.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Asset Sourcing
+
+
+ ShortGPT can source images and video footage from the internet, allowing you to easily find and use relevant visuals.
+
+
+
+
+
+
+
+
+
+ {/* How it works */}
+
+
+
+
+
+ How it works
+
+
+ ShortGPT is an AI-powered framework that automates the process of content creation, from script generation to asset sourcing and video editing.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Automated Editing Framework
+
+
+ ShortGPT employs a heavy usage of LLMs and automated video editing libraries to streamline the video creation process (Ffmpeg, moviepy, ffprobe).
+
+
+
+
+
+
+
+
+
+ Voiceover / Content Creation
+
+
+ ShortGPT integrates multiple neural voice synthesis engines (ElevenLabs, EdgeTTS), to allow human-like voice quality in the audio generated.
+
+
+
+
+
+
+
+
+
+ Asset Sourcing
+
+
+ ShortGPT is equipped with an advanced asset sourcing module that can retrieve images and video footage from the internet. This feature allows for the easy incorporation of relevant visuals into the content (Pexels, youtube, and more soon).
+
+
+
+
+
+
+
+
+
+
+
+ {/* Powered by AI */}
+
+
+
+ Powered by AI
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Automated Editing
+
+
+ ShortGPT automates the video editing process, making it faster and more efficient with the help of AI.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Voiceover / Content Creation
+
+
+ ShortGPT supports multiple languages for voiceover synthesis, making it easy to create content in various languages.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Asset Sourcing
+
+
+ ShortGPT can source images and video footage from the internet, allowing you to easily find and use relevant visuals.
+
+ '''
+
+ @staticmethod
+ def get_html_video_template(file_url_path, file_name, width="auto", height="auto"):
+ """
+ Generate an HTML code snippet for embedding and downloading a video.
+
+ Parameters:
+ file_url_path (str): The URL or path to the video file.
+ file_name (str): The name of the video file.
+ width (str, optional): The width of the video. Defaults to "auto".
+ height (str, optional): The height of the video. Defaults to "auto".
+
+ Returns:
+ str: The generated HTML code snippet.
+ """
+ html = f'''
+
', gr.Button.update(visible=True), gr.update(value=error_html, visible=True)
+
+ def inspect_create_inputs(self, videoType, video_path, yt_link, tts_engine, language_eleven, language_edge,):
+ supported_extensions = ['.mp4', '.avi', '.mov'] # Add more supported video extensions if needed
+ print(videoType, video_path, yt_link)
+ if videoType == "Youtube link":
+ if not yt_link.startswith("https://youtube.com/") and not yt_link.startswith("https://www.youtube.com/"):
+ raise gr.Error('Invalid YouTube URL. Please provide a valid URL. Link example: https://www.youtube.com/watch?v=dQw4w9WgXcQ')
+ else:
+ if not video_path or not os.path.exists(video_path):
+ raise gr.Error('You must drag and drop a valid video file.')
+
+ file_ext = os.path.splitext(video_path)[-1].lower()
+ if file_ext not in supported_extensions:
+ raise gr.Error('Invalid video file. Supported video file extensions are: {}'.format(', '.join(supported_extensions)))
+ if tts_engine == AssetComponentsUtils.ELEVEN_TTS:
+ if not len(language_eleven) >0:
+ raise gr.Error('You must select one or more target languages')
+ if tts_engine == AssetComponentsUtils.EDGE_TTS:
+ if not len(language_edge) >0:
+ raise gr.Error('You must select one or more target languages')
+ return gr.update(visible=False)
+
+
+def update_progress(progress, progress_counter, num_steps, num_shorts, stop_event):
+ start_time = time.time()
+ while not stop_event.is_set():
+ elapsed_time = time.time() - start_time
+ dynamic = int(3649 * elapsed_time / 600)
+ progress(progress_counter / (num_steps * num_shorts), f"Rendering progress - {dynamic}/3649")
+ time.sleep(0.1) # update every 0.1 second
diff --git a/public/subscribe-animation.mp4 b/public/subscribe-animation.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..5da2424839799614b32df7f8173e6eeb82a40f34
--- /dev/null
+++ b/public/subscribe-animation.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:2cbd7d0bdd3bbfa6705c0829b3bdce7596d2ef9a662fd239ba6aeebb05c72127
+size 1072183
diff --git a/public/white_reddit_template.png b/public/white_reddit_template.png
new file mode 100644
index 0000000000000000000000000000000000000000..e168f79203e442c6fcdad510efbfbfcb0212d34f
Binary files /dev/null and b/public/white_reddit_template.png differ
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000000000000000000000000000000000000..7783b14603cb5dcb05e3426aa190c1044cd5e710
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,19 @@
+ffmpeg
+python-dotenv
+gradio==3.38.0
+openai
+tiktoken
+tinydb
+tinymongo
+proglog
+yt-dlp
+torch
+torchaudio
+### whisper timestamped
+whisper-timestamped
+protobuf==3.20.0
+pillow==9.0.0
+moviepy==1.0.3
+progress
+questionary
+edge-tts
\ No newline at end of file
diff --git a/runShortGPT.py b/runShortGPT.py
new file mode 100644
index 0000000000000000000000000000000000000000..1a4cb9a304a676ed423ff620e5f2e1de2a3317c5
--- /dev/null
+++ b/runShortGPT.py
@@ -0,0 +1,4 @@
+from gui.gui_gradio import ShortGptUI
+
+app = ShortGptUI(colab=False)
+app.launch()
\ No newline at end of file
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000000000000000000000000000000000000..00a1b5eac67f13c3c6af244006968b82a24c735e
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,53 @@
+from setuptools import setup, find_packages
+import codecs
+import os
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
+ long_description = "\n" + fh.read()
+
+VERSION = '0.1.2'
+DESCRIPTION = 'Automating video and short content creation with AI'
+LONG_DESCRIPTION = 'A powerful tool for automating content creation. It simplifies video creation, footage sourcing, voiceover synthesis, and editing tasks.'
+
+
+setup(
+ name="shortgpt",
+ version=VERSION,
+ author="RayVentura",
+ author_email="",
+ description=DESCRIPTION,
+ long_description_content_type="text/markdown",
+ long_description=long_description,
+ packages=find_packages(),
+ package_data={'': ['*.yaml', '*.json']}, # This will include all yaml files in package
+ install_requires=[
+ 'ffmpeg',
+ 'python-dotenv',
+ 'openai',
+ 'tiktoken',
+ 'tinydb',
+ 'tinymongo',
+ 'proglog',
+ 'yt-dlp',
+ 'torch',
+ 'whisper-timestamped',
+ 'torchaudio',
+ 'pillow==9.0.0',
+ 'protobuf==3.20.0',
+ 'edge-tts',
+ 'moviepy==1.0.3',
+ 'progress',
+ 'questionary',
+ ],
+ keywords=['python', 'video', 'content creation', 'AI', 'automation', 'editing', 'voiceover synthesis', 'video captions', 'asset sourcing', 'tinyDB'],
+ classifiers=[
+ "Development Status :: 5 - Production/Stable",
+ "Intended Audience :: Developers",
+ "Programming Language :: Python :: 3",
+ "Operating System :: Unix",
+ "Operating System :: MacOS :: MacOS X",
+ "Operating System :: Microsoft :: Windows",
+ ]
+)
\ No newline at end of file
diff --git a/shortGPT/__init__.py b/shortGPT/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..5a893a4af04d4f003cad9e7a9ab39f0373af9eb7
--- /dev/null
+++ b/shortGPT/__init__.py
@@ -0,0 +1,30 @@
+# import time
+# t1 = time.time()
+# from . import config
+# print("Took", time.time() - t1, "seconds to import config")
+# t1 = time.time()
+# from . import editing
+# print("Took", time.time() - t1, "seconds to import editing")
+# t1 = time.time()
+# from . import audio
+# print("Took", time.time() - t1, "seconds to import audio")
+# t1 = time.time()
+# from . import engine
+# print("Took", time.time() - t1, "seconds to import engine")
+# t1 = time.time()
+# from . import database
+# print("Took", time.time() - t1, "seconds to import database")
+# t1 = time.time()
+# from . import gpt
+# print("Took", time.time() - t1, "seconds to import gpt")
+# t1 = time.time()
+# from . import tracking
+# print("Took", time.time() - t1, "seconds to import tracking")
+
+# from . import config
+# from . import database
+# from . import editing_functions
+# from . import audio
+# from . import engine
+# from . import gpt
+# from . import tracking
\ No newline at end of file
diff --git a/shortGPT/api_utils/README.md b/shortGPT/api_utils/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..4c758b1ae66f2b0b39efa110d198a7ad0191e668
--- /dev/null
+++ b/shortGPT/api_utils/README.md
@@ -0,0 +1,53 @@
+# Module: api_utils
+
+The `api_utils` module provides utility functions for working with different APIs. It includes three files: `image_api.py`, `pexels_api.py`, and `eleven_api.py`. Each file contains functions related to a specific API.
+
+## File: image_api.py
+
+This file contains functions for interacting with the Bing Images API and extracting image URLs from the HTML response.
+
+### Functions:
+
+#### `_extractBingImages(html)`
+
+This function takes an HTML response as input and extracts image URLs, widths, and heights from it. It uses regular expressions to find the necessary information. The extracted image URLs are returned as a list of dictionaries, where each dictionary contains the URL, width, and height of an image.
+
+#### `_extractGoogleImages(html)`
+
+This function takes an HTML response as input and extracts image URLs from it. It uses regular expressions to find the necessary information. The extracted image URLs are returned as a list.
+
+#### `getBingImages(query, retries=5)`
+
+This function takes a query string as input and retrieves a list of image URLs from the Bing Images API. It replaces spaces in the query string with `+` and sends a GET request to the API. If the request is successful (status code 200), the HTML response is passed to `_extractBingImages` to extract the image URLs. If the request fails or no images are found, an exception is raised.
+
+## File: pexels_api.py
+
+This file contains functions for interacting with the Pexels Videos API and retrieving video URLs based on a query string.
+
+### Functions:
+
+#### `search_videos(query_string, orientation_landscape=True)`
+
+This function takes a query string and an optional boolean parameter `orientation_landscape` as input. It sends a GET request to the Pexels Videos API to search for videos based on the query string. The orientation of the videos can be specified as landscape or portrait. The function returns the JSON response from the API.
+
+#### `getBestVideo(query_string, orientation_landscape=True, used_vids=[])`
+
+This function takes a query string, an optional boolean parameter `orientation_landscape`, and an optional list `used_vids` as input. It calls the `search_videos` function to retrieve a list of videos based on the query string. It then filters and sorts the videos based on their dimensions and duration, and returns the URL of the best matching video. The `used_vids` parameter can be used to exclude previously used videos from the search results.
+
+## File: eleven_api.py
+
+This file contains functions for interacting with the Eleven API and generating voice recordings based on text input.
+
+### Functions:
+
+#### `getVoices(api_key="")`
+
+This function takes an optional API key as input and retrieves a dictionary of available voices from the Eleven API. The voices are returned as a dictionary, where the keys are voice names and the values are voice IDs.
+
+#### `getCharactersFromKey(key)`
+
+This function takes an API key as input and retrieves the remaining character limit for the given key. It sends a GET request to the Eleven API and extracts the character limit and count from the response.
+
+#### `generateVoice(text, character, fileName, stability=0.2, clarity=0.1, api_key="")`
+
+This function takes a text input, a character name, a file name, and optional parameters `stability`, `clarity`, and `api_key` as input. It generates a voice recording using the Eleven API and saves it to the specified file. The character name is used to select the appropriate voice. The stability and clarity parameters control the quality of the voice recording. The API key is required for authentication. If the request is successful, the file name is returned. Otherwise, an empty string is returned.
\ No newline at end of file
diff --git a/shortGPT/api_utils/__init__.py b/shortGPT/api_utils/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..ac92f4bb5c0fed4eac06b61f453654e99c523569
--- /dev/null
+++ b/shortGPT/api_utils/__init__.py
@@ -0,0 +1,2 @@
+from . import image_api
+from . import eleven_api
\ No newline at end of file
diff --git a/shortGPT/api_utils/eleven_api.py b/shortGPT/api_utils/eleven_api.py
new file mode 100644
index 0000000000000000000000000000000000000000..3b32cd2bd9ed61984880cb7767ca7f391220d185
--- /dev/null
+++ b/shortGPT/api_utils/eleven_api.py
@@ -0,0 +1,52 @@
+import json
+
+import requests
+
+
+class ElevenLabsAPI:
+
+ def __init__(self, api_key):
+ self.api_key = api_key
+ self.url_base = 'https://api.elevenlabs.io/v1/'
+ self.get_voices()
+
+ def get_voices(self):
+ '''Get the list of voices available'''
+ url = self.url_base + 'voices'
+ headers = {'accept': 'application/json'}
+ if self.api_key:
+ headers['xi-api-key'] = self.api_key
+ response = requests.get(url, headers=headers)
+ self.voices = {voice['name']: voice['voice_id'] for voice in response.json()['voices']}
+ return self.voices
+
+ def get_remaining_characters(self):
+ '''Get the number of characters remaining'''
+ url = self.url_base + 'user'
+ headers = {'accept': '*/*', 'xi-api-key': self.api_key, 'Content-Type': 'application/json'}
+ response = requests.get(url, headers=headers)
+
+ if response.status_code == 200:
+ sub = response.json()['subscription']
+ return sub['character_limit'] - sub['character_count']
+ else:
+ raise Exception(response.json()['detail']['message'])
+
+ def generate_voice(self, text, character, filename, stability=0.2, clarity=0.1):
+ '''Generate a voice'''
+ if character not in self.voices:
+ print(character, 'is not in the array of characters: ', list(self.voices.keys()))
+
+ voice_id = self.voices[character]
+ url = f'{self.url_base}text-to-speech/{voice_id}/stream'
+ headers = {'accept': '*/*', 'xi-api-key': self.api_key, 'Content-Type': 'application/json'}
+ data = json.dumps({"model_id": "eleven_multilingual_v1", "text": text, "stability": stability, "similarity_boost": clarity})
+ response = requests.post(url, headers=headers, data=data)
+
+ if response.status_code == 200:
+ with open(filename, 'wb') as f:
+ f.write(response.content)
+ return filename
+ else:
+ message = response.text
+ raise Exception(f'Error in response, {response.status_code} , message: {message}')
diff --git a/shortGPT/api_utils/image_api.py b/shortGPT/api_utils/image_api.py
new file mode 100644
index 0000000000000000000000000000000000000000..df07a2ab1bd3134e809db3d5156fc33918eb186d
--- /dev/null
+++ b/shortGPT/api_utils/image_api.py
@@ -0,0 +1,48 @@
+import json
+import requests
+import re
+import urllib.parse
+
+def _extractBingImages(html):
+ pattern = r'mediaurl=(.*?)&.*?expw=(\d+).*?exph=(\d+)'
+ matches = re.findall(pattern, html)
+ result = []
+
+ for match in matches:
+ url, width, height = match
+ if url.endswith('.jpg') or url.endswith('.png') or url.endswith('.jpeg'):
+ result.append({'url': urllib.parse.unquote(url), 'width': int(width), 'height': int(height)})
+
+ return result
+
+
+def _extractGoogleImages(html):
+ images = []
+ regex = re.compile(r"AF_initDataCallback\({key: 'ds:1', hash: '2', data:(.*?), sideChannel: {}}\);")
+ match = regex.search(html)
+ if match:
+ dz = json.loads(match.group(1))
+ for c in dz[56][1][0][0][1][0]:
+ try:
+ thing = list(c[0][0].values())[0]
+ images.append(thing[1][3])
+ except:
+ pass
+ return images
+
+
+def getBingImages(query, retries=5):
+ query = query.replace(" ", "+")
+ images = []
+ tries = 0
+ while(len(images) == 0 and tries < retries):
+ response = requests.get(f"https://www.bing.com/images/search?q={query}&first=1")
+ if(response.status_code == 200):
+ images = _extractBingImages(response.text)
+ else:
+ print("Error While making bing image searches", response.text)
+ raise Exception("Error While making bing image searches")
+ if(images):
+ return images
+ raise Exception("Error While making bing image searches")
+
diff --git a/shortGPT/api_utils/pexels_api.py b/shortGPT/api_utils/pexels_api.py
new file mode 100644
index 0000000000000000000000000000000000000000..0e442ed7979ddae8b6227e7b92f6321b17dac0f0
--- /dev/null
+++ b/shortGPT/api_utils/pexels_api.py
@@ -0,0 +1,51 @@
+import requests
+
+from shortGPT.config.api_db import ApiKeyManager
+
+
+def search_videos(query_string, orientation_landscape=True):
+ url = "https://api.pexels.com/videos/search"
+ headers = {
+ "Authorization": ApiKeyManager.get_api_key("PEXELS")
+ }
+ params = {
+ "query": query_string,
+ "orientation": "landscape" if orientation_landscape else "portrait",
+ "per_page": 15
+ }
+
+ response = requests.get(url, headers=headers, params=params)
+ json_data = response.json()
+ # print(response.headers['X-Ratelimit-Limit'])
+ # print(response.headers['X-Ratelimit-Remaining'])
+ # print(response.headers['X-Ratelimit-Reset'])
+
+ return json_data
+
+
+def getBestVideo(query_string, orientation_landscape=True, used_vids=[]):
+ vids = search_videos(query_string, orientation_landscape)
+ videos = vids['videos'] # Extract the videos list from JSON
+
+ # Filter and extract videos with width and height as 1920x1080 for landscape or 1080x1920 for portrait
+ if orientation_landscape:
+ filtered_videos = [video for video in videos if video['width'] >= 1920 and video['height'] >= 1080 and video['width']/video['height'] == 16/9]
+ else:
+ filtered_videos = [video for video in videos if video['width'] >= 1080 and video['height'] >= 1920 and video['height']/video['width'] == 16/9]
+
+ # Sort the filtered videos by duration in ascending order
+ sorted_videos = sorted(filtered_videos, key=lambda x: abs(15-int(x['duration'])))
+
+ # Extract the top 3 videos' URLs
+ for video in sorted_videos:
+ for video_file in video['video_files']:
+ if orientation_landscape:
+ if video_file['width'] == 1920 and video_file['height'] == 1080:
+ if not (video_file['link'].split('.hd')[0] in used_vids):
+ return video_file['link']
+ else:
+ if video_file['width'] == 1080 and video_file['height'] == 1920:
+ if not (video_file['link'].split('.hd')[0] in used_vids):
+ return video_file['link']
+ print("NO LINKS found for this round of search with query :", query_string)
+ return None
diff --git a/shortGPT/audio/README.md b/shortGPT/audio/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..1ec9e350c9ff54d06043296ebb1c30ea0878a5dd
--- /dev/null
+++ b/shortGPT/audio/README.md
@@ -0,0 +1,76 @@
+# Audio Module
+
+The audio module provides a set of functions and classes for working with audio files and performing various operations on them.
+
+## audio_utils.py
+
+This file contains utility functions for audio processing.
+
+### downloadYoutubeAudio(url, outputFile)
+Downloads audio from a YouTube video given its URL and saves it to the specified output file. Returns the path to the downloaded audio file and its duration.
+
+### speedUpAudio(tempAudioPath, outputFile, expected_chars_per_sec=CONST_CHARS_PER_SEC)
+Speeds up the audio to make it under 60 seconds. If the duration of the audio is greater than 57 seconds, it will be sped up to fit within the time limit. Otherwise, the audio will be left unchanged. Returns the path to the sped up audio file.
+
+### ChunkForAudio(alltext, chunk_size=2500)
+Splits a text into chunks of a specified size (default is 2500 characters) to be used for audio generation. Returns a list of text chunks.
+
+### audioToText(filename, model_size="tiny")
+Converts an audio file to text using a pre-trained model. Returns a generator object that yields the transcribed text and its corresponding timestamps.
+
+### getWordsPerSec(filename)
+Calculates the average number of words per second in an audio file. Returns the words per second value.
+
+### getCharactersPerSec(filename)
+Calculates the average number of characters per second in an audio file. Returns the characters per second value.
+
+## audio_duration.py
+
+This file contains functions for getting the duration of audio files.
+
+### get_duration_yt_dlp(url)
+Gets the duration of a YouTube video or audio using the yt_dlp library. Returns the duration in seconds.
+
+### get_duration_ffprobe(signed_url)
+Gets the duration of an audio or video file using the ffprobe command line tool. Returns the duration in seconds.
+
+### getAssetDuration(url, isVideo=True)
+Gets the duration of an audio or video asset from various sources, including YouTube and cloud storage providers. Returns the URL of the asset and its duration in seconds.
+
+### getYoutubeAudioLink(url)
+Gets the audio link of a YouTube video given its URL. Returns the audio URL and its duration in seconds.
+
+### getYoutubeVideoLink(url)
+Gets the video link of a YouTube video given its URL. Returns the video URL and its duration in seconds.
+
+## voice_module.py
+
+This file contains an abstract base class for voice modules.
+
+### VoiceModule
+An abstract base class that defines the interface for voice modules. Voice modules are responsible for generating voice recordings from text.
+
+#### update_usage()
+Updates the usage statistics of the voice module.
+
+#### get_remaining_characters()
+Gets the number of remaining characters that can be generated using the voice module.
+
+#### generate_voice(text, outputfile)
+Generates a voice recording from the specified text and saves it to the specified output file.
+
+## eleven_voice_module.py
+
+This file contains a voice module implementation for the ElevenLabs API.
+
+### ElevenLabsVoiceModule
+A voice module implementation for the ElevenLabs API. Requires an API key and a voice name to be initialized.
+
+#### update_usage()
+Updates the usage statistics of the ElevenLabs API.
+
+#### get_remaining_characters()
+Gets the number of remaining characters that can be generated using the ElevenLabs API.
+
+#### generate_voice(text, outputfile)
+Generates a voice recording from the specified text using the ElevenLabs API and saves it to the specified output file. Raises an exception if the API key does not have enough credits to generate the text.
\ No newline at end of file
diff --git a/shortGPT/audio/__init__.py b/shortGPT/audio/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..abd99ee7b1f34522e489a43b424761a0c37a8117
--- /dev/null
+++ b/shortGPT/audio/__init__.py
@@ -0,0 +1,3 @@
+from . import audio_utils
+from . import eleven_voice_module
+from . import audio_duration
\ No newline at end of file
diff --git a/shortGPT/audio/audio_duration.py b/shortGPT/audio/audio_duration.py
new file mode 100644
index 0000000000000000000000000000000000000000..f72a77b5933cbd004e588d66d08e7ec9c4368f66
--- /dev/null
+++ b/shortGPT/audio/audio_duration.py
@@ -0,0 +1,87 @@
+import json
+import subprocess
+
+import yt_dlp
+
+from shortGPT.editing_utils.handle_videos import getYoutubeVideoLink
+
+
+def get_duration_yt_dlp(url):
+ ydl_opts = {
+ "quiet": True,
+ "no_warnings": True,
+ "no_color": True,
+ "no_call_home": True,
+ "no_check_certificate": True
+ }
+ try:
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
+ dictMeta = ydl.extract_info(url, download=False, )
+ return dictMeta['duration'], ""
+ except Exception as e:
+ return None, f"Failed getting duration from the following video/audio url/path using yt_dlp. {e.args[0]}"
+
+
+def get_duration_ffprobe(signed_url):
+ try:
+ cmd = [
+ "ffprobe",
+ "-v",
+ "quiet",
+ "-print_format",
+ "json",
+ "-show_format",
+ "-i",
+ signed_url
+ ]
+ output = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+
+ if output.returncode != 0:
+ return None, f"Error executing command using ffprobe. {output.stderr.strip()}"
+
+ metadata = json.loads(output.stdout)
+ duration = float(metadata["format"]["duration"])
+ return duration, ""
+ except Exception as e:
+ print("Failed getting the duration of the asked ressource", e.args[0])
+ return None, ""
+
+
+def get_asset_duration(url, isVideo=True):
+ if ("youtube.com" in url):
+ if not isVideo:
+ url, _ = getYoutubeAudioLink(url)
+ else:
+ url, _ = getYoutubeVideoLink(url)
+ # Trying two different method to get the duration of the video / audio
+ duration, err_ffprobe = get_duration_ffprobe(url)
+ if duration is not None:
+ return url, duration
+
+ duration, err_yt_dlp = get_duration_yt_dlp(url)
+ if duration is not None:
+ return url, duration
+ print(err_yt_dlp)
+ print(err_ffprobe)
+ print(f"The url/path {url} does not point to a video/ audio. Impossible to extract its duration")
+ return url, None
+
+
+def getYoutubeAudioLink(url):
+ ydl_opts = {
+ "quiet": True,
+ "no_warnings": True,
+ "no_color": True,
+ "no_call_home": True,
+ "no_check_certificate": True,
+ "format": "bestaudio/best"
+ }
+ try:
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
+ dictMeta = ydl.extract_info(
+ url,
+ download=False)
+ return dictMeta['url'], dictMeta['duration']
+ except Exception as e:
+ print("Failed getting audio link from the following video/url", e.args[0])
+ return None
diff --git a/shortGPT/audio/audio_utils.py b/shortGPT/audio/audio_utils.py
new file mode 100644
index 0000000000000000000000000000000000000000..73b3e549a814bf57bdbd36abe1db0755dc6e365c
--- /dev/null
+++ b/shortGPT/audio/audio_utils.py
@@ -0,0 +1,98 @@
+import os
+import subprocess
+
+import yt_dlp
+
+from shortGPT.audio.audio_duration import get_asset_duration
+
+CONST_CHARS_PER_SEC = 20.5 # Arrived to this result after whispering a ton of shorts and calculating the average number of characters per second of speech.
+
+WHISPER_MODEL = None
+
+
+def downloadYoutubeAudio(url, outputFile):
+ ydl_opts = {
+ "quiet": True,
+ "no_warnings": True,
+ "no_color": True,
+ "no_call_home": True,
+ "no_check_certificate": True,
+ "format": "bestaudio/best",
+ "outtmpl": outputFile
+ }
+ try:
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
+ dictMeta = ydl.extract_info(
+ url,
+ download=True)
+ if (not os.path.exists(outputFile)):
+ raise Exception("Audio Download Failed")
+ return outputFile, dictMeta['duration']
+ except Exception as e:
+ print("Failed downloading audio from the following video/url", e.args[0])
+ return None
+
+
+def speedUpAudio(tempAudioPath, outputFile, expected_duration=None): # Speeding up the audio to make it under 60secs, otherwise the output video is not considered as a short.
+ tempAudioPath, duration = get_asset_duration(tempAudioPath, False)
+ if not expected_duration:
+ if (duration > 57):
+ subprocess.run(['ffmpeg', '-i', tempAudioPath, '-af', f'atempo={(duration/57):.5f}', outputFile])
+ else:
+ subprocess.run(['ffmpeg', '-i', tempAudioPath, outputFile])
+ else:
+ subprocess.run(['ffmpeg', '-i', tempAudioPath, '-af', f'atempo={(duration/expected_duration):.5f}', outputFile])
+ if (os.path.exists(outputFile)):
+ return outputFile
+
+
+def ChunkForAudio(alltext, chunk_size=2500):
+ alltext_list = alltext.split('.')
+ chunks = []
+ curr_chunk = ''
+ for text in alltext_list:
+ if len(curr_chunk) + len(text) <= chunk_size:
+ curr_chunk += text + '.'
+ else:
+ chunks.append(curr_chunk)
+ curr_chunk = text + '.'
+ if curr_chunk:
+ chunks.append(curr_chunk)
+ return chunks
+
+
+def audioToText(filename, model_size="base"):
+ from whisper_timestamped import load_model, transcribe_timestamped
+ global WHISPER_MODEL
+ if (WHISPER_MODEL == None):
+ WHISPER_MODEL = load_model(model_size)
+ gen = transcribe_timestamped(WHISPER_MODEL, filename, verbose=False, fp16=False)
+ return gen
+
+
+def getWordsPerSec(filename):
+ a = audioToText(filename)
+ return len(a['text'].split()) / a['segments'][-1]['end']
+
+
+def getCharactersPerSec(filename):
+ a = audioToText(filename)
+ return len(a['text']) / a['segments'][-1]['end']
+
+def run_background_audio_split(sound_file_path):
+ try:
+ # Run spleeter command
+ # Get absolute path of sound file
+ output_dir = os.path.dirname(sound_file_path)
+ command = f"spleeter separate -p spleeter:2stems -o '{output_dir}' '{sound_file_path}'"
+
+ process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ # If spleeter runs successfully, return the path to the background music file
+ if process.returncode == 0:
+ return os.path.join(output_dir, sound_file_path.split("/")[-1].split(".")[0], "accompaniment.wav")
+ else:
+ return None
+ except Exception:
+ # If spleeter crashes, return None
+ return None
diff --git a/shortGPT/audio/edge_voice_module.py b/shortGPT/audio/edge_voice_module.py
new file mode 100644
index 0000000000000000000000000000000000000000..096517db744d4bf318e27fbfa548b0b3c3c81e01
--- /dev/null
+++ b/shortGPT/audio/edge_voice_module.py
@@ -0,0 +1,52 @@
+import asyncio
+import os
+from concurrent.futures import ThreadPoolExecutor
+
+import edge_tts
+
+from shortGPT.audio.voice_module import VoiceModule
+from shortGPT.config.languages import (EDGE_TTS_VOICENAME_MAPPING,
+ LANGUAGE_ACRONYM_MAPPING, Language)
+
+
+def run_async_func(loop, func):
+ return loop.run_until_complete(func)
+
+
+class EdgeTTSVoiceModule(VoiceModule):
+ def __init__(self, voiceName):
+ self.voiceName = voiceName
+ super().__init__()
+
+ def update_usage(self):
+ return None
+
+ def get_remaining_characters(self):
+ return 999999999999
+
+ def generate_voice(self, text, outputfile):
+ loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(loop)
+
+ try:
+ with ThreadPoolExecutor() as executor:
+ loop.run_in_executor(executor, run_async_func, loop, self.async_generate_voice(text, outputfile))
+
+ finally:
+ loop.close()
+ if not os.path.exists(outputfile):
+ print("An error happened during edge_tts audio generation, no output audio generated")
+ raise Exception("An error happened during edge_tts audio generation, no output audio generated")
+ return outputfile
+
+ async def async_generate_voice(self, text, outputfile):
+ try:
+ communicate = edge_tts.Communicate(text, self.voiceName)
+ with open(outputfile, "wb") as file:
+ async for chunk in communicate.stream():
+ if chunk["type"] == "audio":
+ file.write(chunk["data"])
+ except Exception as e:
+ print("Error generating audio using edge_tts", e)
+ raise Exception("An error happened during edge_tts audio generation, no output audio generated", e)
+ return outputfile
diff --git a/shortGPT/audio/eleven_voice_module.py b/shortGPT/audio/eleven_voice_module.py
new file mode 100644
index 0000000000000000000000000000000000000000..37219ba03b322861bfc3d4b52b98d57351fcf6e7
--- /dev/null
+++ b/shortGPT/audio/eleven_voice_module.py
@@ -0,0 +1,29 @@
+from shortGPT.api_utils.eleven_api import ElevenLabsAPI
+from shortGPT.audio.voice_module import VoiceModule
+
+
+class ElevenLabsVoiceModule(VoiceModule):
+ def __init__(self, api_key, voiceName, checkElevenCredits=False):
+ self.api_key = api_key
+ self.voiceName = voiceName
+ self.remaining_credits = None
+ self.eleven_labs_api = ElevenLabsAPI(self.api_key)
+ self.update_usage()
+ if checkElevenCredits and self.get_remaining_characters() < 1200:
+ raise Exception(f"Your ElevenLabs API KEY doesn't have enough credits ({self.remaining_credits} character remaining). Minimum required: 1200 characters (equivalent to a 45sec short)")
+ super().__init__()
+
+ def update_usage(self):
+ self.remaining_credits = self.eleven_labs_api.get_remaining_characters()
+ return self.remaining_credits
+
+ def get_remaining_characters(self):
+ return self.remaining_credits if self.remaining_credits else self.eleven_labs_api.get_remaining_characters()
+
+ def generate_voice(self, text, outputfile):
+ if self.get_remaining_characters() >= len(text):
+ file_path =self.eleven_labs_api.generate_voice(text=text, character=self.voiceName, filename=outputfile)
+ self.update_usage()
+ return file_path
+ else:
+ raise Exception(f"You cannot generate {len(text)} characters as your ElevenLabs key has only {self.remaining_credits} characters remaining")
diff --git a/shortGPT/audio/voice_module.py b/shortGPT/audio/voice_module.py
new file mode 100644
index 0000000000000000000000000000000000000000..9948d7b9bd683519259e7a8ccdde291b10b4601f
--- /dev/null
+++ b/shortGPT/audio/voice_module.py
@@ -0,0 +1,16 @@
+from abc import ABC, abstractmethod
+class VoiceModule(ABC):
+
+ def __init__(self):
+ pass
+ @abstractmethod
+ def update_usage(self):
+ pass
+
+ @abstractmethod
+ def get_remaining_characters(self):
+ pass
+
+ @abstractmethod
+ def generate_voice(self,text, outputfile):
+ pass
\ No newline at end of file
diff --git a/shortGPT/config/README.md b/shortGPT/config/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..d46130a5b7692821853a69587289edb717255b30
--- /dev/null
+++ b/shortGPT/config/README.md
@@ -0,0 +1,204 @@
+# Module: config
+
+The `config` module contains various files and functions related to configuration settings and utilities.
+
+## File: config.py
+
+This file contains functions for reading and writing YAML files, as well as loading local assets specified in a YAML configuration file.
+
+### Functions:
+
+#### `read_yaml_config(file_path: str) -> dict`
+
+This function reads and returns the contents of a YAML file as a dictionary.
+
+Parameters:
+- `file_path` - The path to the YAML file to be read.
+
+Returns:
+- A dictionary containing the contents of the YAML file.
+
+#### `write_yaml_config(file_path: str, data: dict)`
+
+This function writes a dictionary to a YAML file.
+
+Parameters:
+- `file_path` - The path to the YAML file to be written.
+- `data` - The dictionary to be written to the YAML file.
+
+#### `load_editing_assets() -> dict`
+
+This function loads all local assets from the static-assets folder specified in the yaml_config.
+
+Returns:
+- A dictionary containing the YAML configuration with updated local assets.
+
+## File: asset_db.py
+
+This file contains a class `AssetDatabase` that provides methods for managing a database of assets.
+
+### Class: AssetDatabase
+
+This class represents a database of assets and provides methods for adding, removing, and retrieving assets.
+
+Methods:
+
+#### `__init__()`
+
+This method initializes the `AssetDatabase` object. It creates the local and remote asset collections if they don't already exist.
+
+#### `asset_exists(name)`
+
+This method checks if an asset with the given name exists in the database.
+
+Parameters:
+- `name` - The name of the asset.
+
+Returns:
+- `True` if the asset exists, `False` otherwise.
+
+#### `add_local_asset(name, type, path)`
+
+This method adds a local asset to the database.
+
+Parameters:
+- `name` - The name of the asset.
+- `type` - The type of the asset.
+- `path` - The path to the asset file.
+
+#### `add_remote_asset(name, type, url)`
+
+This method adds a remote asset to the database.
+
+Parameters:
+- `name` - The name of the asset.
+- `type` - The type of the asset.
+- `url` - The URL of the remote asset.
+
+#### `remove_asset(name)`
+
+This method removes an asset from the database.
+
+Parameters:
+- `name` - The name of the asset.
+
+#### `get_df()`
+
+This method returns a pandas DataFrame with specific asset details.
+
+Returns:
+- A pandas DataFrame containing the asset details.
+
+#### `sync_local_assets()`
+
+This method loads all local assets from the static-assets folder into the database.
+
+#### `getAssetLink(key)`
+
+This method returns the link or path of an asset with the given key.
+
+Parameters:
+- `key` - The key of the asset.
+
+Returns:
+- The link or path of the asset.
+
+#### `getAssetDuration(key)`
+
+This method returns the duration of an asset with the given key.
+
+Parameters:
+- `key` - The key of the asset.
+
+Returns:
+- The duration of the asset.
+
+#### `updateLocalAsset(key: str)`
+
+This method updates the local asset with the given key.
+
+Parameters:
+- `key` - The key of the asset.
+
+Returns:
+- The file path and duration of the updated asset.
+
+#### `updateYoutubeAsset(key: str)`
+
+This method updates the YouTube asset with the given key.
+
+Parameters:
+- `key` - The key of the asset.
+
+Returns:
+- The remote URL and duration of the updated asset.
+
+## File: api_db.py
+
+This file contains functions for managing API keys.
+
+### Functions:
+
+#### `get_api_key(name)`
+
+This function retrieves the API key with the given name.
+
+Parameters:
+- `name` - The name of the API key.
+
+Returns:
+- The API key.
+
+#### `set_api_key(name, value)`
+
+This function sets the API key with the given name to the specified value.
+
+Parameters:
+- `name` - The name of the API key.
+- `value` - The value of the API key.
+
+## File: languages.py
+
+This file contains an enumeration class `Language` that represents different languages.
+
+### Enum: Language
+
+This enumeration class represents different languages and provides a list of supported languages.
+
+Supported Languages:
+- ENGLISH
+- SPANISH
+- FRENCH
+- ARABIC
+- GERMAN
+- POLISH
+- ITALIAN
+- PORTUGUESE
+
+## File: path_utils.py
+
+This file contains utility functions for searching for program paths.
+
+### Functions:
+
+#### `search_program(program_name)`
+
+This function searches for the specified program and returns its path.
+
+Parameters:
+- `program_name` - The name of the program to search for.
+
+Returns:
+- The path of the program, or None if the program is not found.
+
+#### `get_program_path(program_name)`
+
+This function retrieves the path of the specified program.
+
+Parameters:
+- `program_name` - The name of the program.
+
+Returns:
+- The path of the program, or None if the program is not found.
+
+Note: The `magick_path` variable sets the `IMAGEMAGICK_BINARY` environment variable to the path of the `magick` program if it exists.
\ No newline at end of file
diff --git a/shortGPT/config/__init__.py b/shortGPT/config/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..d782e9b56643a2368e9d600b93b32e7807e129cc
--- /dev/null
+++ b/shortGPT/config/__init__.py
@@ -0,0 +1 @@
+from . import config
\ No newline at end of file
diff --git a/shortGPT/config/api_db.py b/shortGPT/config/api_db.py
new file mode 100644
index 0000000000000000000000000000000000000000..b6659091a53dd2020fddf359f0d2e12e0a863c83
--- /dev/null
+++ b/shortGPT/config/api_db.py
@@ -0,0 +1,23 @@
+import enum
+from shortGPT.database.db_document import TinyMongoDocument
+
+class ApiProvider(enum.Enum):
+ OPENAI = "OPENAI"
+ ELEVEN_LABS = "ELEVEN LABS"
+ PEXELS = "PEXELS"
+
+
+class ApiKeyManager:
+ api_key_doc_manager = TinyMongoDocument("api_db", "api_keys", "key_doc", create=True)
+
+ @classmethod
+ def get_api_key(cls, key: str or ApiProvider):
+ if isinstance(key, ApiProvider):
+ key = key.value
+ return cls.api_key_doc_manager._get(key) or ""
+
+ @classmethod
+ def set_api_key(cls, key: str or ApiProvider, value: str):
+ if isinstance(key, ApiProvider):
+ key = key.value
+ return cls.api_key_doc_manager._save({key: value})
\ No newline at end of file
diff --git a/shortGPT/config/asset_db.py b/shortGPT/config/asset_db.py
new file mode 100644
index 0000000000000000000000000000000000000000..ad8eeb0feb2e9ca951b5269e2848d994aa96300a
--- /dev/null
+++ b/shortGPT/config/asset_db.py
@@ -0,0 +1,340 @@
+import base64
+import re
+import shutil
+import time
+from datetime import datetime
+from pathlib import Path
+import enum
+import pandas as pd
+
+from shortGPT.audio.audio_utils import downloadYoutubeAudio, get_asset_duration
+from shortGPT.database.db_document import TinyMongoDocument
+
+AUDIO_EXTENSIONS = {".mp3", ".m4a", ".wav", ".flac", ".aac", ".ogg", ".wma", ".opus"}
+IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".bmp", ".svg", ".webp"}
+VIDEO_EXTENSIONS = {".mp4", ".mkv", ".flv", ".avi", ".mov", ".wmv", ".webm", ".m4v"}
+TEMPLATE_ASSETS_DB_PATH = '.database/template_asset_db.json'
+ASSETS_DB_PATH = '.database/asset_db.json'
+
+class AssetType(enum.Enum):
+ VIDEO = "video"
+ AUDIO = "audio"
+ IMAGE = "image"
+ BACKGROUND_MUSIC = "background music"
+ BACKGROUND_VIDEO = "background video"
+ OTHER = "other"
+
+class AssetDatabase:
+ """
+ Class for managing assets, both local and remote.
+ The class provides methods to add, remove, get and sync assets.
+ It uses a MongoDB-like database to store information about the assets.
+ """
+
+ if not Path(ASSETS_DB_PATH).exists():
+ shutil.copy(TEMPLATE_ASSETS_DB_PATH, ASSETS_DB_PATH)
+
+ local_assets = TinyMongoDocument("asset_db", "asset_collection", "local_assets", create=True)
+ remote_assets = TinyMongoDocument("asset_db", "asset_collection", "remote_assets", create=True)
+ if not remote_assets._get('subscribe animation'):
+ remote_assets._save({
+ 'subscribe animation':{
+ "type": AssetType.VIDEO.value,
+ "url": "https://www.youtube.com/watch?v=72WhUT0OM98",
+ "ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ }
+ })
+
+ @classmethod
+ def asset_exists(cls, name: str) -> bool:
+ return name in cls.local_assets._get() or name in cls.remote_assets._get()
+
+ @classmethod
+ def add_local_asset(cls, name: str, asset_type: AssetType, path: str):
+ cls.local_assets._save({
+ name: {
+ "type": asset_type.value,
+ "path": path,
+ "ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ }
+ })
+
+ @classmethod
+ def add_remote_asset(cls, name: str, asset_type: AssetType, url: str):
+ cls.remote_assets._save({
+ name: {
+ "type": asset_type.value,
+ "url": url,
+ "ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ }
+ })
+
+ @classmethod
+ def remove_asset(cls, name: str):
+ if name in cls.local_assets._get():
+ cls._remove_local_asset(name)
+ elif name in cls.remote_assets._get():
+ cls.remote_assets._delete(name)
+ else:
+ raise ValueError(f"Asset '{name}' does not exist in the database.")
+
+ @classmethod
+ def get_df(cls, source=None) -> pd.DataFrame:
+ data = []
+ if source is None or source == 'local':
+ for key, asset in cls.local_assets._get().items():
+ data.append({'name': key,
+ 'type': asset['type'],
+ 'link': asset['path'],
+ 'source': 'local',
+ 'ts': asset.get('ts')
+ })
+ if source is None or source == 'youtube':
+ for key, asset in cls.remote_assets._get().items():
+ data.append({'name': key,
+ 'type': asset['type'],
+ 'link': asset['url'],
+ 'source': 'youtube' if 'youtube' in asset['url'] else 'internet',
+ 'ts': asset.get('ts')
+ })
+
+ df = pd.DataFrame(data)
+ if (not df.empty):
+ df.sort_values(by='ts', ascending=False, inplace=True)
+ return df.drop(columns='ts')
+ return df
+
+ @classmethod
+ def sync_local_assets(cls):
+ """
+ Loads all local assets from the static-assets folder into the database.
+ """
+ local_assets = cls.local_assets._get()
+ local_paths = {asset['path'] for asset in local_assets.values()}
+
+ for path in Path('public').rglob('*'):
+ if path.is_file() and str(path) not in local_paths:
+ cls._add_local_asset_from_path(path)
+
+ @classmethod
+ def get_asset_link(cls, key: str) -> str:
+ """
+ Get the link to an asset.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Link to the asset.
+ """
+ if key in cls.local_assets._get():
+ return cls._update_local_asset_timestamp_and_get_link(key)
+ elif key in cls.remote_assets._get():
+ return cls._get_remote_asset_link(key)
+ else:
+ raise ValueError(f"Asset '{key}' does not exist in the database.")
+
+ @classmethod
+ def get_asset_duration(cls, key: str) -> str:
+ """
+ Get the duration of an asset.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Duration of the asset.
+ """
+ if key in cls.local_assets._get():
+ return cls._get_local_asset_duration(key)
+ elif key in cls.remote_assets._get():
+ return cls._get_remote_asset_duration(key)
+ else:
+ raise ValueError(f"Asset '{key}' does not exist in the database.")
+
+ @classmethod
+ def _remove_local_asset(cls, name: str):
+ """
+ Remove a local asset from the database.
+
+ Args:
+ name (str): Name of the asset.
+ """
+ asset = cls.local_assets._get(name)
+ if 'required' not in asset:
+ try:
+ Path(asset['path']).unlink()
+ except FileNotFoundError as e:
+ print(f"File not found: {e}")
+ cls.local_assets._delete(name)
+
+ @classmethod
+ def _add_local_asset_from_path(cls, path: Path):
+ """
+ Add a local asset to the database from a file path.
+
+ Args:
+ path (Path): Path to the asset.
+ """
+ file_ext = path.suffix
+ if file_ext in AUDIO_EXTENSIONS:
+ asset_type = AssetType.AUDIO
+ elif file_ext in IMAGE_EXTENSIONS:
+ asset_type = AssetType.IMAGE
+ elif file_ext in VIDEO_EXTENSIONS:
+ asset_type = AssetType.VIDEO
+ else:
+ asset_type = AssetType.OTHER
+ cls.local_assets._save({
+ path.stem: {
+ "path": str(path),
+ "type": asset_type.value,
+ "ts": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ }
+ })
+
+ @classmethod
+ def _update_local_asset_timestamp_and_get_link(cls, key: str) -> str:
+ """
+ Update the timestamp of a local asset and get its link.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Link to the asset.
+ """
+ asset = cls.local_assets._get(key)
+ asset['ts'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ cls.local_assets._save({key: asset})
+ return asset['path']
+
+ @classmethod
+ def _get_remote_asset_link(cls, key: str) -> str:
+ """
+ Get the link to a remote asset.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Link to the asset.
+ """
+ asset = cls.remote_assets._get(key)
+ asset['ts'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ cls.remote_assets._save({key: asset})
+ if 'youtube' in asset['url']:
+ return cls._get_youtube_asset_link(key, asset)
+ return asset['url']
+
+ @classmethod
+ def _get_local_asset_duration(cls, key: str) -> str:
+ """
+ Get the duration of a local asset.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Duration of the asset.
+ """
+ asset = cls.local_assets._get(key)
+ asset['ts'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ cls.local_assets._save({key: asset})
+ if 'duration' not in asset:
+ _, duration = cls._update_local_asset_duration(key)
+ return duration
+ return asset['duration']
+
+ @classmethod
+ def _get_remote_asset_duration(cls, key: str) -> str:
+ """
+ Get the duration of a remote asset.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Duration of the asset.
+ """
+ asset = cls.remote_assets._get(key)
+ asset['ts'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ cls.remote_assets._save({key: asset})
+ if 'duration' in asset:
+ return asset['duration']
+ _, duration = cls._update_youtube_asset_duration(key)
+ return duration
+
+ @classmethod
+ def _update_local_asset_duration(cls, key: str) -> str:
+ """
+ Update the duration of a local asset.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Duration of the asset.
+ """
+ asset = cls.local_assets._get(key)
+ path = Path(asset['path'])
+ if any(t in asset['type'] for t in ['audio', 'video', 'music']):
+ _, duration = get_asset_duration(str(path))
+ asset['duration'] = duration
+ else:
+ duration = None
+ cls.local_assets._save({key: asset})
+ return str(path), duration
+
+ @classmethod
+ def _update_youtube_asset_duration(cls, key: str) -> str:
+ """
+ Update the duration of a Youtube asset.
+
+ Args:
+ key (str): Name of the asset.
+
+ Returns:
+ str: Duration of the asset.
+ """
+ asset = cls.remote_assets._get(key)
+ youtube_url = asset['url']
+ remote_url, duration = get_asset_duration(youtube_url, isVideo="video" in asset['type'])
+ asset.update({
+ "remote_url": base64.b64encode(remote_url.encode()).decode('utf-8'),
+ "duration": duration,
+ })
+ cls.remote_assets._save({key: asset})
+ return remote_url, duration
+
+ @classmethod
+ def _get_youtube_asset_link(cls, key: str, asset: dict) -> str:
+ """
+ Get the link to a Youtube asset.
+
+ Args:
+ key (str): Name of the asset.
+ asset (dict): Asset data.
+
+ Returns:
+ str: Link to the asset.
+ """
+ if any(t in asset['type'] for t in ['audio', 'music']):
+ local_audio_file, duration = downloadYoutubeAudio(asset['url'], f"public/{key}.wav")
+ cls.local_assets._save({
+ key: {
+ 'path': local_audio_file,
+ 'duration': duration,
+ 'type': 'audio',
+ 'ts': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+ }
+ })
+ return local_audio_file
+ if 'remote_url' in asset:
+ asset['remote_url'] = base64.b64decode(asset['remote_url']).decode('utf-8')
+ expire_timestamp_match = re.search(r"expire=(\d+)", asset['remote_url'])
+ not_expired = expire_timestamp_match and int(expire_timestamp_match.group(1)) > time.time() + 1800
+ if not_expired and 'duration' in asset:
+ return asset['remote_url']
+ remote_url, _ = cls._update_youtube_asset_duration(key)
+ return remote_url
diff --git a/shortGPT/config/config.py b/shortGPT/config/config.py
new file mode 100644
index 0000000000000000000000000000000000000000..1cc9d2af4fe14dbb2fd7a929f59f907e3e400742
--- /dev/null
+++ b/shortGPT/config/config.py
@@ -0,0 +1,58 @@
+import yaml
+import os
+from dotenv import load_dotenv
+
+load_dotenv()
+
+ELEVEN_LABS_KEY = os.getenv('ELEVEN_LABS_API_KEY')
+OPENAI_KEY = os.getenv('OPENAI_API_KEY')
+PLAY_HT_USERID = os.getenv('PLAY_HT_USERID')
+PLAY_HT_API_KEY = os.getenv('PLAY_HT_API_KEY')
+
+
+def read_yaml_config(file_path: str) -> dict:
+ """Reads and returns the contents of a YAML file as dictionary"""
+ with open(file_path, 'r') as file:
+ contents = yaml.safe_load(file)
+ return contents
+
+def write_yaml_config(file_path: str, data: dict):
+ """Writes a dictionary to a YAML file"""
+ with open(file_path, 'w') as file:
+ yaml.dump(data, file)
+
+def load_editing_assets() -> dict:
+ """Loads all local assets from the static-assets folder specified in the yaml_config"""
+ yaml_config = read_yaml_config("public.yaml")
+ if yaml_config['local-assets'] == None:
+ yaml_config['local-assets'] = {}
+ # Create a copy of the dictionary before iterating over it
+ local_paths = []
+ if yaml_config['local-assets'] != {}:
+ local_assets = yaml_config['local-assets'].copy()
+ # Removing local paths that don't exist
+ for key in local_assets:
+ asset = local_assets[key]
+ if(type(asset) == str):
+ filePath = local_assets[key]
+ else:
+ filePath = local_assets[key]['path']
+ if not os.path.exists(filePath):
+ del yaml_config['local-assets'][key]
+ else:
+ local_paths.append(filePath)
+
+ folder_path = 'public'
+ for foldername, subfolders, filenames in os.walk(folder_path):
+ for filename in filenames:
+ file_path = os.path.join(foldername, filename).replace("\\", "/")
+ if not file_path in local_paths:
+ yaml_config['local-assets'][filename] = file_path
+
+ write_yaml_config("public.yaml", yaml_config)
+
+ return yaml_config
+
+
+# print(load_editing_assets())
+# print(read_yaml_config("editing_assets.yaml")['local-assets'])
diff --git a/shortGPT/config/languages.py b/shortGPT/config/languages.py
new file mode 100644
index 0000000000000000000000000000000000000000..362813042c45b5f53cf682a6c5bbcbdb8fcb2026
--- /dev/null
+++ b/shortGPT/config/languages.py
@@ -0,0 +1,246 @@
+
+from enum import Enum
+
+class Language(Enum):
+ ENGLISH = "English"
+ SPANISH = "Spanish"
+ FRENCH = "French"
+ ARABIC = "Arabic"
+ GERMAN = "German"
+ POLISH = "Polish"
+ ITALIAN = "Italian"
+ PORTUGUESE = "Portuguese"
+ AFRIKAANS = "Afrikaans"
+ AMHARIC = "Amharic"
+ AZERBAIJANI = "Azerbaijani"
+ BULGARIAN = "Bulgarian"
+ BENGALI = "Bengali"
+ BOSNIAN = "Bosnian"
+ CATALAN = "Catalan"
+ CZECH = "Czech"
+ WELSH = "Welsh"
+ DANISH = "Danish"
+ GREEK = "Greek"
+ ESTONIAN = "Estonian"
+ PERSIAN = "Persian"
+ FINNISH = "Finnish"
+ FILIPINO = "Filipino"
+ GALICIAN = "Galician"
+ GUJARATI = "Gujarati"
+ HEBREW = "Hebrew"
+ HINDI = "Hindi"
+ CROATIAN = "Croatian"
+ HUNGARIAN = "Hungarian"
+ INDONESIAN = "Indonesian"
+ ICELANDIC = "Icelandic"
+ JAPANESE = "Japanese"
+ JAVANESE = "Javanese"
+ GEORGIAN = "Georgian"
+ KAZAKH = "Kazakh"
+ KHMER = "Khmer"
+ KANNADA = "Kannada"
+ KOREAN = "Korean"
+ LAO = "Lao"
+ LITHUANIAN = "Lithuanian"
+ LATVIAN = "Latvian"
+ MACEDONIAN = "Macedonian"
+ MALAYALAM = "Malayalam"
+ MONGOLIAN = "Mongolian"
+ MARATHI = "Marathi"
+ MALAY = "Malay"
+ MALTESE = "Maltese"
+ MYANMAR = "Myanmar"
+ NORWEGIAN = "Norwegian"
+ NEPALI = "Nepali"
+ DUTCH = "Dutch"
+ NORWEGIAN_BOKMAL = "Norwegian Bokmรฅl"
+ NORWEGIAN_NYNORSK = "Norwegian Nynorsk"
+ PASHTO = "Pashto"
+ ROMANIAN = "Romanian"
+ RUSSIAN = "Russian"
+ SINHALA = "Sinhala"
+ SLOVAK = "Slovak"
+ SLOVENIAN = "Slovenian"
+ SOMALI = "Somali"
+ ALBANIAN = "Albanian"
+ SERBIAN = "Serbian"
+ SUNDANESE = "Sundanese"
+ SWEDISH = "Swedish"
+ SWAHILI = "Swahili"
+ TAMIL = "Tamil"
+ TELUGU = "Telugu"
+ THAI = "Thai"
+ TURKISH = "Turkish"
+ UKRAINIAN = "Ukrainian"
+ URDU = "Urdu"
+ UZBEK = "Uzbek"
+ VIETNAMESE = "Vietnamese"
+ CHINESE = "Chinese"
+ ZULU = "Zulu"
+
+ELEVEN_SUPPORTED_LANGUAGES=[Language.ENGLISH,
+ Language.SPANISH,
+ Language.FRENCH,
+ Language.ARABIC,
+ Language.GERMAN,
+ Language.POLISH,
+ Language.ITALIAN,
+ Language.PORTUGUESE]
+
+LANGUAGE_ACRONYM_MAPPING={
+ Language.ENGLISH : "en",
+ Language.SPANISH : "es",
+ Language.FRENCH : "fr",
+ Language.ARABIC : "ar",
+ Language.GERMAN : "de",
+ Language.POLISH : "pl",
+ Language.ITALIAN : "it",
+ Language.PORTUGUESE : "pt",
+ Language.AFRIKAANS : "af",
+ Language.AMHARIC : "am",
+ Language.AZERBAIJANI : "az",
+ Language.BULGARIAN : "bg",
+ Language.BENGALI : "bn",
+ Language.BOSNIAN : "bs",
+ Language.CATALAN : "ca",
+ Language.CZECH : "cs",
+ Language.WELSH : "cy",
+ Language.DANISH : "da",
+ Language.GREEK : "el",
+ Language.ESTONIAN : "et",
+ Language.PERSIAN : "fa",
+ Language.FINNISH : "fi",
+ Language.FILIPINO : "fil",
+ Language.GALICIAN : "gl",
+ Language.GUJARATI : "gu",
+ Language.HEBREW : "he",
+ Language.HINDI : "hi",
+ Language.CROATIAN : "hr",
+ Language.HUNGARIAN : "hu",
+ Language.INDONESIAN : "id",
+ Language.ICELANDIC : "is",
+ Language.JAPANESE : "ja",
+ Language.JAVANESE : "jv",
+ Language.GEORGIAN : "ka",
+ Language.KAZAKH : "kk",
+ Language.KHMER : "km",
+ Language.KANNADA : "kn",
+ Language.KOREAN : "ko",
+ Language.LAO : "lo",
+ Language.LITHUANIAN : "lt",
+ Language.LATVIAN : "lv",
+ Language.MACEDONIAN : "mk",
+ Language.MALAYALAM : "ml",
+ Language.MONGOLIAN : "mn",
+ Language.MARATHI : "mr",
+ Language.MALAY : "ms",
+ Language.MALTESE : "mt",
+ Language.MYANMAR : "my",
+ Language.NORWEGIAN : "no",
+ Language.NEPALI : "ne",
+ Language.DUTCH : "nl",
+ Language.NORWEGIAN_BOKMAL : "nb",
+ Language.NORWEGIAN_NYNORSK : "nn",
+ Language.PASHTO : "ps",
+ Language.ROMANIAN : "ro",
+ Language.RUSSIAN : "ru",
+ Language.SINHALA : "si",
+ Language.SLOVAK : "sk",
+ Language.SLOVENIAN : "sl",
+ Language.SOMALI : "so",
+ Language.ALBANIAN : "sq",
+ Language.SERBIAN : "sr",
+ Language.SUNDANESE : "su",
+ Language.SWEDISH : "sv",
+ Language.SWAHILI : "sw",
+ Language.TAMIL : "ta",
+ Language.TELUGU : "te",
+ Language.THAI : "th",
+ Language.TURKISH : "tr",
+ Language.UKRAINIAN : "uk",
+ Language.URDU : "ur",
+ Language.UZBEK : "uz",
+ Language.VIETNAMESE : "vi",
+ Language.CHINESE : "zh",
+ Language.ZULU : "zu",
+}
+ACRONYM_LANGUAGE_MAPPING = {v: k for k, v in LANGUAGE_ACRONYM_MAPPING.items()}
+
+EDGE_TTS_VOICENAME_MAPPING = {
+ Language.ENGLISH: {'male': 'en-AU-WilliamNeural', 'female': 'en-AU-NatashaNeural'},
+ Language.SPANISH: {'male': 'es-AR-TomasNeural', 'female': 'es-AR-ElenaNeural'},
+ Language.FRENCH: {'male': 'fr-CA-AntoineNeural', 'female': 'fr-CA-SylvieNeural'},
+ Language.ARABIC: {'male': 'ar-AE-HamdanNeural', 'female': 'ar-AE-FatimaNeural'},
+ Language.GERMAN: {'male': 'de-DE-ConradNeural', 'female': 'de-DE-KatjaNeural'},
+ Language.POLISH: {'male': 'pl-PL-MarekNeural', 'female': 'pl-PL-ZofiaNeural'},
+ Language.ITALIAN: {'male': 'it-IT-DiegoNeural', 'female': 'it-IT-ElsaNeural'},
+ Language.PORTUGUESE: {'male': 'pt-BR-AntonioNeural', 'female': 'pt-BR-FranciscaNeural'},
+ Language.AFRIKAANS: {'male': 'af-ZA-WillemNeural', 'female': 'af-ZA-AdriNeural'},
+ Language.AMHARIC: {'male': 'am-ET-AmehaNeural', 'female': 'am-ET-MekdesNeural'},
+ Language.AZERBAIJANI: {'male': 'az-AZ-BabekNeural', 'female': 'az-AZ-BanuNeural'},
+ Language.BULGARIAN: {'male': 'bg-BG-BorislavNeural', 'female': 'bg-BG-KalinaNeural'},
+ Language.BENGALI: {'male': 'bn-BD-PradeepNeural', 'female': 'bn-BD-NabanitaNeural'},
+ Language.BOSNIAN: {'male': 'bs-BA-GoranNeural', 'female': 'bs-BA-VesnaNeural'},
+ Language.CATALAN: {'male': 'ca-ES-EnricNeural', 'female': 'ca-ES-JoanaNeural'},
+ Language.CZECH: {'male': 'cs-CZ-AntoninNeural', 'female': 'cs-CZ-VlastaNeural'},
+ Language.WELSH: {'male': 'cy-GB-AledNeural', 'female': 'cy-GB-NiaNeural'},
+ Language.DANISH: {'male': 'da-DK-JeppeNeural', 'female': 'da-DK-ChristelNeural'},
+ Language.GREEK: {'male': 'el-GR-NestorasNeural', 'female': 'el-GR-AthinaNeural'},
+ Language.ESTONIAN: {'male': 'et-EE-KertNeural', 'female': 'et-EE-AnuNeural'},
+ Language.PERSIAN: {'male': 'fa-IR-FaridNeural', 'female': 'fa-IR-DilaraNeural'},
+ Language.FINNISH: {'male': 'fi-FI-HarriNeural', 'female': 'fi-FI-NooraNeural'},
+ Language.FILIPINO: {'male': 'fil-PH-AngeloNeural', 'female': 'fil-PH-BlessicaNeural'},
+ Language.GALICIAN: {'male': 'gl-ES-RoiNeural', 'female': 'gl-ES-SabelaNeural'},
+ Language.GUJARATI: {'male': 'gu-IN-NiranjanNeural', 'female': 'gu-IN-DhwaniNeural'},
+ Language.HEBREW: {'male': 'he-IL-AvriNeural', 'female': 'he-IL-HilaNeural'},
+ Language.HINDI: {'male': 'hi-IN-MadhurNeural', 'female': 'hi-IN-SwaraNeural'},
+ Language.CROATIAN: {'male': 'hr-HR-SreckoNeural', 'female': 'hr-HR-GabrijelaNeural'},
+ Language.HUNGARIAN: {'male': 'hu-HU-TamasNeural', 'female': 'hu-HU-NoemiNeural'},
+ Language.INDONESIAN: {'male': 'id-ID-ArdiNeural', 'female': 'id-ID-GadisNeural'},
+ Language.ICELANDIC: {'male': 'is-IS-GunnarNeural', 'female': 'is-IS-GudrunNeural'},
+ Language.ITALIAN: {'male': 'it-IT-DiegoNeural', 'female': 'it-IT-ElsaNeural'},
+ Language.JAPANESE: {'male': 'ja-JP-KeitaNeural', 'female': 'ja-JP-NanamiNeural'},
+ Language.JAVANESE: {'male': 'jv-ID-DimasNeural', 'female': 'jv-ID-SitiNeural'},
+ Language.GEORGIAN: {'male': 'ka-GE-GiorgiNeural', 'female': 'ka-GE-EkaNeural'},
+ Language.KAZAKH: {'male': 'kk-KZ-DauletNeural', 'female': 'kk-KZ-AigulNeural'},
+ Language.KHMER: {'male': 'km-KH-PisethNeural', 'female': 'km-KH-SreymomNeural'},
+ Language.KANNADA: {'male': 'kn-IN-GaganNeural', 'female': 'kn-IN-SapnaNeural'},
+ Language.KOREAN: {'male': 'ko-KR-InJoonNeural', 'female': 'ko-KR-SunHiNeural'},
+ Language.LAO: {'male': 'lo-LA-KeomanyNeural', 'female': 'lo-LA-ChanthavongNeural'},
+ Language.LITHUANIAN: {'male': 'lt-LT-LeonasNeural', 'female': 'lt-LT-OnaNeural'},
+ Language.LATVIAN: {'male': 'lv-LV-NilsNeural', 'female': 'lv-LV-EveritaNeural'},
+ Language.MACEDONIAN: {'male': 'mk-MK-AleksandarNeural', 'female': 'mk-MK-MarijaNeural'},
+ Language.MALAYALAM: {'male': 'ml-IN-MidhunNeural', 'female': 'ml-IN-MidhunNeural'},
+ Language.MONGOLIAN: {'male': 'mn-MN-YesuiNeural', 'female': 'mn-MN-BataaNeural'},
+ Language.MARATHI: {'male': 'mr-IN-ManoharNeural', 'female': 'mr-IN-AarohiNeural'},
+ Language.MALAY: {'male': 'ms-MY-OsmanNeural', 'female': 'ms-MY-YasminNeural'},
+ Language.MALTESE: {'male': 'mt-MT-JosephNeural', 'female': 'mt-MT-GraceNeural'},
+ Language.MYANMAR: {'male': 'my-MM-ThihaNeural', 'female': 'my-MM-NilarNeural'},
+ Language.NORWEGIAN: {'male': 'nb-NO-FinnNeural', 'female': 'nb-NO-PernilleNeural'},
+ Language.NEPALI: {'male': 'ne-NP-SagarNeural', 'female': 'ne-NP-HemkalaNeural'},
+ Language.DUTCH: {'male': 'nl-NL-MaartenNeural', 'female': 'nl-NL-FennaNeural'},
+ Language.NORWEGIAN_BOKMAL: {'male': 'nb-NO-FinnNeural', 'female': 'nb-NO-PernilleNeural'},
+ Language.NORWEGIAN_NYNORSK: {'male': 'nb-NO-FinnNeural', 'female': 'nb-NO-PernilleNeural'},
+ Language.PASHTO: {'male': 'ps-AF-LatifaNeural', 'female': 'ps-AF-GulNawazNeural'},
+ Language.ROMANIAN: {'male': 'ro-RO-EmilNeural', 'female': 'ro-RO-AlinaNeural'},
+ Language.RUSSIAN: {'male': 'ru-RU-DmitryNeural', 'female': 'ru-RU-SvetlanaNeural'},
+ Language.SINHALA: {'male': 'si-LK-SameeraNeural', 'female': 'si-LK-ThiliniNeural'},
+ Language.SLOVAK: {'male': 'sk-SK-LukasNeural', 'female': 'sk-SK-ViktoriaNeural'},
+ Language.SLOVENIAN: {'male': 'sl-SI-RokNeural', 'female': 'sl-SI-PetraNeural'},
+ Language.SOMALI: {'male': 'so-SO-MuuseNeural', 'female': 'so-SO-UbaxNeural'},
+ Language.ALBANIAN: {'male': 'sq-AL-IlirNeural', 'female': 'sq-AL-AnilaNeural'},
+ Language.SERBIAN: {'male': 'sr-RS-NicholasNeural', 'female': 'sr-RS-SophieNeural'},
+ Language.SUNDANESE: {'male': 'su-ID-JajangNeural', 'female': 'su-ID-TutiNeural'},
+ Language.SWEDISH: {'male': 'sv-SE-MattiasNeural', 'female': 'sv-SE-SofieNeural'},
+ Language.SWAHILI: {'male': 'sw-TZ-DaudiNeural', 'female': 'sw-TZ-DaudiNeural'},
+ Language.TAMIL: {'male': 'ta-IN-ValluvarNeural', 'female': 'ta-IN-PallaviNeural'},
+ Language.TELUGU: {'male': 'te-IN-MohanNeural', 'female': 'te-IN-ShrutiNeural'},
+ Language.THAI: {'male': 'th-TH-NiwatNeural', 'female': 'th-TH-PremwadeeNeural'},
+ Language.TURKISH: {'male': 'tr-TR-AhmetNeural', 'female': 'tr-TR-EmelNeural'},
+ Language.UKRAINIAN: {'male': 'uk-UA-OstapNeural', 'female': 'uk-UA-PolinaNeural'},
+ Language.URDU: {'male': 'ur-PK-AsadNeural', 'female': 'ur-PK-UzmaNeural'},
+ Language.UZBEK: {'male': 'uz-UZ-SardorNeural', 'female': 'uz-UZ-MadinaNeural'},
+ Language.VIETNAMESE: {'male': 'vi-VN-NamMinhNeural', 'female': 'vi-VN-HoaiMyNeural'},
+ Language.CHINESE: {'male': 'zh-CN-YunxiNeural', 'female': 'zh-CN-XiaoxiaoNeural'},
+ Language.ZULU: {'male': 'zu-ZA-ThembaNeural', 'female': 'zu-ZA-ThandoNeural'}
+}
\ No newline at end of file
diff --git a/shortGPT/config/path_utils.py b/shortGPT/config/path_utils.py
new file mode 100644
index 0000000000000000000000000000000000000000..a027be8ca4cade9dfe20c883347232397fb7e89a
--- /dev/null
+++ b/shortGPT/config/path_utils.py
@@ -0,0 +1,36 @@
+import os
+import platform
+import sys
+import subprocess
+import subprocess
+import tempfile
+def search_program(program_name):
+ try:
+ search_cmd = "where" if platform.system() == "Windows" else "which"
+ return subprocess.check_output([search_cmd, program_name]).decode().strip()
+ except subprocess.CalledProcessError:
+ return None
+
+def get_program_path(program_name):
+ program_path = search_program(program_name)
+ return program_path
+
+magick_path = get_program_path("magick")
+if magick_path:
+ os.environ['IMAGEMAGICK_BINARY'] = magick_path
+
+import os
+
+def is_running_in_colab():
+ return 'COLAB_GPU' in os.environ
+
+def handle_path(path, extension = ".mp4"):
+ if 'https' in path:
+ if is_running_in_colab():
+ temp_file = tempfile.NamedTemporaryFile(suffix= extension, delete=False)
+ # The '-y' option overwrites the output file if it already exists.
+ command = ['ffmpeg', '-y', '-i', path, temp_file.name]
+ subprocess.run(command, check=True)
+ temp_file.close()
+ return temp_file.name
+ return path
\ No newline at end of file
diff --git a/shortGPT/database/README.md b/shortGPT/database/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..4fc3dd05efa2bda14f23dca4f2e4fae54fb7fc46
--- /dev/null
+++ b/shortGPT/database/README.md
@@ -0,0 +1,147 @@
+# Database Module Documentation
+
+The `database` module provides classes for managing database documents and data in the ShortGPT application. The module consists of three files:
+
+- `content_data_manager.py`: Defines the `ContentDataManager` class, which manages the content data for a document in the database.
+- `content_database.py`: Defines the `ContentDatabase` class, which provides methods for creating and accessing `ContentDataManager` instances.
+- `db_document.py`: Defines the `DatabaseDocument` abstract base class and the `TinyMongoDocument` class, which represents a document in a TinyMongo database.
+
+## File: content_data_manager.py
+
+The `content_data_manager.py` file contains the `ContentDataManager` class, which is responsible for managing the content data for a document in the database.
+
+### Class: ContentDataManager
+
+#### `__init__(self, db_doc: DatabaseDocument, content_type: str, new=False)`
+
+- Initializes a new instance of the `ContentDataManager` class.
+- Parameters:
+ - `db_doc`: The `DatabaseDocument` instance representing the document in the database.
+ - `content_type`: The type of content to be managed by the `ContentDataManager`.
+ - `new`: (Optional) A boolean flag indicating whether the document is new or existing. Default is `False`.
+
+#### `save(self, key, value)`
+
+- Saves the specified key-value pair to the document.
+- Parameters:
+ - `key`: The key of the data to be saved.
+ - `value`: The value of the data to be saved.
+
+#### `get(self, key)`
+
+- Retrieves the value associated with the specified key from the document.
+- Parameters:
+ - `key`: The key of the data to be retrieved.
+- Returns:
+ - The value associated with the specified key.
+
+#### `_getId(self)`
+
+- Retrieves the ID of the document.
+- Returns:
+ - The ID of the document.
+
+#### `delete(self)`
+
+- Deletes the document from the database.
+
+#### `__str__(self)`
+
+- Returns a string representation of the document.
+
+## File: content_database.py
+
+The `content_database.py` file contains the `ContentDatabase` class, which provides methods for creating and accessing `ContentDataManager` instances.
+
+### Class: ContentDatabase
+
+#### `instanciateContentDataManager(self, id: str, content_type: str, new=False)`
+
+- Creates a new `ContentDataManager` instance for the specified document ID and content type.
+- Parameters:
+ - `id`: The ID of the document.
+ - `content_type`: The type of content to be managed by the `ContentDataManager`.
+ - `new`: (Optional) A boolean flag indicating whether the document is new or existing. Default is `False`.
+- Returns:
+ - A new `ContentDataManager` instance.
+
+#### `getContentDataManager(self, id, content_type: str)`
+
+- Retrieves an existing `ContentDataManager` instance for the specified document ID and content type.
+- Parameters:
+ - `id`: The ID of the document.
+ - `content_type`: The type of content to be managed by the `ContentDataManager`.
+- Returns:
+ - The existing `ContentDataManager` instance, or `None` if not found.
+
+#### `createContentDataManager(self, content_type: str) -> ContentDataManager`
+
+- Creates a new `ContentDataManager` instance for a new document with the specified content type.
+- Parameters:
+ - `content_type`: The type of content to be managed by the `ContentDataManager`.
+- Returns:
+ - A new `ContentDataManager` instance.
+
+## File: db_document.py
+
+The `db_document.py` file contains the `DatabaseDocument` abstract base class and the `TinyMongoDocument` class, which represents a document in a TinyMongo database.
+
+### Abstract Class: DatabaseDocument
+
+- An abstract base class that defines the interface for a database document.
+- Subclasses must implement the abstract methods:
+ - `_save(self, key, data)`
+ - `_get(self, key)`
+ - `_getId(self)`
+ - `__str__(self)`
+ - `_delete(self)`
+
+### Class: TinyMongoDocument
+
+- Represents a document in a TinyMongo database.
+- Inherits from the `DatabaseDocument` abstract base class.
+
+#### `__init__(self, db_name: str, collection_name: str, document_id: str, create=False)`
+
+- Initializes a new instance of the `TinyMongoDocument` class.
+- Parameters:
+ - `db_name`: The name of the database.
+ - `collection_name`: The name of the collection.
+ - `document_id`: The ID of the document.
+ - `create`: (Optional) A boolean flag indicating whether to create the document if it doesn't exist. Default is `False`.
+
+#### `exists(self)`
+
+- Checks if the document exists in the database.
+- Returns:
+ - `True` if the document exists, `False` otherwise.
+
+#### `_save(self, data)`
+
+- Saves the specified data to the document.
+- Parameters:
+ - `data`: The data to be saved.
+
+#### `_get(self, key=None)`
+
+- Retrieves the value associated with the specified key from the document.
+- Parameters:
+ - `key`: (Optional) The key of the data to be retrieved. If not specified, returns the entire document.
+- Returns:
+ - The value associated with the specified key, or the entire document if no key is specified.
+
+#### `_delete(self, key)`
+
+- Deletes the specified key from the document.
+- Parameters:
+ - `key`: The key to be deleted.
+
+#### `_getId(self)`
+
+- Retrieves the ID of the document.
+- Returns:
+ - The ID of the document.
+
+#### `__str__(self)`
+
+- Returns a string representation of the document.
\ No newline at end of file
diff --git a/shortGPT/database/__init__.py b/shortGPT/database/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/shortGPT/database/content_data_manager.py b/shortGPT/database/content_data_manager.py
new file mode 100644
index 0000000000000000000000000000000000000000..bd984975e8c0d9b7d4a325caaa2e83ecbdebbd3b
--- /dev/null
+++ b/shortGPT/database/content_data_manager.py
@@ -0,0 +1,29 @@
+from shortGPT.database.db_document import AbstractDatabaseDocument
+
+
+class ContentDataManager():
+
+ def __init__(self, db_doc: AbstractDatabaseDocument, content_type: str, new=False):
+ self.contentType = content_type
+ self.db_doc = db_doc
+ if new:
+ self.db_doc._save({
+ 'content_type': content_type,
+ 'ready_to_upload': False,
+ 'last_completed_step': 0,
+ })
+
+ def save(self, key, value):
+ self.db_doc._save({key: value})
+
+ def get(self, key):
+ return self.db_doc._get(key)
+
+ def _getId(self):
+ return self.db_doc._getId()
+
+ def delete(self):
+ self.db_doc.delete()
+
+ def __str__(self):
+ return self.db_doc.__str__()
diff --git a/shortGPT/database/content_database.py b/shortGPT/database/content_database.py
new file mode 100644
index 0000000000000000000000000000000000000000..b892db5660ed3040637e6dcb7cf43481e0e677c5
--- /dev/null
+++ b/shortGPT/database/content_database.py
@@ -0,0 +1,28 @@
+from uuid import uuid4
+from shortGPT.database.db_document import TINY_MONGO_DATABASE, TinyMongoDocument
+
+from shortGPT.database.content_data_manager import ContentDataManager
+class ContentDatabase:
+ def __init__(self, ):
+ self.content_collection = TINY_MONGO_DATABASE["content_db"]["content_documents"]
+
+ def instanciateContentDataManager(self, id: str, content_type: str, new=False):
+ db_doc = TinyMongoDocument("content_db", "content_documents", id)
+ return ContentDataManager(db_doc, content_type, new)
+
+ def getContentDataManager(self, id, content_type: str):
+ try:
+ db_doc = TinyMongoDocument("content_db", "content_documents", id)
+ return ContentDataManager(db_doc, content_type, False)
+ except:
+ return None
+
+ def createContentDataManager(self, content_type: str) -> ContentDataManager:
+ try:
+ new_short_id = uuid4().hex[:24]
+ db_doc = TinyMongoDocument("content_db", "content_documents", new_short_id, True)
+ return ContentDataManager(db_doc, content_type, True)
+ except:
+ return None
+
+
\ No newline at end of file
diff --git a/shortGPT/database/db_document.py b/shortGPT/database/db_document.py
new file mode 100644
index 0000000000000000000000000000000000000000..ad6943a2cbab16c2df27b8c8423a3a80a7b08c22
--- /dev/null
+++ b/shortGPT/database/db_document.py
@@ -0,0 +1,119 @@
+import threading
+from abc import ABC, abstractmethod
+
+import tinydb
+import tinymongo as tm
+
+
+class AbstractDatabaseDocument(ABC):
+
+ @abstractmethod
+ def _save(self, key, data):
+ '''Save the data in the database'''
+ pass
+
+ @abstractmethod
+ def _get(self, key):
+ '''Get the data from the database'''
+ pass
+
+ @abstractmethod
+ def _getId(self):
+ '''Get the id of the document'''
+ pass
+
+ @abstractmethod
+ def __str__(self):
+ '''Return the string representation of the document'''
+ pass
+
+ @abstractmethod
+ def _delete(self):
+ '''Delete the document'''
+ pass
+
+
+class TinyMongoClient(tm.TinyMongoClient):
+ @property
+ def _storage(self):
+ return tinydb.storages.JSONStorage
+
+
+TINY_MONGO_DATABASE = TinyMongoClient("./.database")
+
+
+class TinyMongoDocument(AbstractDatabaseDocument):
+ _lock = threading.Lock()
+
+ def __init__(self, db_name: str, collection_name: str, document_id: str, create=False):
+ self.collection = TINY_MONGO_DATABASE[db_name][collection_name]
+ self.collection_name = collection_name
+ self.document_id = document_id
+ if (not self.exists()):
+ if create:
+ self.collection.insert_one({"_id": document_id})
+ else:
+ raise Exception(f"The document with id {document_id} in collection {collection_name} of database {db_name} does not exist")
+
+ def exists(self):
+ with self._lock:
+ return self.collection.find({"_id": self.document_id}).count() == 1
+
+ def _save(self, data):
+ with self._lock:
+ try:
+ update_data = {'$set': {}}
+ for key, value in data.items():
+ path_parts = key.split(".")
+
+ if len(path_parts) > 1:
+ root_key = ".".join(path_parts[:-1])
+ last_key = path_parts[-1]
+ current_value = self._get(root_key)
+ if not isinstance(current_value, dict):
+ current_value = {}
+ current_value[last_key] = value
+ update_data['$set'][root_key] = current_value
+ else:
+ update_data['$set'][key] = value
+
+ self.collection.update_one({'_id': self.document_id}, update_data)
+ except Exception as e:
+ print(f"Error saving data: {e}")
+
+ def _get(self, key=None):
+ with self._lock:
+ try:
+ document = self.collection.find_one({'_id': self.document_id})
+ if not key:
+ del document['_id']
+ return document
+ keys = key.split(".")
+ value = document[keys[0]]
+ for k in keys[1:]:
+ value = value[k]
+ return value
+ except Exception as e:
+ #print(f"Error getting value for key '{key}': {e}")
+ return None
+
+ def _delete(self, key):
+ with self._lock:
+ try:
+ document = self.collection.find_one({'_id': self.document_id})
+ if key in document:
+ del document[key]
+ self.collection.remove({'_id': self.document_id})
+ self.collection.insert(document)
+ else:
+ print(f"Key '{key}' not found in the document")
+ except Exception as e:
+ print(f"Error deleting key '{key}': {e}")
+
+ def _getId(self):
+ return self.document_id
+
+ def __str__(self):
+ with self._lock:
+ document = self.collection.find_one({'_id': self.document_id})
+ return str(document)
diff --git a/shortGPT/editing_framework/README.md b/shortGPT/editing_framework/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..c0cc0038a18320c6995dc92bacf5e4ac89f42145
--- /dev/null
+++ b/shortGPT/editing_framework/README.md
@@ -0,0 +1,182 @@
+# Editing Framework Module Documentation
+
+The `editing_framework` module provides a set of classes and functions for editing videos and images. This module is part of the `shortGPT` project and is designed to be used with the `CoreEditingEngine` class to generate videos and images based on a specified editing schema.
+
+## Module Files
+
+The `editing_framework` module consists of three files:
+
+1. `rendering_logger.py`: This file contains the `MoviepyProgressLogger` class, which is used for logging the progress of the rendering process.
+2. `editing_engine.py`: This file contains the `EditingStep` and `Flow` enums, as well as the `EditingEngine` class, which is the main class for managing the editing process.
+3. `core_editing_engine.py`: This file contains the `CoreEditingEngine` class, which is responsible for generating videos and images based on the editing schema.
+
+## `rendering_logger.py`
+
+This file defines the `MoviepyProgressLogger` class, which is a subclass of `ProgressBarLogger` from the `proglog` module. It provides a callback function for logging the progress of the rendering process. The `MoviepyProgressLogger` class has the following methods:
+
+### `__init__(self, callBackFunction=None)`
+
+- Initializes a new instance of the `MoviepyProgressLogger` class.
+- Parameters:
+ - `callBackFunction`: An optional callback function that will be called with the progress string.
+
+### `bars_callback(self, bar, attr, value, old_value=None)`
+
+- This method is called every time the logger progress is updated.
+- It calculates the rendering progress and the estimated time left.
+- It calls the callback function with the progress string or prints the progress string if no callback function is provided.
+- Parameters:
+ - `bar`: The progress bar name.
+ - `attr`: The progress attribute name.
+ - `value`: The current progress value.
+ - `old_value`: The previous progress value.
+
+### `format_time(self, seconds)`
+
+- Formats the given time in seconds to the format "mm:ss".
+- Parameters:
+ - `seconds`: The time in seconds.
+- Returns:
+ - The formatted time string.
+
+## `editing_engine.py`
+
+This file defines the `EditingStep` and `Flow` enums, as well as the `EditingEngine` class, which is responsible for managing the editing process. The `EditingEngine` class has the following methods:
+
+### `__init__(self)`
+
+- Initializes a new instance of the `EditingEngine` class.
+- It initializes the editing step tracker and the editing schema.
+
+### `addEditingStep(self, editingStep: EditingStep, args: Dict[str, any] = {})`
+
+- Adds an editing step to the editing schema with the specified arguments.
+- Parameters:
+ - `editingStep`: The editing step to add.
+ - `args`: The arguments for the editing step.
+- Raises:
+ - `Exception`: If a required argument is missing.
+
+### `ingestFlow(self, flow: Flow, args)`
+
+- Ingests a flow into the editing schema with the specified arguments.
+- Parameters:
+ - `flow`: The flow to ingest.
+ - `args`: The arguments for the flow.
+- Raises:
+ - `Exception`: If a required argument is missing.
+
+### `dumpEditingSchema(self)`
+
+- Returns the current editing schema.
+
+### `renderVideo(self, outputPath, logger=None)`
+
+- Renders the video based on the editing schema and saves it to the specified output path.
+- Parameters:
+ - `outputPath`: The path to save the rendered video.
+ - `logger`: An optional logger object for logging the rendering progress.
+
+### `renderImage(self, outputPath)`
+
+- Renders the image based on the editing schema and saves it to the specified output path.
+- Parameters:
+ - `outputPath`: The path to save the rendered image.
+
+## `core_editing_engine.py`
+
+This file defines the `CoreEditingEngine` class, which is responsible for generating videos and images based on the editing schema. The `CoreEditingEngine` class has the following methods:
+
+### `generate_image(self, schema:Dict[str, Any], output_file)`
+
+- Generates an image based on the editing schema and saves it to the specified output file.
+- Parameters:
+ - `schema`: The editing schema.
+ - `output_file`: The path to save the generated image.
+- Returns:
+ - The path to the saved image.
+
+### `generate_video(self, schema:Dict[str, Any], output_file, logger=None)`
+
+- Generates a video based on the editing schema and saves it to the specified output file.
+- Parameters:
+ - `schema`: The editing schema.
+ - `output_file`: The path to save the generated video.
+ - `logger`: An optional logger object for logging the rendering progress.
+- Returns:
+ - The path to the saved video.
+
+### `process_common_actions(self, clip: Union[VideoFileClip, ImageClip, TextClip, AudioFileClip], actions: List[Dict[str, Any]])`
+
+- Processes common actions for the given clip.
+- Parameters:
+ - `clip`: The clip to process.
+ - `actions`: The list of actions to apply to the clip.
+- Returns:
+ - The processed clip.
+
+### `process_common_visual_actions(self, clip: Union[VideoFileClip, ImageClip, TextClip], actions: List[Dict[str, Any]])`
+
+- Processes common visual clip actions for the given clip.
+- Parameters:
+ - `clip`: The clip to process.
+ - `actions`: The list of actions to apply to the clip.
+- Returns:
+ - The processed clip.
+
+### `process_audio_actions(self, clip: AudioFileClip, actions: List[Dict[str, Any]])`
+
+- Processes audio actions for the given audio clip.
+- Parameters:
+ - `clip`: The audio clip to process.
+ - `actions`: The list of actions to apply to the audio clip.
+- Returns:
+ - The processed audio clip.
+
+### `process_video_asset(self, asset: Dict[str, Any])`
+
+- Processes a video asset based on the asset parameters and actions.
+- Parameters:
+ - `asset`: The video asset to process.
+- Returns:
+ - The processed video clip.
+
+### `process_image_asset(self, asset: Dict[str, Any])`
+
+- Processes an image asset based on the asset parameters and actions.
+- Parameters:
+ - `asset`: The image asset to process.
+- Returns:
+ - The processed image clip.
+
+### `process_text_asset(self, asset: Dict[str, Any])`
+
+- Processes a text asset based on the asset parameters and actions.
+- Parameters:
+ - `asset`: The text asset to process.
+- Returns:
+ - The processed text clip.
+
+### `process_audio_asset(self, asset: Dict[str, Any])`
+
+- Processes an audio asset based on the asset parameters and actions.
+- Parameters:
+ - `asset`: The audio asset to process.
+- Returns:
+ - The processed audio clip.
+
+### `__normalize_image(self, clip)`
+
+- Normalizes the image clip.
+- Parameters:
+ - `clip`: The image clip to normalize.
+- Returns:
+ - The normalized image clip.
+
+### `__normalize_frame(self, frame)`
+
+- Normalizes the given frame.
+- Parameters:
+ - `frame`: The frame to normalize.
+- Returns:
+ - The normalized frame.
\ No newline at end of file
diff --git a/shortGPT/editing_framework/__init__.py b/shortGPT/editing_framework/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/shortGPT/editing_framework/core_editing_engine.py b/shortGPT/editing_framework/core_editing_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..0feb8fa7d9df53ad75b2e0febfb06d19066d4e99
--- /dev/null
+++ b/shortGPT/editing_framework/core_editing_engine.py
@@ -0,0 +1,251 @@
+from shortGPT.config.path_utils import get_program_path
+import os
+magick_path = get_program_path("magick")
+if magick_path:
+ os.environ['IMAGEMAGICK_BINARY'] = magick_path
+from shortGPT.config.path_utils import handle_path
+import numpy as np
+import json
+from typing import Any, Dict, List, Union
+from moviepy.editor import (AudioFileClip, CompositeVideoClip,CompositeAudioClip, ImageClip,
+ TextClip, VideoFileClip, vfx,)
+from moviepy.audio.fx.audio_loop import audio_loop
+from moviepy.audio.fx.audio_normalize import audio_normalize
+from shortGPT.editing_framework.rendering_logger import MoviepyProgressLogger
+
+def load_schema(json_path):
+ return json.loads(open(json_path, 'r', encoding='utf-8').read())
+
+class CoreEditingEngine:
+
+ def generate_image(self, schema:Dict[str, Any],output_file , logger=None):
+ assets = dict(sorted(schema['visual_assets'].items(), key=lambda item: item[1]['z']))
+ clips = []
+
+ for asset_key in assets:
+ asset = assets[asset_key]
+ asset_type = asset['type']
+ if asset_type == 'image':
+ try:
+ clip = self.process_image_asset(asset)
+ except Exception as e:
+ continue
+ elif asset_type == 'text':
+ clip = self.process_text_asset(asset)
+ clips.append(clip)
+ else:
+ raise ValueError(f'Invalid asset type: {asset_type}')
+ clips.append(clip)
+
+ image = CompositeVideoClip(clips)
+ image.save_frame(output_file)
+ return output_file
+
+ def generate_video(self, schema:Dict[str, Any], output_file, logger=None) -> None:
+ visual_assets = dict(sorted(schema['visual_assets'].items(), key=lambda item: item[1]['z']))
+ audio_assets = dict(sorted(schema['audio_assets'].items(), key=lambda item: item[1]['z']))
+
+ visual_clips = []
+ for asset_key in visual_assets:
+ asset = visual_assets[asset_key]
+ asset_type = asset['type']
+ if asset_type == 'video':
+ clip = self.process_video_asset(asset)
+ elif asset_type == 'image':
+ try:
+ clip = self.process_image_asset(asset)
+ except Exception as e:
+ continue
+ elif asset_type == 'text':
+ clip = self.process_text_asset(asset)
+ else:
+ raise ValueError(f'Invalid asset type: {asset_type}')
+
+ visual_clips.append(clip)
+
+ audio_clips = []
+
+ for asset_key in audio_assets:
+ asset = audio_assets[asset_key]
+ asset_type = asset['type']
+ if asset_type == "audio":
+ audio_clip = self.process_audio_asset(asset)
+ else:
+ raise ValueError(f"Invalid asset type: {asset_type}")
+
+ audio_clips.append(audio_clip)
+ video = CompositeVideoClip(visual_clips)
+ if(audio_clips):
+ audio = CompositeAudioClip(audio_clips)
+ video.duration = audio.duration
+ video.audio = audio
+ if logger:
+ my_logger = MoviepyProgressLogger(callBackFunction=logger)
+ video.write_videofile(output_file, codec='libx264', audio_codec='aac', logger=my_logger)
+ else:
+ video.write_videofile(output_file, codec='libx264', audio_codec='aac')
+ return output_file
+
+ def generate_audio(self, schema:Dict[str, Any], output_file, logger=None) -> None:
+ audio_assets = dict(sorted(schema['audio_assets'].items(), key=lambda item: item[1]['z']))
+ audio_clips = []
+
+ for asset_key in audio_assets:
+ asset = audio_assets[asset_key]
+ asset_type = asset['type']
+ if asset_type == "audio":
+ audio_clip = self.process_audio_asset(asset)
+ else:
+ raise ValueError(f"Invalid asset type: {asset_type}")
+
+ audio_clips.append(audio_clip)
+ audio = CompositeAudioClip(audio_clips)
+ audio.fps = 44100
+ if logger:
+ my_logger = MoviepyProgressLogger(callBackFunction=logger)
+ audio.write_audiofile(output_file, logger=my_logger)
+ else:
+ audio.write_audiofile(output_file)
+ return output_file
+ # Process common actions
+ def process_common_actions(self,
+ clip: Union[VideoFileClip, ImageClip, TextClip, AudioFileClip],
+ actions: List[Dict[str, Any]]) -> Union[VideoFileClip, AudioFileClip, ImageClip, TextClip]:
+ for action in actions:
+ if action['type'] == 'set_time_start':
+ clip = clip.set_start(action['param'])
+ continue
+
+ if action['type'] == 'set_time_end':
+ clip = clip.set_end(action['param'])
+ continue
+
+ if action['type'] == 'subclip':
+ clip = clip.subclip(**action['param'])
+ continue
+
+ return clip
+
+ # Process common visual clip actions
+ def process_common_visual_actions(self,
+ clip: Union[VideoFileClip, ImageClip, TextClip],
+ actions: List[Dict[str, Any]]) -> Union[VideoFileClip, ImageClip, TextClip]:
+ clip = self.process_common_actions(clip, actions)
+ for action in actions:
+
+ if action['type'] == 'resize':
+ clip = clip.resize(**action['param'])
+ continue
+
+ if action['type'] == 'crop':
+ clip = clip.crop(**action['param'])
+ continue
+
+ if action['type'] == 'screen_position':
+ clip = clip.set_position(**action['param'])
+ continue
+
+ if action['type'] == 'green_screen':
+ params = action['param']
+ color = params['color'] if params['color'] else [52, 255, 20]
+ thr = params['thr'] if params['thr'] else 100
+ s = params['s'] if params['s'] else 5
+ clip = clip.fx(vfx.mask_color, color=color,thr=thr, s=s)
+ continue
+
+ if action['type'] == 'normalize_image':
+ clip = clip.fx(self.__normalize_image)
+ continue
+
+ if action['type'] == 'auto_resize_image':
+ ar = clip.aspect_ratio
+ height = action['param']['maxHeight']
+ width = action['param']['maxWidth']
+ if ar <1:
+ clip = clip.resize((height*ar, height))
+ else:
+ clip = clip.resize((width, width/ar))
+ continue
+
+ return clip
+
+ # Process audio actions
+ def process_audio_actions(self, clip: AudioFileClip,
+ actions: List[Dict[str, Any]]) -> AudioFileClip:
+ clip = self.process_common_actions(clip, actions)
+ for action in actions:
+ if action['type'] == 'normalize_music':
+ clip = clip.fx(audio_normalize)
+ pass
+ if action['type'] == 'loop_background_music':
+ target_duration = action['param']
+ start = clip.duration * 0.15
+ clip = clip.subclip(start)
+ clip = clip.fx(audio_loop, duration=target_duration)
+ pass
+
+ if action['type'] == 'volume_percentage':
+ clip = clip.volumex(action['param'])
+ pass
+
+ return clip
+
+ # Process individual asset types
+ def process_video_asset(self, asset: Dict[str, Any]) -> VideoFileClip:
+ params = {
+ 'filename': handle_path(asset['parameters']['url'])
+ }
+ if 'audio' in asset['parameters']:
+ params['audio'] = asset['parameters']['audio']
+ clip = VideoFileClip(**params)
+ return self.process_common_visual_actions(clip, asset['actions'])
+
+ def process_image_asset(self, asset: Dict[str, Any]) -> ImageClip:
+ clip = ImageClip(asset['parameters']['url'])
+ return self.process_common_visual_actions(clip, asset['actions'])
+
+ def process_text_asset(self, asset: Dict[str, Any]) -> TextClip:
+ text_clip_params = asset['parameters']
+
+ if not (any(key in text_clip_params for key in ['text','fontsize', 'size'])):
+ raise Exception('You must include at least a size or a fontsize to determine the size of your text')
+ text_clip_params['txt'] = text_clip_params['text']
+ clip_info = {k: text_clip_params[k] for k in ('txt', 'fontsize', 'font', 'color', 'stroke_width', 'stroke_color', 'size', 'kerning', 'method', 'align') if k in text_clip_params}
+ clip = TextClip(**clip_info)
+
+ return self.process_common_visual_actions(clip, asset['actions'])
+
+ def process_audio_asset(self, asset: Dict[str, Any]) -> AudioFileClip:
+ clip = AudioFileClip(asset['parameters']['url'])
+ return self.process_audio_actions(clip, asset['actions'])
+
+ def __normalize_image(self, clip):
+ def f(get_frame, t):
+ if f.normalized_frame is not None:
+ return f.normalized_frame
+ else:
+ frame = get_frame(t)
+ f.normalized_frame = self.__normalize_frame(frame)
+ return f.normalized_frame
+
+ f.normalized_frame = None
+
+ return clip.fl(f)
+
+
+ def __normalize_frame(self, frame):
+ shape = np.shape(frame)
+ [dimensions, ] = np.shape(shape)
+
+ if dimensions == 2:
+ (height, width) = shape
+ normalized_frame = np.zeros((height, width, 3))
+ for y in range(height):
+ for x in range(width):
+ grey_value = frame[y][x]
+ normalized_frame[y][x] = (grey_value, grey_value, grey_value)
+ return normalized_frame
+ else:
+ return frame
+
+
diff --git a/shortGPT/editing_framework/editing_engine.py b/shortGPT/editing_framework/editing_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..e97cf9fca1d96eef436a50ca1753b33385c206af
--- /dev/null
+++ b/shortGPT/editing_framework/editing_engine.py
@@ -0,0 +1,228 @@
+import json
+from typing import Any, Dict, List, Union
+from enum import Enum
+import collections.abc
+
+from shortGPT.editing_framework.core_editing_engine import CoreEditingEngine
+
+def update_dict(d, u):
+ for k, v in u.items():
+ if isinstance(v, collections.abc.Mapping):
+ d[k] = update_dict(d.get(k, {}), v)
+ else:
+ d[k] = v
+ return d
+
+
+class EditingStep(Enum):
+ CROP_1920x1080 = "crop_1920x1080_to_short.json"
+ ADD_CAPTION_SHORT = "make_caption.json"
+ ADD_CAPTION_SHORT_ARABIC = "make_caption_arabic.json"
+ ADD_CAPTION_LANDSCAPE = "make_caption_landscape.json"
+ ADD_CAPTION_LANDSCAPE_ARABIC = "make_caption_arabic_landscape.json"
+ ADD_WATERMARK = "show_watermark.json"
+ ADD_SUBSCRIBE_ANIMATION = "subscribe_animation.json"
+ SHOW_IMAGE = "show_top_image.json"
+ ADD_VOICEOVER_AUDIO = "add_voiceover.json"
+ ADD_BACKGROUND_MUSIC = "background_music.json"
+ ADD_REDDIT_IMAGE = "show_reddit_image.json"
+ ADD_BACKGROUND_VIDEO = "add_background_video.json"
+ INSERT_AUDIO = "insert_audio.json"
+ EXTRACT_AUDIO = "extract_audio.json"
+ ADD_BACKGROUND_VOICEOVER = "add_background_voiceover.json"
+
+class Flow(Enum):
+ WHITE_REDDIT_IMAGE_FLOW = "build_reddit_image.json"
+
+from pathlib import Path
+
+_here = Path(__file__).parent
+STEPS_PATH = (_here / 'editing_steps/').resolve()
+FLOWS_PATH = (_here / 'flows/').resolve()
+
+class EditingEngine:
+ def __init__(self,):
+ self.editing_step_tracker = dict((step, 0) for step in EditingStep)
+ self.schema = {'visual_assets': {}, 'audio_assets': {}}
+
+ def addEditingStep(self, editingStep: EditingStep, args: Dict[str, any] = {}):
+ json_step = json.loads(
+ open(STEPS_PATH / f"{editingStep.value}", 'r', encoding='utf-8').read())
+ step_name, editingStepDict = list(json_step.items())[0]
+ if 'inputs' in editingStepDict:
+ required_args = (editingStepDict['inputs']['actions'] if 'actions' in editingStepDict['inputs'] else []) + (editingStepDict['inputs']['parameters'] if 'parameters' in editingStepDict['inputs'] else [])
+ for required_argument in required_args:
+ if required_argument not in args:
+ raise Exception(
+ f"Error. '{required_argument}' input missing, you must include it to use this editing step")
+ if required_args:
+ pass
+ action_names = [action['type'] for action in editingStepDict['actions']
+ ] if 'actions' in editingStepDict else []
+ param_names = [param_name for param_name in editingStepDict['parameters']
+ ] if 'parameters' in editingStepDict else []
+ for arg_name in args:
+ if ('inputs' in editingStepDict):
+ if 'parameters' in editingStepDict['inputs'] and arg_name in param_names:
+ editingStepDict['parameters'][arg_name] = args[arg_name]
+ pass
+ if 'actions' in editingStepDict['inputs'] and arg_name in action_names:
+ for i, action in enumerate(editingStepDict['actions']):
+ if action['type'] == arg_name:
+ editingStepDict['actions'][i]['param'] = args[arg_name]
+ if editingStepDict['type'] == 'audio':
+ self.schema['audio_assets'][f"{step_name}_{self.editing_step_tracker[editingStep]}"] = editingStepDict
+ else:
+ self.schema['visual_assets'][f"{step_name}_{self.editing_step_tracker[editingStep]}"] = editingStepDict
+ self.editing_step_tracker[editingStep] += 1
+
+
+ def ingestFlow(self, flow: Flow, args):
+ json_flow = json.loads(open(FLOWS_PATH / f"{flow.value}", 'r', encoding='utf-8').read())
+ for required_argument in list(json_flow['inputs'].keys()):
+ if required_argument not in args:
+ raise Exception(
+ f"Error. '{required_argument}' input missing, you must include it to use this editing step")
+ update = args[required_argument]
+ for path_key in reversed(json_flow['inputs'][required_argument].split("/")):
+ update = {path_key: update}
+ json_flow = update_dict(json_flow, update)
+ self.schema = json_flow
+
+ def dumpEditingSchema(self):
+ return self.schema
+
+ def renderVideo(self, outputPath, logger=None):
+ engine = CoreEditingEngine()
+ engine.generate_video(self.schema, outputPath, logger=logger)
+ def renderImage(self, outputPath, logger=None):
+ engine = CoreEditingEngine()
+ engine.generate_image(self.schema, outputPath, logger=logger)
+ def generateAudio(self, outputPath, logger=None):
+ engine = CoreEditingEngine()
+ engine.generate_audio(self.schema, outputPath, logger=logger)
+
+
+
+# import json
+# from typing import Any, Dict, List, Union
+# from enum import Enum
+# import collections.abc
+# import os
+# from shortGPT.editing_framework.core_editing_engine import CoreEditingEngine
+
+# def update_dict(d, u):
+# for k, v in u.items():
+# if isinstance(v, collections.abc.Mapping):
+# d[k] = update_dict(d.get(k, {}), v)
+# else:
+# d[k] = v
+# return d
+
+
+# class EditingStep(Enum):
+# CROP_1920x1080 = "crop_1920x1080_to_short.json"
+# ADD_CAPTION_SHORT = "make_caption.json"
+# ADD_CAPTION_SHORT_ARABIC = "make_caption_arabic.json"
+# ADD_CAPTION_LANDSCAPE = "make_caption_landscape.json"
+# ADD_CAPTION_LANDSCAPE_ARABIC = "make_caption_arabic_landscape.json"
+# ADD_WATERMARK = "show_watermark.json"
+# ADD_SUBSCRIBE_ANIMATION = "subscribe_animation.json"
+# SHOW_IMAGE = "show_top_image.json"
+# ADD_VOICEOVER_AUDIO = "add_voiceover.json"
+# ADD_BACKGROUND_MUSIC = "background_music.json"
+# ADD_REDDIT_IMAGE = "show_reddit_image.json"
+# ADD_BACKGROUND_VIDEO = "add_background_video.json"
+# INSERT_AUDIO = "insert_audio.json"
+# EXTRACT_AUDIO = "extract_audio.json"
+# ADD_BACKGROUND_VOICEOVER = "add_background_voiceover.json"
+
+# class Flow(Enum):
+# WHITE_REDDIT_IMAGE_FLOW = "build_reddit_image.json"
+
+# STEPS_PATH = "shortGPT/editing_framework/editing_steps/"
+# FLOWS_PATH = "shortGPT/editing_framework/flows/"
+
+
+# class EditingTrack:
+# def __init__(self, filepath=None):
+# self.editing_step_tracker = dict((step, 0) for step in EditingStep)
+# self.schema = {'visual_assets': {}, 'audio_assets': {}}
+# self.filepath = filepath
+
+# if filepath is not None:
+# try:
+# self.load_from_file(filepath)
+# except FileNotFoundError:
+# self.save_to_file(filepath)
+
+# def addEditingStep(self, editingStep: EditingStep, args: Dict[str, any] = {}):
+# json_step = json.loads(
+# open(STEPS_PATH+editingStep.value, 'r', encoding='utf-8').read())
+# step_name, editingStepDict = list(json_step.items())[0]
+# if 'inputs' in editingStepDict:
+# required_args = (editingStepDict['inputs']['actions'] if 'actions' in editingStepDict['inputs'] else []) + (editingStepDict['inputs']['parameters'] if 'parameters' in editingStepDict['inputs'] else [])
+# for required_argument in required_args:
+# if required_argument not in args:
+# raise Exception(
+# f"Error. '{required_argument}' input missing, you must include it to use this editing step")
+# if required_args:
+# pass
+# action_names = [action['type'] for action in editingStepDict['actions']
+# ] if 'actions' in editingStepDict else []
+# param_names = [param_name for param_name in editingStepDict['parameters']
+# ] if 'parameters' in editingStepDict else []
+# for arg_name in args:
+# if ('inputs' in editingStepDict):
+# if 'parameters' in editingStepDict['inputs'] and arg_name in param_names:
+# editingStepDict['parameters'][arg_name] = args[arg_name]
+# pass
+# if 'actions' in editingStepDict['inputs'] and arg_name in action_names:
+# for i, action in enumerate(editingStepDict['actions']):
+# if action['type'] == arg_name:
+# editingStepDict['actions'][i]['param'] = args[arg_name]
+# if editingStepDict['type'] == 'audio':
+# self.schema['audio_assets'][f"{step_name}_{self.editing_step_tracker[editingStep]}"] = editingStepDict
+# else:
+# self.schema['visual_assets'][f"{step_name}_{self.editing_step_tracker[editingStep]}"] = editingStepDict
+# self.editing_step_tracker[editingStep] += 1
+
+
+# def ingestFlow(self, flow: Flow, args):
+# json_flow = json.loads(open(FLOWS_PATH+flow.value, 'r', encoding='utf-8').read())
+# for required_argument in list(json_flow['inputs'].keys()):
+# if required_argument not in args:
+# raise Exception(
+# f"Error. '{required_argument}' input missing, you must include it to use this editing step")
+# update = args[required_argument]
+# for path_key in reversed(json_flow['inputs'][required_argument].split("/")):
+# update = {path_key: update}
+# json_flow = update_dict(json_flow, update)
+# self.schema = json_flow
+
+# def dumpEditingSchema(self):
+# return self.schema
+
+# def save_to_file(self):
+# if self.file_path:
+# with open(self.file_path, 'w') as f:
+# json.dump({'step_tracker': {key.name: value for key, value in self.step_tracker.items()}, 'asset_schema': self.asset_schema}, f)
+
+# def load_from_file(self):
+# if self.file_path and os.path.exists(self.file_path):
+# with open(self.file_path, 'r') as f:
+# data = json.load(f)
+# self.step_tracker = {EditingStep[key]: value for key, value in data.get('step_tracker', {}).items()}
+# self.asset_schema = data.get('asset_schema', {'visual_assets': {}, 'audio_assets': {}})
+# else:
+# raise Exception("File does not exist")
+
+# def renderVideo(self, outputPath, logger=None):
+# engine = CoreEditingEngine()
+# engine.generate_video(self.schema, outputPath, logger=logger)
+# def renderImage(self, outputPath, logger=None):
+# engine = CoreEditingEngine()
+# engine.generate_image(self.schema, outputPath, logger=logger)
+# def generateAudio(self, outputPath, logger=None):
+# engine = CoreEditingEngine()
+# engine.generate_audio(self.schema, outputPath, logger=logger)
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/__init__.py b/shortGPT/editing_framework/editing_steps/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/shortGPT/editing_framework/editing_steps/add_background_video.json b/shortGPT/editing_framework/editing_steps/add_background_video.json
new file mode 100644
index 0000000000000000000000000000000000000000..0f73615c48b7863067c4a3b2be1b60fa6fc6bbc8
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/add_background_video.json
@@ -0,0 +1,24 @@
+{
+ "background_video": {
+ "type": "video",
+ "z": 0,
+ "inputs":{
+ "parameters": ["url"],
+ "actions": ["set_time_start", "set_time_end"]
+ },
+ "parameters": {
+ "url": null,
+ "audio": false
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/add_background_voiceover.json b/shortGPT/editing_framework/editing_steps/add_background_voiceover.json
new file mode 100644
index 0000000000000000000000000000000000000000..1981c788e1ae73da9a2627c5a93fd1eaef64f107
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/add_background_voiceover.json
@@ -0,0 +1,19 @@
+{
+ "background_voiceover": {
+ "inputs": {
+ "parameters": ["url"],
+ "actions": ["volume_percentage"]
+ },
+ "type": "audio",
+ "z": -1,
+ "parameters": {
+ "url": null
+ },
+ "actions": [
+ {
+ "type": "volume_percentage",
+ "param": null
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/add_voiceover.json b/shortGPT/editing_framework/editing_steps/add_voiceover.json
new file mode 100644
index 0000000000000000000000000000000000000000..4c85875db60455b291c5178be44c9a4b74f60a51
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/add_voiceover.json
@@ -0,0 +1,17 @@
+{
+ "voiceover": {
+ "inputs": {
+ "parameters": [
+ "url"
+ ]
+ },
+ "type": "audio",
+ "z": -1,
+ "parameters": {
+ "url": null
+ },
+ "actions": [
+
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/background_music.json b/shortGPT/editing_framework/editing_steps/background_music.json
new file mode 100644
index 0000000000000000000000000000000000000000..03f335cf1443f69f383aa54d584e9b5b634701bc
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/background_music.json
@@ -0,0 +1,29 @@
+{
+ "background_music": {
+ "inputs": {
+ "parameters": ["url", "volume_percentage"],
+ "actions":["loop_background_music"]
+ },
+ "type": "audio",
+ "z": -1,
+ "parameters": {
+ "url": null
+ },
+ "actions": [
+ {
+ "type": "loop_background_music",
+ "param": {
+ "duration": null
+ }
+ },
+ {
+ "type":"normalize_audio",
+ "param":{}
+ },
+ {
+ "type": "volume_percentage",
+ "param": null
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/crop_1920x1080_to_short.json b/shortGPT/editing_framework/editing_steps/crop_1920x1080_to_short.json
new file mode 100644
index 0000000000000000000000000000000000000000..72a36b3a089eaec438b434ba6eb024b0986be935
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/crop_1920x1080_to_short.json
@@ -0,0 +1,40 @@
+{
+ "background_video": {
+ "type": "video",
+ "z": 0,
+ "inputs":{
+ "parameters": ["url"]
+ },
+ "parameters": {
+ "url": null,
+ "audio": false
+ },
+ "actions": [
+ {
+ "type": "crop",
+ "param": {
+ "x1": 420,
+ "y1": 0,
+ "width": 1080,
+ "height": 1080
+ }
+ },
+ {
+ "type": "resize",
+ "param": {
+ "width": 1920,
+ "height": 1920
+ }
+ },
+ {
+ "type": "crop",
+ "param": {
+ "x1": 420,
+ "y1": 0,
+ "width": 1080,
+ "height": 1920
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/extract_audio.json b/shortGPT/editing_framework/editing_steps/extract_audio.json
new file mode 100644
index 0000000000000000000000000000000000000000..35a4df12019b7838dbadb9581cd7b1639ac03f4a
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/extract_audio.json
@@ -0,0 +1,27 @@
+{
+ "extract_audio": {
+ "inputs": {
+ "parameters": ["url"],
+ "actions": ["subclip", "set_time_start", "set_time_end"]
+ },
+ "type": "audio",
+ "z": -2,
+ "parameters": {
+ "url": null
+ },
+ "actions": [
+ {
+ "type": "subclip",
+ "param": null
+ },
+ {
+ "type": "set_time_start",
+ "param": null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/insert_audio.json b/shortGPT/editing_framework/editing_steps/insert_audio.json
new file mode 100644
index 0000000000000000000000000000000000000000..6b9d2bafe320349dc5930bbaf96d9edff0a1caa4
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/insert_audio.json
@@ -0,0 +1,23 @@
+{
+ "insert_audio": {
+ "inputs": {
+ "parameters": ["url"],
+ "actions": ["set_time_start", "set_time_end"]
+ },
+ "type": "audio",
+ "z": -1,
+ "parameters": {
+ "url": null
+ },
+ "actions": [
+ {
+ "type":"set_time_start",
+ "param":null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/make_caption.json b/shortGPT/editing_framework/editing_steps/make_caption.json
new file mode 100644
index 0000000000000000000000000000000000000000..2a0af06f382de583ca37256af951177e2f457a93
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/make_caption.json
@@ -0,0 +1,39 @@
+{
+ "caption": {
+ "type": "text",
+ "z": 4,
+ "inputs":{
+ "parameters": ["text"],
+ "actions": ["set_time_start", "set_time_end"]
+ },
+ "parameters": {
+ "text": null,
+ "fontsize": 100,
+ "font": "Syncopate-Bold",
+ "color": "white",
+ "stroke_width": 3,
+ "stroke_color": "black",
+ "method": "caption",
+ "size": [
+ 900,
+ null
+ ]
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ },
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": "center"
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/make_caption_arabic.json b/shortGPT/editing_framework/editing_steps/make_caption_arabic.json
new file mode 100644
index 0000000000000000000000000000000000000000..56f63d8600788f21f8e9e1d3d3d46b34b03e11bc
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/make_caption_arabic.json
@@ -0,0 +1,39 @@
+{
+ "caption": {
+ "type": "text",
+ "z": 4,
+ "inputs":{
+ "parameters": ["text"],
+ "actions": ["set_time_start", "set_time_end"]
+ },
+ "parameters": {
+ "text": null,
+ "fontsize": 150,
+ "font": "Segoe-UI-Bold",
+ "color": "white",
+ "stroke_width": 2,
+ "stroke_color": "black",
+ "method": "caption",
+ "size": [
+ 900,
+ null
+ ]
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ },
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": "center"
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/make_caption_arabic_landscape.json b/shortGPT/editing_framework/editing_steps/make_caption_arabic_landscape.json
new file mode 100644
index 0000000000000000000000000000000000000000..4aab2e91f58d6bef7b95fd973780716ba7564808
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/make_caption_arabic_landscape.json
@@ -0,0 +1,34 @@
+{
+ "caption": {
+ "type": "text",
+ "z": 4,
+ "inputs":{
+ "parameters": ["text"],
+ "actions": ["set_time_start", "set_time_end"]
+ },
+ "parameters": {
+ "text": null,
+ "fontsize": 105,
+ "font": "Segoe-UI-Bold",
+ "color": "white",
+ "stroke_width": 2,
+ "stroke_color": "black"
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ },
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": ["center", 800]
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/make_caption_landscape.json b/shortGPT/editing_framework/editing_steps/make_caption_landscape.json
new file mode 100644
index 0000000000000000000000000000000000000000..6cc600fa4e55d8f02bd1c04415249ccf2b2d44dc
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/make_caption_landscape.json
@@ -0,0 +1,35 @@
+{
+ "caption": {
+ "type": "text",
+ "z": 4,
+ "inputs":{
+ "parameters": ["text"],
+ "actions": ["set_time_start", "set_time_end"]
+ },
+ "parameters": {
+ "text": null,
+ "fontsize": 70,
+ "font": "Syncopate-Bold",
+ "color": "white",
+ "stroke_width": 3,
+ "stroke_color": "black",
+ "method": "label"
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ },
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": ["center", 820]
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/show_reddit_image.json b/shortGPT/editing_framework/editing_steps/show_reddit_image.json
new file mode 100644
index 0000000000000000000000000000000000000000..a445ea74fb8379275577dbaf0d1000d675ffc71e
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/show_reddit_image.json
@@ -0,0 +1,31 @@
+{
+ "reddit_image": {
+ "type": "image",
+ "inputs":{
+ "parameters": ["url"]
+ },
+ "z": 5,
+ "parameters": {
+ "url": null
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": 0
+ },
+ {
+ "type": "set_time_end",
+ "param": 3.5
+ },
+
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": [
+ "center","center"
+ ]
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/show_top_image.json b/shortGPT/editing_framework/editing_steps/show_top_image.json
new file mode 100644
index 0000000000000000000000000000000000000000..4dc9e221ce5797c547f4885410fa7d3340afd503
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/show_top_image.json
@@ -0,0 +1,46 @@
+{
+ "top_image_1": {
+ "type": "image",
+ "inputs":{
+ "parameters": ["url"],
+ "actions": ["set_time_start", "set_time_end"]
+ },
+ "z": 5,
+ "parameters": {
+ "url": null
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": null
+ },
+ {
+ "type": "set_time_end",
+ "param": null
+ },
+ {
+ "type": "auto_resize_image",
+ "param":{
+ "maxWidth": 690,
+ "maxHeight": 690
+ }
+ },
+ {
+ "type": "normalize_image",
+ "param":{
+ "maxWidth": 690,
+ "maxHeight": 690
+ }
+ },
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": [
+ "center",
+ 50
+ ]
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/show_watermark.json b/shortGPT/editing_framework/editing_steps/show_watermark.json
new file mode 100644
index 0000000000000000000000000000000000000000..4097342b6bffcf4e50cb28b2cee947c0b750e212
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/show_watermark.json
@@ -0,0 +1,34 @@
+{
+ "short_watermark": {
+ "inputs":{
+ "parameters": ["text"]
+ },
+ "type": "text",
+ "z": 3,
+ "parameters": {
+ "text": null,
+ "fontsize": 80,
+ "font": "Berlin-Sans-FB-Demi-Bold",
+ "color": "white",
+ "stroke_width": 1,
+ "stroke_color": "black",
+ "method": "caption",
+ "size": [
+ 650,
+ 400
+ ]
+ },
+ "actions": [
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": [
+ "center",
+ 0.7
+ ],
+ "relative": true
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/editing_steps/subscribe_animation.json b/shortGPT/editing_framework/editing_steps/subscribe_animation.json
new file mode 100644
index 0000000000000000000000000000000000000000..fdd790355ed9a2df9e22662b465810d246646d2a
--- /dev/null
+++ b/shortGPT/editing_framework/editing_steps/subscribe_animation.json
@@ -0,0 +1,44 @@
+{
+ "subscribe_animation": {
+ "type": "video",
+ "z": 6,
+ "inputs":{
+ "parameters": ["url"]
+ },
+ "parameters": {
+ "url": null,
+ "audio": false
+ },
+ "actions": [
+ {
+ "type": "set_time_start",
+ "param": 3.5
+ },
+ {
+ "type": "resize",
+ "param": {
+ "newsize": 0.4
+ }
+ },
+ {
+ "type": "green_screen",
+ "param": {
+ "color": [
+ 52,
+ 255,
+ 20
+ ],
+ "thr": 100,
+ "s": 5
+ }
+ },
+ {
+ "type": "screen_position",
+ "param": {
+ "pos": ["center",
+ 1160]
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/flows/__init__.py b/shortGPT/editing_framework/flows/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/shortGPT/editing_framework/flows/build_reddit_image.json b/shortGPT/editing_framework/flows/build_reddit_image.json
new file mode 100644
index 0000000000000000000000000000000000000000..c7fa0d197fd8dde4dbdb7e6c6781738e73c3f078
--- /dev/null
+++ b/shortGPT/editing_framework/flows/build_reddit_image.json
@@ -0,0 +1,103 @@
+{
+ "inputs":{
+ "username_text": "visual_assets/username_txt/parameters/text",
+ "ncomments_text": "visual_assets/ncomments_txt/parameters/text",
+ "nupvote_text": "visual_assets/nupvote_txt/parameters/text",
+ "question_text": "visual_assets/question_txt/parameters/text"
+ },
+ "visual_assets":{
+ "white_reddit_template_image": {
+ "type": "image",
+ "z": 0,
+ "parameters": {
+ "url": "public/white_reddit_template.png"
+ },
+ "actions": [
+ ]
+ },
+ "username_txt": {
+ "type": "text",
+ "z": 1,
+ "parameters": {
+ "text": null,
+ "fontsize": 32,
+ "font" : "Arial",
+ "color": "rgb(129, 131, 132)",
+ "kerning": -0.7
+ },
+ "actions": [
+ {
+ "type": "screen_position",
+ "param": {
+ "pos":[350, 43],
+ "relative": false
+ }
+ }
+ ]
+ },
+ "ncomments_txt":{
+ "type": "text",
+ "z": 1,
+ "parameters": {
+ "text": null,
+ "fontsize": 34,
+ "font" : "Arial-Bold",
+ "color": "rgb(129, 131, 132)",
+ "kerning": -0.7
+ },
+ "actions": [
+ {
+ "type": "screen_position",
+ "param": {
+ "pos":[222, 301],
+ "relative": false
+ }
+ }
+ ]
+ },
+ "nupvote_txt":{
+ "type": "text",
+ "z": 1,
+ "parameters": {
+ "text": null,
+ "fontsize": 36,
+ "font" : "Arial-Bold",
+ "color": "rgb(26, 26 , 27)",
+ "kerning": -0.7
+ },
+ "actions": [
+ {
+ "type": "screen_position",
+ "param": {
+ "pos":[28, 115],
+ "relative": false
+ }
+ }
+ ]
+ },
+ "question_txt": {
+ "type": "text",
+ "z": 1,
+ "parameters": {
+ "text": null,
+ "fontsize": 40,
+ "font" : "Arial-Bold",
+ "color": "rgb(26, 26, 27)",
+ "size": [850, null],
+ "method": "caption",
+ "align": "West",
+ "kerning": -1.7
+ },
+ "actions": [
+ {
+ "type": "screen_position",
+ "param": {
+ "pos":[150, 110],
+ "relative": false
+ }
+ }
+ ]
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/shortGPT/editing_framework/rendering_logger.py b/shortGPT/editing_framework/rendering_logger.py
new file mode 100644
index 0000000000000000000000000000000000000000..4aff73874d5992f3a738a2e14606fe4d3af18786
--- /dev/null
+++ b/shortGPT/editing_framework/rendering_logger.py
@@ -0,0 +1,24 @@
+from proglog import ProgressBarLogger
+import time
+
+class MoviepyProgressLogger(ProgressBarLogger):
+
+ def __init__(self, callBackFunction = None):
+ super().__init__()
+ self.callBackFunction = callBackFunction
+ self.start_time = time.time()
+
+ def bars_callback(self, bar, attr, value, old_value=None):
+ # Every time the logger progress is updated, this function is called
+ percentage = (value / self.bars[bar]['total']) * 100
+ elapsed_time = time.time() - self.start_time
+ estimated_time = (elapsed_time / percentage) * (100 - percentage) if percentage != 0 else 0
+ progress_string = f'Rendering progress : {value}/{self.bars[bar]["total"]} | Time spent: {self.format_time(elapsed_time)} | Time left: {self.format_time(estimated_time)}'
+ if (self.callBackFunction):
+ self.callBackFunction(progress_string)
+ else:
+ print(progress_string)
+
+ def format_time(self, seconds):
+ minutes, seconds = divmod(seconds, 60)
+ return f'{int(minutes)}m {int(seconds)}s'
diff --git a/shortGPT/editing_utils/README.md b/shortGPT/editing_utils/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..8a106a647b7c00ca0b58b6e3bb833bdb1c67999d
--- /dev/null
+++ b/shortGPT/editing_utils/README.md
@@ -0,0 +1,55 @@
+# Module: editing_utils
+
+The `editing_utils` module provides utility functions for editing videos and images. It consists of three files: `editing_images.py`, `captions.py`, and `handle_videos.py`.
+
+## File: editing_images.py
+
+This file contains functions related to editing images.
+
+### Function: getImageUrlsTimed(imageTextPairs)
+
+This function takes a list of image-text pairs and returns a list of tuples containing the image URL and the corresponding text. It uses the `searchImageUrlsFromQuery` function to search for image URLs based on the provided text.
+
+### Function: searchImageUrlsFromQuery(query, top=3, expected_dim=[720,720], retries=5)
+
+This function searches for image URLs based on a given query. It uses the `getBingImages` function from the `shortGPT.api_utils.image_api` module to fetch the images. The `top` parameter specifies the number of images to fetch (default is 3), and the `expected_dim` parameter specifies the expected dimensions of the images (default is [720,720]). If no images are found, the function returns None. Otherwise, it selects the images with the closest dimensions to the expected dimensions and returns the URL of the first image.
+
+## File: captions.py
+
+This file contains functions related to handling captions.
+
+### Function: interpolateTimeFromDict(word_position, d)
+
+This function interpolates the time based on the word position in a dictionary. The dictionary contains word positions as keys and corresponding timestamps as values. Given a word position, the function returns the interpolated timestamp.
+
+### Function: cleanWord(word)
+
+This function cleans a word by removing any non-alphanumeric characters.
+
+### Function: getTimestampMapping(whisper_analysis)
+
+This function extracts the mapping of word positions to timestamps from a Whisper analysis. The `whisper_analysis` parameter is a dictionary containing the analysis results. The function returns a dictionary with word positions as keys and corresponding timestamps as values.
+
+### Function: splitWordsBySize(words, maxCaptionSize)
+
+This function splits a list of words into captions based on a maximum caption size. The `maxCaptionSize` parameter specifies the maximum number of characters allowed in a caption (default is 15). The function returns a list of captions.
+
+### Function: getCaptionsWithTime(whisper_analysis, maxCaptionSize=15)
+
+This function generates captions with their corresponding timestamps from a Whisper analysis. The `whisper_analysis` parameter is a dictionary containing the analysis results. The `maxCaptionSize` parameter specifies the maximum number of characters allowed in a caption (default is 15). The function uses the `getTimestampMapping` function to get the word position to timestamp mapping and the `splitWordsBySize` function to split the words into captions. It returns a list of caption-time pairs.
+
+## File: handle_videos.py
+
+This file contains functions related to handling videos.
+
+### Function: getYoutubeAudio(url)
+
+This function retrieves the audio URL and duration from a YouTube video. The `url` parameter specifies the URL of the YouTube video. The function uses the `yt_dlp` library to extract the audio information. It returns the audio URL and duration as a tuple. If the retrieval fails, it returns None.
+
+### Function: getYoutubeVideoLink(url)
+
+This function retrieves the video URL and duration from a YouTube video. The `url` parameter specifies the URL of the YouTube video. The function uses the `yt_dlp` library to extract the video information. It returns the video URL and duration as a tuple. If the retrieval fails, it returns None.
+
+### Function: extract_random_clip_from_video(video_url, video_duration, clip_duration, output_file)
+
+This function extracts a random clip from a video and saves it to an output file. The `video_url` parameter specifies the URL of the video, the `video_duration` parameter specifies the duration of the video, the `clip_duration` parameter specifies the duration of the desired clip, and the `output_file` parameter specifies the file path for the extracted clip. The function uses the `ffmpeg` library to perform the extraction. It randomly selects a start time within 15% to 85% of the video duration and extracts a clip of the specified duration starting from the selected start time. If the extraction fails or the output file is not created, an exception is raised.
\ No newline at end of file
diff --git a/shortGPT/editing_utils/__init__.py b/shortGPT/editing_utils/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..cab35dfe994d156c0197810ca2827548972cd5f0
--- /dev/null
+++ b/shortGPT/editing_utils/__init__.py
@@ -0,0 +1,2 @@
+from . import editing_images
+from . import captions
\ No newline at end of file
diff --git a/shortGPT/editing_utils/captions.py b/shortGPT/editing_utils/captions.py
new file mode 100644
index 0000000000000000000000000000000000000000..e14c445c30e16fc8ee1cb2c25d3793c2599d84da
--- /dev/null
+++ b/shortGPT/editing_utils/captions.py
@@ -0,0 +1,71 @@
+import re
+
+def getSpeechBlocks(whispered, silence_time=2):
+ text_blocks, (st, et, txt) = [], (0,0,"")
+ for i, seg in enumerate(whispered['segments']):
+ if seg['start'] - et > silence_time:
+ if txt: text_blocks.append([[st, et], txt])
+ (st, et, txt) = (seg['start'], seg['end'], seg['text'])
+ else:
+ et, txt = seg['end'], txt + seg['text']
+
+ if txt: text_blocks.append([[st, et], txt]) # For last text block
+
+ return text_blocks
+
+def cleanWord(word):
+ return re.sub(r'[^\w\s\-_"\'\']', '', word)
+
+def interpolateTimeFromDict(word_position, d):
+ for key, value in d.items():
+ if key[0] <= word_position <= key[1]:
+ return value
+ return None
+
+def getTimestampMapping(whisper_analysis):
+ index = 0
+ locationToTimestamp = {}
+ for segment in whisper_analysis['segments']:
+ for word in segment['words']:
+ newIndex = index + len(word['text'])+1
+ locationToTimestamp[(index, newIndex)] = word['end']
+ index = newIndex
+ return locationToTimestamp
+
+
+def splitWordsBySize(words, maxCaptionSize):
+ halfCaptionSize = maxCaptionSize / 2
+ captions = []
+ while words:
+ caption = words[0]
+ words = words[1:]
+ while words and len(caption + ' ' + words[0]) <= maxCaptionSize:
+ caption += ' ' + words[0]
+ words = words[1:]
+ if len(caption) >= halfCaptionSize and words:
+ break
+ captions.append(caption)
+ return captions
+
+def getCaptionsWithTime(whisper_analysis, maxCaptionSize=15, considerPunctuation=False):
+ wordLocationToTime = getTimestampMapping(whisper_analysis)
+ position = 0
+ start_time = 0
+ CaptionsPairs = []
+ text = whisper_analysis['text']
+
+ if considerPunctuation:
+ sentences = re.split(r'(?<=[.!?]) +', text)
+ words = [word for sentence in sentences for word in splitWordsBySize(sentence.split(), maxCaptionSize)]
+ else:
+ words = text.split()
+ words = [cleanWord(word) for word in splitWordsBySize(words, maxCaptionSize)]
+
+ for word in words:
+ position += len(word) + 1
+ end_time = interpolateTimeFromDict(position, wordLocationToTime)
+ if end_time and word:
+ CaptionsPairs.append(((start_time, end_time), word))
+ start_time = end_time
+
+ return CaptionsPairs
\ No newline at end of file
diff --git a/shortGPT/editing_utils/editing_images.py b/shortGPT/editing_utils/editing_images.py
new file mode 100644
index 0000000000000000000000000000000000000000..da162120cc931038d2d29fcb7b51e0e5c39da3ef
--- /dev/null
+++ b/shortGPT/editing_utils/editing_images.py
@@ -0,0 +1,20 @@
+from shortGPT.api_utils.image_api import getBingImages
+from tqdm import tqdm
+import random
+import math
+
+def getImageUrlsTimed(imageTextPairs):
+ return [(pair[0], searchImageUrlsFromQuery(pair[1])) for pair in tqdm(imageTextPairs, desc='Search engine queries for images...')]
+
+
+
+def searchImageUrlsFromQuery(query, top=3, expected_dim=[720,720], retries=5):
+ images = getBingImages(query, retries=retries)
+ if(images):
+ distances = list(map(lambda x: math.dist([x['width'], x['height']], expected_dim), images[0:top]))
+ shortest_ones = sorted(distances)
+ random.shuffle(shortest_ones)
+ for distance in shortest_ones:
+ image_url = images[distances.index(distance)]['url']
+ return image_url
+ return None
\ No newline at end of file
diff --git a/shortGPT/editing_utils/handle_videos.py b/shortGPT/editing_utils/handle_videos.py
new file mode 100644
index 0000000000000000000000000000000000000000..7c562c2dd1eb2a7fd39e59aba5500f39dc4a4bf2
--- /dev/null
+++ b/shortGPT/editing_utils/handle_videos.py
@@ -0,0 +1,88 @@
+import ffmpeg
+import os
+import random
+import yt_dlp
+import subprocess
+import json
+
+def getYoutubeVideoLink(url):
+ if 'shorts' in url:
+ ydl_opts = {
+ "quiet": True,
+ "no_warnings": True,
+ "no_color": True,
+ "no_call_home": True,
+ "no_check_certificate": True,
+ "format": "bestvideo[height<=1920]"
+ }
+ else:
+ ydl_opts = {
+ "quiet": True,
+ "no_warnings": True,
+ "no_color": True,
+ "no_call_home": True,
+ "no_check_certificate": True,
+ "format": "bestvideo[height<=1080]"
+ }
+ try:
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
+ dictMeta = ydl.extract_info(
+ url,
+ download=False)
+ return dictMeta['url'], dictMeta['duration']
+ except Exception as e:
+ print("Failed getting video link from the following video/url", e.args[0])
+ return None, None
+
+def extract_random_clip_from_video(video_url, video_duration, clip_duration , output_file):
+ print(video_url, video_duration, clip_duration , output_file)
+ """Extracts a clip from a video using a signed URL.
+ Args:
+ video_url (str): The signed URL of the video.
+ video_url (int): Duration of the video.
+ start_time (int): The start time of the clip in seconds.
+ clip_duration (int): The duration of the clip in seconds.
+ output_file (str): The output file path for the extracted clip.
+ """
+ if not video_duration:
+ raise Exception("Could not get video duration")
+ if not video_duration*0.7 > 120:
+ raise Exception("Video too short")
+ start_time = video_duration*0.15 + random.random()* (0.7*video_duration-clip_duration)
+
+ (
+ ffmpeg
+ .input(video_url, ss=start_time, t=clip_duration)
+ .output(output_file, codec="libx264", preset="ultrafast")
+ .run()
+ )
+ if not os.path.exists(output_file):
+ raise Exception("Random clip failed to be written")
+ return output_file
+
+
+def get_aspect_ratio(video_file):
+ cmd = 'ffprobe -i "{}" -v quiet -print_format json -show_format -show_streams'.format(video_file)
+# jsonstr = subprocess.getoutput(cmd)
+ jsonstr = subprocess.check_output(cmd, shell=True, encoding='utf-8')
+ r = json.loads(jsonstr)
+ # look for "codec_type": "video". take the 1st one if there are mulitple
+ video_stream_info = [x for x in r['streams'] if x['codec_type']=='video'][0]
+ if 'display_aspect_ratio' in video_stream_info and video_stream_info['display_aspect_ratio']!="0:1":
+ a,b = video_stream_info['display_aspect_ratio'].split(':')
+ dar = int(a)/int(b)
+ else:
+ # some video do not have the info of 'display_aspect_ratio'
+ w,h = video_stream_info['width'], video_stream_info['height']
+ dar = int(w)/int(h)
+ ## not sure if we should use this
+ #cw,ch = video_stream_info['coded_width'], video_stream_info['coded_height']
+ #sar = int(cw)/int(ch)
+ if 'sample_aspect_ratio' in video_stream_info and video_stream_info['sample_aspect_ratio']!="0:1":
+ # some video do not have the info of 'sample_aspect_ratio'
+ a,b = video_stream_info['sample_aspect_ratio'].split(':')
+ sar = int(a)/int(b)
+ else:
+ sar = dar
+ par = dar/sar
+ return dar
\ No newline at end of file
diff --git a/shortGPT/engine/README.md b/shortGPT/engine/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..b965ec201844c3e78b176b47d2f03eb6a09be24a
--- /dev/null
+++ b/shortGPT/engine/README.md
@@ -0,0 +1,127 @@
+# **Module: engine**
+
+This module contains the main engine classes for generating different types of short videos. There are four main engine classes in this module:
+
+- `AbstractContentEngine`: This is an abstract base class that provides the basic functionalities and attributes required by all content engines. It implements common methods for initializing the content engine, preparing editing paths, verifying parameters, and rendering the short video.
+
+- `ContentShortEngine`: This class extends `AbstractContentEngine` and is used for generating general content short videos. It implements specific methods for generating a script, generating temporary audio, speeding up the audio, timing captions, generating image search terms, generating image URLs, choosing background music and video, and preparing background and custom assets. It also overrides the `__generateScript` method to generate the script for the content short video.
+
+- `ContentVideoEngine`: This class extends `AbstractContentEngine` and is used for generating general content videos. It implements specific methods for generating temporary audio, speeding up the audio, timing captions, generating video search terms, generating video URLs, choosing background music, and preparing background and custom assets.
+
+- `FactsShortEngine`: This class extends `ContentShortEngine` and is used for generating facts short videos. It overrides the `_generateScript` method to generate the script for the facts short video.
+
+- `RedditShortEngine`: This class extends `ContentShortEngine` and is used for generating reddit short videos. It overrides the `_generateScript` method to generate the script for the reddit short video and adds a custom step for preparing a reddit image.
+
+---
+
+## **File: abstract_content_engine.py**
+
+This file contains the `AbstractContentEngine` class, which is an abstract base class for all content engines. It provides the basic functionalities and attributes required by all content engines.
+
+### **Class: AbstractContentEngine**
+
+#### **Attributes:**
+
+- `CONTENT_DB`: An instance of the `ContentDatabase` class, which is used to store and retrieve content data.
+
+#### **Methods:**
+
+- `__init__(self, short_id: str, content_type:str, language: Language, voiceName: str)`: Initializes an instance of the `AbstractContentEngine` class with the given parameters. It sets the `dataManager`, `id`, `_db_language`, `voiceModule`, `assetStore`, `stepDict`, and `logger` attributes.
+
+- `__getattr__(self, name)`: Overrides the `__getattr__` method to retrieve attributes that start with '_db_' from the `dataManager`.
+
+- `__setattr__(self, name, value)`: Overrides the `__setattr__` method to save attributes that start with '_db_' to the `dataManager`.
+
+- `prepareEditingPaths(self)`: Creates the directory for storing dynamic assets if it doesn't already exist.
+
+- `verifyParameters(*args, **kwargs)`: Verifies that all the required parameters are not null. If any parameter is null, it raises an exception.
+
+- `isShortDone(self)`: Checks if the short video is done rendering by checking the value of the '_db_ready_to_upload' attribute.
+
+- `makeContent(self)`: Generates the short video by executing the steps defined in the `stepDict`. It yields the current step number and a message indicating the progress.
+
+- `get_video_output_path(self)`: Returns the path of the rendered video.
+
+- `get_total_steps(self)`: Returns the total number of steps in the `stepDict`.
+
+- `set_logger(self, logger)`: Sets the logger function for logging the progress of the short video rendering.
+
+- `initializeMagickAndFFMPEG(self)`: Initializes the paths for FFmpeg, FFProbe, and ImageMagick. If any of these programs are not found, it raises an exception.
+
+---
+
+## **File: content_short_engine.py**
+
+This file contains the `ContentShortEngine` class, which is used for generating general content short videos. It extends the `AbstractContentEngine` class and adds specific methods for generating a script, generating temporary audio, speeding up the audio, timing captions, generating image search terms, generating image URLs, choosing background music and video, and preparing background and custom assets.
+
+### **Class: ContentShortEngine**
+
+#### **Attributes:**
+
+- `stepDict`: A dictionary that maps step numbers to their corresponding methods for generating the short video.
+
+#### **Methods:**
+
+- `__init__(self, short_type: str, background_video_name: str, background_music_name: str, short_id="", num_images=None, watermark=None, language: Language = Language.ENGLISH, voiceName="")`: Initializes an instance of the `ContentShortEngine` class with the given parameters. It sets the `stepDict` attribute with the specific methods for generating the short video.
+
+- `__generateScript(self)`: Abstract method that generates the script for the content short video. This method needs to be implemented by the child classes.
+
+- `__prepareCustomAssets(self)`: Abstract method that prepares the custom assets for the content short video. This method needs to be implemented by the child classes.
+
+- `__editAndRenderShort(self)`: Abstract method that performs the editing and rendering of the content short video. This method needs to be implemented by the child classes.
+
+---
+
+## **File: content_video_engine.py**
+
+This file contains the `ContentVideoEngine` class, which is used for generating general content videos. It extends the `AbstractContentEngine` class and adds specific methods for generating temporary audio, speeding up the audio, timing captions, generating video search terms, generating video URLs, choosing background music, and preparing background and custom assets.
+
+### **Class: ContentVideoEngine**
+
+#### **Methods:**
+
+- `__generateTempAudio(self)`: Generates the temporary audio for the content video by using the `voiceModule` to generate a voice from the script.
+
+- `__speedUpAudio(self)`: Speeds up the temporary audio to match the duration of the background video.
+
+- `__timeCaptions(self)`: Converts the audio to text and then generates captions with time based on the text.
+
+- `__generateVideoSearchTerms(self)`: Generates the video search terms by using the timed captions.
+
+- `__generateVideoUrls(self)`: Generates the video URLs by using the video search terms and the `getBestVideo` function from the `pexels_api`.
+
+- `__chooseBackgroundMusic(self)`: Retrieves the background music URL from the `assetStore` based on the background music name.
+
+- `__prepareBackgroundAssets(self)`: Prepares the background assets for the content video by retrieving the voiceover audio duration, trimming the background video, and extracting a random clip from the background video.
+
+- `__prepareCustomAssets(self)`: Abstract method that prepares the custom assets for the content video. This method needs to be implemented by the child classes.
+
+- `__editAndRenderShort(self)`: Performs the editing and rendering of the content video by using the `videoEditor` and the editing steps defined in the `stepDict`.
+
+---
+
+## **File: facts_short_engine.py**
+
+This file contains the `FactsShortEngine` class, which is used for generating facts short videos. It extends the `ContentShortEngine` class and overrides the `_generateScript` method to generate the script for the facts short video.
+
+### **Class: FactsShortEngine**
+
+#### **Methods:**
+
+- `_generateScript(self)`: Generates the script for the facts short video by using the `generateFacts` function from the `facts_gpt` module.
+
+---
+
+## **File: reddit_short_engine.py**
+
+This file contains the `RedditShortEngine` class, which is used for generating reddit short videos. It extends the `ContentShortEngine` class and overrides the `_generateScript` method to generate the script for the reddit short video. It also adds a custom step for preparing a reddit image.
+
+### **Class: RedditShortEngine**
+
+#### **Methods:**
+
+- `_generateScript(self)`: Generates the script for the reddit short video by using the `getInterestingRedditQuestion` function from the `reddit_gpt` module.
+
+- `_prepareCustomAssets(self)`: Prepares the custom assets for the reddit short video by using the `ingestFlow` method from the `imageEditingEngine` to create a reddit image.
+
+- `_editAndRenderShort(self)`: Performs the editing and rendering of the reddit short video by using the `videoEditor` and the editing steps defined in the `stepDict`.
\ No newline at end of file
diff --git a/shortGPT/engine/__init__.py b/shortGPT/engine/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..b7feb036d51f4e90ec5559261788417b0c71c9a8
--- /dev/null
+++ b/shortGPT/engine/__init__.py
@@ -0,0 +1,2 @@
+from . import abstract_content_engine
+from . import reddit_short_engine
\ No newline at end of file
diff --git a/shortGPT/engine/abstract_content_engine.py b/shortGPT/engine/abstract_content_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..de53333b4e0c216b6490df7cdd44f41ecaf2901e
--- /dev/null
+++ b/shortGPT/engine/abstract_content_engine.py
@@ -0,0 +1,95 @@
+import os
+from abc import ABC
+
+from shortGPT.audio.voice_module import VoiceModule
+from shortGPT.config.languages import Language
+from shortGPT.config.path_utils import get_program_path
+from shortGPT.database.content_database import ContentDatabase
+
+CONTENT_DB = ContentDatabase()
+
+
+class AbstractContentEngine(ABC):
+ def __init__(self, short_id: str, content_type: str, language: Language, voiceModule: VoiceModule):
+ if short_id:
+ self.dataManager = CONTENT_DB.getContentDataManager(
+ short_id, content_type
+ )
+ else:
+ self.dataManager = CONTENT_DB.createContentDataManager(content_type)
+ self.id = str(self.dataManager._getId())
+ self.initializeMagickAndFFMPEG()
+ self.prepareEditingPaths()
+ self._db_language = language.value
+ self.voiceModule = voiceModule
+ self.stepDict = {}
+ self.default_logger = lambda _: None
+ self.logger = self.default_logger
+
+ def __getattr__(self, name):
+ if name.startswith('_db_'):
+ db_path = name[4:] # remove '_db_' prefix
+ cache_attr = '_' + name
+ if not hasattr(self, cache_attr):
+ setattr(self, cache_attr, self.dataManager.get(db_path))
+ return getattr(self, cache_attr)
+ else:
+ return super().__getattr__(name)
+
+ def __setattr__(self, name, value):
+ if name.startswith('_db_'):
+ db_path = name[4:] # remove '_db_' prefix
+ cache_attr = '_' + name
+ setattr(self, cache_attr, value)
+ self.dataManager.save(db_path, value)
+ else:
+ super().__setattr__(name, value)
+
+ def prepareEditingPaths(self):
+ self.dynamicAssetDir = f".editing_assets/{self.dataManager.contentType}_assets/{self.id}/"
+ if not os.path.exists(self.dynamicAssetDir):
+ os.makedirs(self.dynamicAssetDir)
+
+ def verifyParameters(*args, **kargs):
+ keys = list(kargs.keys())
+ for key in keys:
+ if not kargs[key]:
+ print(kargs)
+ raise Exception(f"Parameter :{key} is null")
+
+ def isShortDone(self):
+ return self._db_ready_to_upload
+
+ def makeContent(self):
+ while (not self.isShortDone()):
+ currentStep = self._db_last_completed_step + 1
+ if currentStep not in self.stepDict:
+ raise Exception(f'Incorrect step {currentStep}')
+ if self.stepDict[currentStep].__name__ == "_editAndRenderShort":
+ yield currentStep, f'Current step ({currentStep} / {self.get_total_steps()}) : ' + "Preparing rendering assets..."
+ else:
+ yield currentStep, f'Current step ({currentStep} / {self.get_total_steps()}) : ' + self.stepDict[currentStep].__name__
+ if self.logger is not self.default_logger:
+ print(f'Step {currentStep} {self.stepDict[currentStep].__name__}')
+ self.stepDict[currentStep]()
+ self._db_last_completed_step = currentStep
+
+ def get_video_output_path(self):
+ return self._db_video_path
+
+ def get_total_steps(self):
+ return len(self.stepDict)
+
+ def set_logger(self, logger):
+ self.logger = logger
+
+ def initializeMagickAndFFMPEG(self):
+ ffmpeg_path = get_program_path("ffmpeg")
+ if not ffmpeg_path:
+ raise Exception("FFmpeg, a program used for automated editing within ShortGPT was not found on your computer. Please go back to the README and follow the instructions to install FFMPEG")
+ ffprobe_path = get_program_path("ffprobe")
+ if not ffprobe_path:
+ raise Exception("FFProbe, a dependecy of FFmpeg was not found. Please go back to the README and follow the instructions to install FFMPEG")
+ convert_path = get_program_path("convert")
+ if not convert_path:
+ raise Exception("ImageMagick, a program required for making Captions with ShortGPT was not found on your computer. Please go back to the README and follow the instructions to install ImageMagick")
diff --git a/shortGPT/engine/content_short_engine.py b/shortGPT/engine/content_short_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..432ccef3c1bdc90972a6c969a1d68fa2cca51730
--- /dev/null
+++ b/shortGPT/engine/content_short_engine.py
@@ -0,0 +1,168 @@
+import datetime
+import os
+import re
+import shutil
+from abc import abstractmethod
+
+from shortGPT.audio import audio_utils
+from shortGPT.audio.audio_duration import get_asset_duration
+from shortGPT.audio.voice_module import VoiceModule
+from shortGPT.config.asset_db import AssetDatabase
+from shortGPT.config.languages import Language
+from shortGPT.editing_framework.editing_engine import (EditingEngine,
+ EditingStep)
+from shortGPT.editing_utils import captions, editing_images
+from shortGPT.editing_utils.handle_videos import extract_random_clip_from_video
+from shortGPT.engine.abstract_content_engine import AbstractContentEngine
+from shortGPT.gpt import gpt_editing, gpt_translate, gpt_yt
+
+
+class ContentShortEngine(AbstractContentEngine):
+
+ def __init__(self, short_type: str, background_video_name: str, background_music_name: str, voiceModule: VoiceModule, short_id="",
+ num_images=None, watermark=None, language: Language = Language.ENGLISH,):
+ super().__init__(short_id, short_type, language, voiceModule)
+ if not short_id:
+ if (num_images):
+ self._db_num_images = num_images
+ if (watermark):
+ self._db_watermark = watermark
+ self._db_background_video_name = background_video_name
+ self._db_background_music_name = background_music_name
+
+ self.stepDict = {
+ 1: self._generateScript,
+ 2: self._generateTempAudio,
+ 3: self._speedUpAudio,
+ 4: self._timeCaptions,
+ 5: self._generateImageSearchTerms,
+ 6: self._generateImageUrls,
+ 7: self._chooseBackgroundMusic,
+ 8: self._chooseBackgroundVideo,
+ 9: self._prepareBackgroundAssets,
+ 10: self._prepareCustomAssets,
+ 11: self._editAndRenderShort,
+ 12: self._addYoutubeMetadata
+ }
+
+ @abstractmethod
+ def _generateScript(self):
+ self._db_script = ""
+
+ def _generateTempAudio(self):
+ if not self._db_script:
+ raise NotImplementedError("generateScript method must set self._db_script.")
+ if (self._db_temp_audio_path):
+ return
+ self.verifyParameters(text=self._db_script)
+ script = self._db_script
+ if (self._db_language != Language.ENGLISH.value):
+ self._db_translated_script = gpt_translate.translateContent(script, self._db_language)
+ script = self._db_translated_script
+ self._db_temp_audio_path = self.voiceModule.generate_voice(
+ script, self.dynamicAssetDir + "temp_audio_path.wav")
+
+ def _speedUpAudio(self):
+ if (self._db_audio_path):
+ return
+ self.verifyParameters(tempAudioPath=self._db_temp_audio_path)
+ self._db_audio_path = audio_utils.speedUpAudio(
+ self._db_temp_audio_path, self.dynamicAssetDir+"audio_voice.wav")
+
+ def _timeCaptions(self):
+ self.verifyParameters(audioPath=self._db_audio_path)
+ whisper_analysis = audio_utils.audioToText(self._db_audio_path)
+ self._db_timed_captions = captions.getCaptionsWithTime(
+ whisper_analysis)
+
+ def _generateImageSearchTerms(self):
+ self.verifyParameters(captionsTimed=self._db_timed_captions)
+ if self._db_num_images:
+ self._db_timed_image_searches = gpt_editing.getImageQueryPairs(
+ self._db_timed_captions, n=self._db_num_images)
+
+ def _generateImageUrls(self):
+ if self._db_timed_image_searches:
+ self._db_timed_image_urls = editing_images.getImageUrlsTimed(
+ self._db_timed_image_searches)
+
+ def _chooseBackgroundMusic(self):
+ self._db_background_music_url = AssetDatabase.get_asset_link(self._db_background_music_name)
+
+ def _chooseBackgroundVideo(self):
+ self._db_background_video_url = AssetDatabase.get_asset_link(
+ self._db_background_video_name)
+ self._db_background_video_duration = AssetDatabase.get_asset_duration(
+ self._db_background_video_name)
+
+ def _prepareBackgroundAssets(self):
+ self.verifyParameters(
+ voiceover_audio_url=self._db_audio_path,
+ video_duration=self._db_background_video_duration,
+ background_video_url=self._db_background_video_url, music_url=self._db_background_music_url)
+ if not self._db_voiceover_duration:
+ self.logger("Rendering short: (1/4) preparing voice asset...")
+ self._db_audio_path, self._db_voiceover_duration = get_asset_duration(
+ self._db_audio_path, isVideo=False)
+ if not self._db_background_trimmed:
+ self.logger("Rendering short: (2/4) preparing background video asset...")
+ self._db_background_trimmed = extract_random_clip_from_video(
+ self._db_background_video_url, self._db_background_video_duration, self._db_voiceover_duration, self.dynamicAssetDir + "clipped_background.mp4")
+
+ def _prepareCustomAssets(self):
+ self.logger("Rendering short: (3/4) preparing custom assets...")
+ pass
+
+ def _editAndRenderShort(self):
+ self.verifyParameters(
+ voiceover_audio_url=self._db_audio_path,
+ video_duration=self._db_background_video_duration,
+ music_url=self._db_background_music_url)
+
+ outputPath = self.dynamicAssetDir+"rendered_video.mp4"
+ if not (os.path.exists(outputPath)):
+ self.logger("Rendering short: Starting automated editing...")
+ videoEditor = EditingEngine()
+ videoEditor.addEditingStep(EditingStep.ADD_VOICEOVER_AUDIO, {
+ 'url': self._db_audio_path})
+ videoEditor.addEditingStep(EditingStep.ADD_BACKGROUND_MUSIC, {'url': self._db_background_music_url,
+ 'loop_background_music': self._db_voiceover_duration,
+ "volume_percentage": 0.11})
+ videoEditor.addEditingStep(EditingStep.CROP_1920x1080, {
+ 'url': self._db_background_trimmed})
+ videoEditor.addEditingStep(EditingStep.ADD_SUBSCRIBE_ANIMATION, {'url': AssetDatabase.get_asset_link('subscribe animation')})
+
+ if self._db_watermark:
+ videoEditor.addEditingStep(EditingStep.ADD_WATERMARK, {
+ 'text': self._db_watermark})
+
+ caption_type = EditingStep.ADD_CAPTION_SHORT_ARABIC if self._db_language == Language.ARABIC.value else EditingStep.ADD_CAPTION_SHORT
+ for timing, text in self._db_timed_captions:
+ videoEditor.addEditingStep(caption_type, {'text': text.upper(),
+ 'set_time_start': timing[0],
+ 'set_time_end': timing[1]})
+ if self._db_num_images:
+ for timing, image_url in self._db_timed_image_urls:
+ videoEditor.addEditingStep(EditingStep.SHOW_IMAGE, {'url': image_url,
+ 'set_time_start': timing[0],
+ 'set_time_end': timing[1]})
+
+ videoEditor.renderVideo(outputPath, logger= self.logger if self.logger is not self.default_logger else None)
+
+ self._db_video_path = outputPath
+
+ def _addYoutubeMetadata(self):
+
+ self._db_yt_title, self._db_yt_description = gpt_yt.generate_title_description_dict(self._db_script)
+
+ now = datetime.datetime.now()
+ date_str = now.strftime("%Y-%m-%d_%H-%M-%S")
+ newFileName = f"videos/{date_str} - " + \
+ re.sub(r"[^a-zA-Z0-9 '\n\.]", '', self._db_yt_title)
+
+ shutil.move(self._db_video_path, newFileName+".mp4")
+ with open(newFileName+".txt", "w", encoding="utf-8") as f:
+ f.write(
+ f"---Youtube title---\n{self._db_yt_title}\n---Youtube description---\n{self._db_yt_description}")
+ self._db_video_path = newFileName+".mp4"
+ self._db_ready_to_upload = True
diff --git a/shortGPT/engine/content_translation_engine.py b/shortGPT/engine/content_translation_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..a99e2eba07525fe6b76788a68279e4aeb5d40641
--- /dev/null
+++ b/shortGPT/engine/content_translation_engine.py
@@ -0,0 +1,130 @@
+import datetime
+import os
+import re
+import shutil
+
+from tqdm import tqdm
+
+from shortGPT.audio.audio_duration import get_asset_duration
+from shortGPT.audio.audio_utils import (audioToText, get_asset_duration,
+ run_background_audio_split,
+ speedUpAudio)
+from shortGPT.audio.voice_module import VoiceModule
+from shortGPT.config.languages import ACRONYM_LANGUAGE_MAPPING, Language
+from shortGPT.editing_framework.editing_engine import (EditingEngine,
+ EditingStep)
+from shortGPT.editing_utils.captions import (getCaptionsWithTime,
+ getSpeechBlocks)
+from shortGPT.editing_utils.handle_videos import get_aspect_ratio
+from shortGPT.engine.abstract_content_engine import AbstractContentEngine
+from shortGPT.gpt.gpt_translate import translateContent
+
+
+class ContentTranslationEngine(AbstractContentEngine):
+
+ def __init__(self, voiceModule: VoiceModule, src_url: str = "", target_language: Language = Language.ENGLISH, use_captions=False, id=""):
+ super().__init__(id, "content_translation", target_language, voiceModule)
+ if not id:
+ self._db_should_translate = True
+ if src_url:
+ self._db_src_url = src_url
+ self._db_use_captions = use_captions
+ self._db_target_language = target_language.value
+
+ self.stepDict = {
+ 1: self._transcribe_audio,
+ 2: self._translate_content,
+ 3: self._generate_translated_audio,
+ 4: self._edit_and_render_video,
+ 5: self._add_metadata
+ }
+
+ def _transcribe_audio(self):
+ video_audio, _ = get_asset_duration(self._db_src_url, isVideo=False)
+ self.verifyParameters(content_path=video_audio)
+ self.logger(f"1/5 - Transcribing original audio to text...")
+ whispered = audioToText(video_audio, model_size='base')
+ self._db_speech_blocks = getSpeechBlocks(whispered, silence_time=0.8)
+ if (ACRONYM_LANGUAGE_MAPPING.get(whispered['language']) == Language(self._db_target_language)):
+ self._db_translated_timed_sentences = self._db_speech_blocks
+ self._db_should_translate = False
+
+ expected_chars = len("".join([text for _, text in self._db_speech_blocks]))
+ chars_remaining = self.voiceModule.get_remaining_characters()
+ if chars_remaining < expected_chars:
+ raise Exception(
+ f"Your VoiceModule's key doesn't have enough characters to totally translate this video | Remaining: {chars_remaining} | Number of characters to translate: {expected_chars}")
+
+ def _translate_content(self):
+ if (self._db_should_translate):
+ self.verifyParameters(_db_speech_blocks=self._db_speech_blocks)
+
+ translated_timed_sentences = []
+ for i, ((t1, t2), text) in tqdm(enumerate(self._db_speech_blocks), desc="Translating content"):
+ self.logger(f"2/5 - Translating text content - {i+1} / {len(self._db_speech_blocks)}")
+ translated_text = translateContent(text, self._db_target_language)
+ translated_timed_sentences.append([[t1, t2], translated_text])
+ self._db_translated_timed_sentences = translated_timed_sentences
+
+ def _generate_translated_audio(self):
+ self.verifyParameters(translated_timed_sentences=self._db_translated_timed_sentences)
+
+ translated_audio_blocks = []
+ for i, ((t1, t2), translated_text) in tqdm(enumerate(self._db_translated_timed_sentences), desc="Generating translated audio"):
+ self.logger(f"3/5 - Generating translated audio - {i+1} / {len(self._db_translated_timed_sentences)}")
+ translated_voice = self.voiceModule.generate_voice(translated_text, self.dynamicAssetDir+f"translated_{i}_{self._db_target_language}.wav")
+ if not translated_voice:
+ raise Exception('An error happending during audio voice creation')
+ final_audio_path = speedUpAudio(translated_voice, self.dynamicAssetDir+f"translated_{i}_{self._db_target_language}_spedup.wav", expected_duration=t2-t1 - 0.05)
+ _, translated_duration = get_asset_duration(final_audio_path, isVideo=False)
+ translated_audio_blocks.append([[t1, t1+translated_duration], final_audio_path])
+ self._db_audio_bits = translated_audio_blocks
+
+ def _edit_and_render_video(self):
+ self.verifyParameters(_db_audio_bits=self._db_audio_bits)
+ self.logger(f"4.1 / 5 - Preparing automated editing")
+ target_language = Language(self._db_target_language)
+ input_video, video_length = get_asset_duration(self._db_src_url)
+ video_audio, _ = get_asset_duration(self._db_src_url, isVideo=False)
+ editing_engine = EditingEngine()
+ editing_engine.addEditingStep(EditingStep.ADD_BACKGROUND_VIDEO, {'url': input_video, "set_time_start": 0, "set_time_end": video_length})
+ last_t2 = 0
+ for (t1, t2), audio_path in self._db_audio_bits:
+ t2+=-0.05
+ editing_engine.addEditingStep(EditingStep.INSERT_AUDIO, {'url': audio_path, 'set_time_start': t1, 'set_time_end': t2})
+ if t1-last_t2 >4:
+ editing_engine.addEditingStep(EditingStep.EXTRACT_AUDIO, {"url": video_audio, "subclip": {"t_start": last_t2, "t_end": t1}, "set_time_start": last_t2, "set_time_end": t1})
+ last_t2 = t2
+
+ if video_length - last_t2 >4:
+ editing_engine.addEditingStep(EditingStep.EXTRACT_AUDIO, {"url": video_audio, "subclip": {"t_start": last_t2, "t_end": video_length}, "set_time_start": last_t2, "set_time_end": video_length})
+
+ if self._db_use_captions:
+ is_landscape = get_aspect_ratio(input_video) > 1
+ if not self._db_timed_translated_captions:
+ if not self._db_translated_voiceover_path:
+ self.logger(f"4.5 / 5 - Generating captions in {target_language.value}")
+ editing_engine.generateAudio(self.dynamicAssetDir+"translated_voiceover.wav")
+ self._db_translated_voiceover_path = self.dynamicAssetDir+"translated_voiceover.wav"
+ whispered_translated = audioToText(self._db_translated_voiceover_path, model_size='base')
+ timed_translated_captions = getCaptionsWithTime(whispered_translated, maxCaptionSize=50 if is_landscape else 15, considerPunctuation=True)
+ self._db_timed_translated_captions = [[[t1,t2], text] for (t1, t2), text in timed_translated_captions if t2 - t1 <= 4]
+ for (t1, t2), text in self._db_timed_translated_captions:
+ caption_key = "LANDSCAPE" if is_landscape else "SHORT"
+ caption_key += "_ARABIC" if target_language == Language.ARABIC else ""
+ caption_type = getattr(EditingStep, f"ADD_CAPTION_{caption_key}")
+ editing_engine.addEditingStep(caption_type, {'text': text, "set_time_start": t1, "set_time_end": t2})
+
+ self._db_video_path = self.dynamicAssetDir+"translated_content.mp4"
+
+ editing_engine.renderVideo(self._db_video_path, logger= self.logger if self.logger is not self.default_logger else None)
+ def _add_metadata(self):
+ self.logger(f"5 / 5 - Saving translated video")
+ now = datetime.datetime.now()
+ date_str = now.strftime("%Y-%m-%d_%H-%M-%S")
+ newFileName = f"videos/{date_str} - " + \
+ re.sub(r"[^a-zA-Z0-9 '\n\.]", '', f"translated_content_to_{self._db_target_language}")
+
+ shutil.move(self._db_video_path, newFileName+".mp4")
+ self._db_video_path = newFileName+".mp4"
+ self._db_ready_to_upload = True
diff --git a/shortGPT/engine/content_video_engine.py b/shortGPT/engine/content_video_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..5f6befe741b51413429d182c3198e5e7b1fbca1b
--- /dev/null
+++ b/shortGPT/engine/content_video_engine.py
@@ -0,0 +1,158 @@
+import datetime
+import os
+import re
+import shutil
+
+from shortGPT.api_utils.pexels_api import getBestVideo
+from shortGPT.audio import audio_utils
+from shortGPT.audio.audio_duration import get_asset_duration
+from shortGPT.audio.voice_module import VoiceModule
+from shortGPT.config.asset_db import AssetDatabase
+from shortGPT.config.languages import Language
+from shortGPT.editing_framework.editing_engine import (EditingEngine,
+ EditingStep)
+from shortGPT.editing_utils import captions
+from shortGPT.engine.abstract_content_engine import AbstractContentEngine
+from shortGPT.gpt import gpt_editing, gpt_translate, gpt_yt
+
+
+class ContentVideoEngine(AbstractContentEngine):
+
+ def __init__(self, voiceModule: VoiceModule, script: str, background_music_name="", id="",
+ watermark=None, isVerticalFormat=False, language: Language = Language.ENGLISH):
+ super().__init__(id, "general_video", language, voiceModule)
+ if not id:
+ if (watermark):
+ self._db_watermark = watermark
+ if background_music_name:
+ self._db_background_music_name = background_music_name
+ self._db_script = script
+ self._db_format_vertical = isVerticalFormat
+
+ self.stepDict = {
+ 1: self._generateTempAudio,
+ 2: self._speedUpAudio,
+ 3: self._timeCaptions,
+ 4: self._generateVideoSearchTerms,
+ 5: self._generateVideoUrls,
+ 6: self._chooseBackgroundMusic,
+ 7: self._prepareBackgroundAssets,
+ 8: self._prepareCustomAssets,
+ 9: self._editAndRenderShort,
+ 10: self._addMetadata
+ }
+
+ def _generateTempAudio(self):
+ if not self._db_script:
+ raise NotImplementedError("generateScript method must set self._db_script.")
+ if (self._db_temp_audio_path):
+ return
+ self.verifyParameters(text=self._db_script)
+ script = self._db_script
+ if (self._db_language != Language.ENGLISH.value):
+ self._db_translated_script = gpt_translate.translateContent(script, self._db_language)
+ script = self._db_translated_script
+ self._db_temp_audio_path = self.voiceModule.generate_voice(
+ script, self.dynamicAssetDir + "temp_audio_path.wav")
+
+ def _speedUpAudio(self):
+ if (self._db_audio_path):
+ return
+ self.verifyParameters(tempAudioPath=self._db_temp_audio_path)
+ # Since the video is not supposed to be a short( less than 60sec), there is no reason to speed it up
+ self._db_audio_path = self._db_temp_audio_path
+ return
+ self._db_audio_path = audio_utils.speedUpAudio(
+ self._db_temp_audio_path, self.dynamicAssetDir+"audio_voice.wav")
+
+ def _timeCaptions(self):
+ self.verifyParameters(audioPath=self._db_audio_path)
+ whisper_analysis = audio_utils.audioToText(self._db_audio_path)
+ max_len = 15
+ if not self._db_format_vertical:
+ max_len = 30
+ self._db_timed_captions = captions.getCaptionsWithTime(
+ whisper_analysis, maxCaptionSize=max_len)
+
+ def _generateVideoSearchTerms(self):
+ self.verifyParameters(captionsTimed=self._db_timed_captions)
+ # Returns a list of pairs of timing (t1,t2) + 3 search video queries, such as: [[t1,t2], [search_query_1, search_query_2, search_query_3]]
+ self._db_timed_video_searches = gpt_editing.getVideoSearchQueriesTimed(self._db_timed_captions)
+
+ def _generateVideoUrls(self):
+ timed_video_searches = self._db_timed_video_searches
+ self.verifyParameters(captionsTimed=timed_video_searches)
+ timed_video_urls = []
+ used_links = []
+ for (t1, t2), search_terms in timed_video_searches:
+ url = ""
+ for query in reversed(search_terms):
+ url = getBestVideo(query, orientation_landscape=not self._db_format_vertical, used_vids=used_links)
+ if url:
+ used_links.append(url.split('.hd')[0])
+ break
+ timed_video_urls.append([[t1, t2], url])
+ self._db_timed_video_urls = timed_video_urls
+
+ def _chooseBackgroundMusic(self):
+ if self._db_background_music_name:
+ self._db_background_music_url = AssetDatabase.get_asset_link(self._db_background_music_name)
+
+ def _prepareBackgroundAssets(self):
+ self.verifyParameters(voiceover_audio_url=self._db_audio_path)
+ if not self._db_voiceover_duration:
+ self.logger("Rendering short: (1/4) preparing voice asset...")
+ self._db_audio_path, self._db_voiceover_duration = get_asset_duration(
+ self._db_audio_path, isVideo=False)
+
+ def _prepareCustomAssets(self):
+ self.logger("Rendering short: (3/4) preparing custom assets...")
+ pass
+
+ def _editAndRenderShort(self):
+ self.verifyParameters(
+ voiceover_audio_url=self._db_audio_path)
+
+ outputPath = self.dynamicAssetDir+"rendered_video.mp4"
+ if not (os.path.exists(outputPath)):
+ self.logger("Rendering short: Starting automated editing...")
+ videoEditor = EditingEngine()
+ videoEditor.addEditingStep(EditingStep.ADD_VOICEOVER_AUDIO, {
+ 'url': self._db_audio_path})
+ if (self._db_background_music_url):
+ videoEditor.addEditingStep(EditingStep.ADD_BACKGROUND_MUSIC, {'url': self._db_background_music_url,
+ 'loop_background_music': self._db_voiceover_duration,
+ "volume_percentage": 0.08})
+ for (t1, t2), video_url in self._db_timed_video_urls:
+ videoEditor.addEditingStep(EditingStep.ADD_BACKGROUND_VIDEO, {'url': video_url,
+ 'set_time_start': t1,
+ 'set_time_end': t2})
+ if (self._db_format_vertical):
+ caption_type = EditingStep.ADD_CAPTION_SHORT_ARABIC if self._db_language == Language.ARABIC.value else EditingStep.ADD_CAPTION_SHORT
+ else:
+ caption_type = EditingStep.ADD_CAPTION_LANDSCAPE_ARABIC if self._db_language == Language.ARABIC.value else EditingStep.ADD_CAPTION_LANDSCAPE
+
+ for (t1, t2), text in self._db_timed_captions:
+ videoEditor.addEditingStep(caption_type, {'text': text.upper(),
+ 'set_time_start': t1,
+ 'set_time_end': t2})
+
+ videoEditor.renderVideo(outputPath, logger= self.logger if self.logger is not self.default_logger else None)
+
+ self._db_video_path = outputPath
+
+ def _addMetadata(self):
+
+ self._db_yt_title, self._db_yt_description = gpt_yt.generate_title_description_dict(self._db_script)
+
+ now = datetime.datetime.now()
+ date_str = now.strftime("%Y-%m-%d_%H-%M-%S")
+ newFileName = f"videos/{date_str} - " + \
+ re.sub(r"[^a-zA-Z0-9 '\n\.]", '', self._db_yt_title)
+
+ shutil.move(self._db_video_path, newFileName+".mp4")
+ with open(newFileName+".txt", "w", encoding="utf-8") as f:
+ f.write(
+ f"---Youtube title---\n{self._db_yt_title}\n---Youtube description---\n{self._db_yt_description}")
+ self._db_video_path = newFileName+".mp4"
+ self._db_ready_to_upload = True
diff --git a/shortGPT/engine/facts_short_engine.py b/shortGPT/engine/facts_short_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..4466a9917744fe452f8d8db5b8642d982e7b9b1e
--- /dev/null
+++ b/shortGPT/engine/facts_short_engine.py
@@ -0,0 +1,21 @@
+from shortGPT.audio.voice_module import VoiceModule
+from shortGPT.gpt import facts_gpt
+from shortGPT.config.languages import Language
+from shortGPT.engine.content_short_engine import ContentShortEngine
+
+
+class FactsShortEngine(ContentShortEngine):
+
+ def __init__(self, voiceModule: VoiceModule, facts_type: str, background_video_name: str, background_music_name: str,short_id="",
+ num_images=None, watermark=None, language:Language = Language.ENGLISH):
+ super().__init__(short_id=short_id, short_type="facts_shorts", background_video_name=background_video_name, background_music_name=background_music_name,
+ num_images=num_images, watermark=watermark, language=language, voiceModule=voiceModule)
+
+ self._db_facts_type = facts_type
+
+ def _generateScript(self):
+ """
+ Implements Abstract parent method to generate the script for the Facts short.
+ """
+ self._db_script = facts_gpt.generateFacts(self._db_facts_type)
+
diff --git a/shortGPT/engine/multi_language_translation_engine.py b/shortGPT/engine/multi_language_translation_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..af13c28f1d9240a803270150326202e9deaa5979
--- /dev/null
+++ b/shortGPT/engine/multi_language_translation_engine.py
@@ -0,0 +1,138 @@
+import datetime
+import os
+import re
+import shutil
+
+from tqdm import tqdm
+
+from shortGPT.audio.audio_duration import get_asset_duration
+from shortGPT.audio.audio_utils import (audioToText, get_asset_duration,
+ run_background_audio_split,
+ speedUpAudio)
+from shortGPT.audio.eleven_voice_module import VoiceModule
+from shortGPT.config.languages import ACRONYM_LANGUAGE_MAPPING, Language
+from shortGPT.editing_framework.editing_engine import (EditingEngine,
+ EditingStep)
+from shortGPT.editing_utils.captions import (getCaptionsWithTime,
+ getSpeechBlocks)
+from shortGPT.editing_utils.handle_videos import get_aspect_ratio
+from shortGPT.engine.abstract_content_engine import CONTENT_DB, AbstractContentEngine
+from shortGPT.gpt.gpt_translate import translateContent
+
+class MultiLanguageTranslationEngine(AbstractContentEngine):
+
+ def __init__(self, voiceModule: VoiceModule, src_url: str = "", target_language: Language = Language.ENGLISH, use_captions=False, id=""):
+ super().__init__(id, "content_translation", target_language, voiceModule)
+ if not id:
+ self._db_should_translate = True
+ if src_url:
+ self._db_src_url = src_url
+ self._db_use_captions = use_captions
+ self._db_target_language = target_language.value
+
+ self.stepDict = {
+ 1: self._transcribe_audio,
+ 2: self._translate_content,
+ 3: self._generate_translated_audio,
+ 4: self._edit_and_render_video,
+ 5: self._add_metadata
+ }
+
+ def _transcribe_audio(self):
+ cached_translation = CONTENT_DB.content_collection.find_one({
+ "content_type": 'content_translation',
+ 'src_url': self._db_src_url,
+ 'ready_to_upload': True
+ })
+ if not (cached_translation and 'speech_blocks' in cached_translation and 'original_language' in cached_translation):
+ video_audio, _ = get_asset_duration(self._db_src_url, isVideo=False)
+ self.verifyParameters(content_path=video_audio)
+ self.logger(f"1/5 - Transcribing original audio to text...")
+ whispered = audioToText(video_audio, model_size='base')
+ self._db_speech_blocks = getSpeechBlocks(whispered, silence_time=0.8)
+ self._db_original_language = whispered['language']
+
+ if (ACRONYM_LANGUAGE_MAPPING.get(self._db_original_language) == Language(self._db_target_language)):
+ self._db_translated_timed_sentences = self._db_speech_blocks
+ self._db_should_translate = False
+
+ expected_chars = len("".join([text for _, text in self._db_speech_blocks]))
+ chars_remaining = self.voiceModule.get_remaining_characters()
+ if chars_remaining < expected_chars:
+ raise Exception(
+ f"Your VoiceModule's key doesn't have enough characters to totally translate this video | Remaining: {chars_remaining} | Number of characters to translate: {expected_chars}")
+
+ def _translate_content(self):
+ if (self._db_should_translate):
+ self.verifyParameters(_db_speech_blocks=self._db_speech_blocks)
+
+ translated_timed_sentences = []
+ for i, ((t1, t2), text) in tqdm(enumerate(self._db_speech_blocks), desc="Translating content"):
+ self.logger(f"2/5 - Translating text content - {i+1} / {len(self._db_speech_blocks)}")
+ translated_text = translateContent(text, self._db_target_language)
+ translated_timed_sentences.append([[t1, t2], translated_text])
+ self._db_translated_timed_sentences = translated_timed_sentences
+
+ def _generate_translated_audio(self):
+ self.verifyParameters(translated_timed_sentences=self._db_translated_timed_sentences)
+
+ translated_audio_blocks = []
+ for i, ((t1, t2), translated_text) in tqdm(enumerate(self._db_translated_timed_sentences), desc="Generating translated audio"):
+ self.logger(f"3/5 - Generating translated audio - {i+1} / {len(self._db_translated_timed_sentences)}")
+ translated_voice = self.voiceModule.generate_voice(translated_text, self.dynamicAssetDir+f"translated_{i}_{self._db_target_language}.wav")
+ if not translated_voice:
+ raise Exception('An error happending during audio voice creation')
+ final_audio_path = speedUpAudio(translated_voice, self.dynamicAssetDir+f"translated_{i}_{self._db_target_language}_spedup.wav", expected_duration=t2-t1 - 0.05)
+ _, translated_duration = get_asset_duration(final_audio_path, isVideo=False)
+ translated_audio_blocks.append([[t1, t1+translated_duration], final_audio_path])
+ self._db_audio_bits = translated_audio_blocks
+
+ def _edit_and_render_video(self):
+ self.verifyParameters(_db_audio_bits=self._db_audio_bits)
+ self.logger(f"4.1 / 5 - Preparing automated editing")
+ target_language = Language(self._db_target_language)
+ input_video, video_length = get_asset_duration(self._db_src_url)
+ video_audio, _ = get_asset_duration(self._db_src_url, isVideo=False)
+ editing_engine = EditingEngine()
+ editing_engine.addEditingStep(EditingStep.ADD_BACKGROUND_VIDEO, {'url': input_video, "set_time_start": 0, "set_time_end": video_length})
+ last_t2 = 0
+ for (t1, t2), audio_path in self._db_audio_bits:
+ t2+=-0.05
+ editing_engine.addEditingStep(EditingStep.INSERT_AUDIO, {'url': audio_path, 'set_time_start': t1, 'set_time_end': t2})
+ if t1-last_t2 >4:
+ editing_engine.addEditingStep(EditingStep.EXTRACT_AUDIO, {"url": video_audio, "subclip": {"t_start": last_t2, "t_end": t1}, "set_time_start": last_t2, "set_time_end": t1})
+ last_t2 = t2
+
+ if video_length - last_t2 >4:
+ editing_engine.addEditingStep(EditingStep.EXTRACT_AUDIO, {"url": video_audio, "subclip": {"t_start": last_t2, "t_end": video_length}, "set_time_start": last_t2, "set_time_end": video_length})
+
+ if self._db_use_captions:
+ is_landscape = get_aspect_ratio(input_video) > 1
+ if not self._db_timed_translated_captions:
+ if not self._db_translated_voiceover_path:
+ self.logger(f"4.5 / 5 - Generating captions in {target_language.value}")
+ editing_engine.generateAudio(self.dynamicAssetDir+"translated_voiceover.wav")
+ self._db_translated_voiceover_path = self.dynamicAssetDir+"translated_voiceover.wav"
+ whispered_translated = audioToText(self._db_translated_voiceover_path, model_size='base')
+ timed_translated_captions = getCaptionsWithTime(whispered_translated, maxCaptionSize=50 if is_landscape else 15, considerPunctuation=True)
+ self._db_timed_translated_captions = [[[t1,t2], text] for (t1, t2), text in timed_translated_captions if t2 - t1 <= 4]
+ for (t1, t2), text in self._db_timed_translated_captions:
+ caption_key = "LANDSCAPE" if is_landscape else "SHORT"
+ caption_key += "_ARABIC" if target_language == Language.ARABIC else ""
+ caption_type = getattr(EditingStep, f"ADD_CAPTION_{caption_key}")
+ editing_engine.addEditingStep(caption_type, {'text': text, "set_time_start": t1, "set_time_end": t2})
+
+ self._db_video_path = self.dynamicAssetDir+"translated_content.mp4"
+
+ editing_engine.renderVideo(self._db_video_path, logger= self.logger if self.logger is not self.default_logger else None)
+
+ def _add_metadata(self):
+ self.logger(f"5 / 5 - Saving translated video")
+ now = datetime.datetime.now()
+ date_str = now.strftime("%Y-%m-%d_%H-%M-%S")
+ newFileName = f"videos/{date_str} - " + \
+ re.sub(r"[^a-zA-Z0-9 '\n\.]", '', f"translated_content_to_{self._db_target_language}")
+
+ shutil.move(self._db_video_path, newFileName+".mp4")
+ self._db_video_path = newFileName+".mp4"
+ self._db_ready_to_upload = True
diff --git a/shortGPT/engine/reddit_short_engine.py b/shortGPT/engine/reddit_short_engine.py
new file mode 100644
index 0000000000000000000000000000000000000000..d3f7652adf580896bd98f93296217329736a96f5
--- /dev/null
+++ b/shortGPT/engine/reddit_short_engine.py
@@ -0,0 +1,105 @@
+from shortGPT.audio.voice_module import VoiceModule
+from shortGPT.config.asset_db import AssetDatabase
+from shortGPT.config.languages import Language
+from shortGPT.engine.content_short_engine import ContentShortEngine
+from shortGPT.editing_framework.editing_engine import EditingEngine, EditingStep, Flow
+from shortGPT.gpt import reddit_gpt, gpt_voice
+import os
+
+
+class RedditShortEngine(ContentShortEngine):
+ # Mapping of variable names to database paths
+ def __init__(self,voiceModule: VoiceModule, background_video_name: str, background_music_name: str,short_id="",
+ num_images=None, watermark=None, language:Language = Language.ENGLISH):
+ super().__init__(short_id=short_id, short_type="reddit_shorts", background_video_name=background_video_name, background_music_name=background_music_name,
+ num_images=num_images, watermark=watermark, language=language, voiceModule=voiceModule)
+
+ def __generateRandomStory(self):
+ question = reddit_gpt.getInterestingRedditQuestion()
+ script = reddit_gpt.createRedditScript(question)
+ return script
+
+ def __getRealisticStory(self, max_tries=3):
+ current_realistic_score = 0
+ current_try = 0
+ current_generated_script = ""
+ while (current_realistic_score < 6 and current_try < max_tries) or len(current_generated_script) > 1000:
+ new_script = self.__generateRandomStory()
+ new_realistic_score = reddit_gpt.getRealisticness(new_script)
+ if new_realistic_score >= current_realistic_score:
+ current_generated_script = new_script
+ current_realistic_score = new_realistic_score
+ current_try += 1
+ return current_generated_script, current_try
+
+ def _generateScript(self):
+ """
+ Implements Abstract parent method to generate the script for the reddit short
+ """
+ self.logger("Generating reddit question & entertaining story")
+ self._db_script, _ = self.__getRealisticStory(max_tries=1)
+ self._db_reddit_question = reddit_gpt.getQuestionFromThread(
+ self._db_script)
+
+ def _prepareCustomAssets(self):
+ """
+ Override parent method to generate custom reddit image asset
+ """
+ self.logger("Rendering short: (3/4) preparing custom reddit image...")
+ self.verifyParameters(question=self._db_reddit_question,)
+ title, header, n_comments, n_upvotes = reddit_gpt.generateRedditPostMetadata(
+ self._db_reddit_question)
+ imageEditingEngine = EditingEngine()
+ imageEditingEngine.ingestFlow(Flow.WHITE_REDDIT_IMAGE_FLOW, {
+ "username_text": header,
+ "ncomments_text": n_comments,
+ "nupvote_text": n_upvotes,
+ "question_text": title
+ })
+ imageEditingEngine.renderImage(
+ self.dynamicAssetDir+"redditThreadImage.png")
+ self._db_reddit_thread_image = self.dynamicAssetDir+"redditThreadImage.png"
+
+ def _editAndRenderShort(self):
+ """
+ Override parent method to customize video rendering sequence by adding a Reddit image
+ """
+ self.verifyParameters(
+ voiceover_audio_url=self._db_audio_path,
+ video_duration=self._db_background_video_duration,
+ music_url=self._db_background_music_url)
+
+ outputPath = self.dynamicAssetDir+"rendered_video.mp4"
+ if not (os.path.exists(outputPath)):
+ self.logger("Rendering short: Starting automated editing...")
+ videoEditor = EditingEngine()
+ videoEditor.addEditingStep(EditingStep.ADD_VOICEOVER_AUDIO, {
+ 'url': self._db_audio_path})
+ videoEditor.addEditingStep(EditingStep.ADD_BACKGROUND_MUSIC, {'url': self._db_background_music_url,
+ 'loop_background_music': self._db_voiceover_duration,
+ "volume_percentage": 0.11})
+ videoEditor.addEditingStep(EditingStep.CROP_1920x1080, {
+ 'url': self._db_background_trimmed})
+ videoEditor.addEditingStep(EditingStep.ADD_SUBSCRIBE_ANIMATION, {'url': AssetDatabase.get_asset_link('subscribe animation')})
+
+ if self._db_watermark:
+ videoEditor.addEditingStep(EditingStep.ADD_WATERMARK, {
+ 'text': self._db_watermark})
+ videoEditor.addEditingStep(EditingStep.ADD_REDDIT_IMAGE, {
+ 'url': self._db_reddit_thread_image})
+
+ caption_type = EditingStep.ADD_CAPTION_SHORT_ARABIC if self._db_language == Language.ARABIC.value else EditingStep.ADD_CAPTION_SHORT
+ for timing, text in self._db_timed_captions:
+ videoEditor.addEditingStep(caption_type, {'text': text.upper(),
+ 'set_time_start': timing[0],
+ 'set_time_end': timing[1]})
+ if self._db_num_images:
+ for timing, image_url in self._db_timed_image_urls:
+ videoEditor.addEditingStep(EditingStep.SHOW_IMAGE, {'url': image_url,
+ 'set_time_start': timing[0],
+ 'set_time_end': timing[1]})
+
+ videoEditor.renderVideo(outputPath, logger= self.logger if self.logger is not self.default_logger else None)
+
+ self._db_video_path = outputPath
+
diff --git a/shortGPT/gpt/README.md b/shortGPT/gpt/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..e2f2b63bc7ae30c37533f4b41a5610aebbd4401b
--- /dev/null
+++ b/shortGPT/gpt/README.md
@@ -0,0 +1,129 @@
+# Module: gpt
+
+The `gpt` module provides various functions for working with the OpenAI GPT-3 API. This module consists of multiple files, each serving a specific purpose. Let's take a look at each file and its contents.
+
+## File: gpt_utils.py
+
+This file contains utility functions used by other files in the module. Here are the functions defined in this file:
+
+### `num_tokens_from_messages(texts, model="gpt-3.5-turbo-0301")`
+
+This function calculates the number of tokens used by a list of messages. It takes the `texts` parameter as input, which can be either a string or a list of strings. The function returns the total number of tokens used.
+
+### `extract_biggest_json(string)`
+
+This function extracts the largest JSON object from a string. It searches for JSON objects using a regular expression and returns the object with the maximum length.
+
+### `get_first_number(string)`
+
+This function searches for the first occurrence of a number in a string and returns it. It uses a regular expression to match the number.
+
+### `load_yaml_file(file_path: str) -> dict`
+
+This function reads and returns the contents of a YAML file as a dictionary. It takes the file path as input and uses the `yaml.safe_load()` function to parse the YAML file.
+
+### `load_json_file(file_path)`
+
+This function reads and returns the contents of a JSON file. It takes the file path as input and uses the `json.load()` function to parse the JSON file.
+
+### `load_local_yaml_prompt(file_path)`
+
+This function loads a YAML file containing chat and system prompts and returns the chat and system prompts as separate strings.
+
+### `open_file(filepath)`
+
+This function opens and reads a file and returns its contents as a string. It takes the file path as input and uses the `open()` function to read the file.
+
+### `gpt3Turbo_completion(chat_prompt="", system="You are an AI that can give the answer to anything", temp=0.7, model="gpt-3.5-turbo", max_tokens=1000, remove_nl=True, conversation=None)`
+
+This function performs a GPT-3 completion using the OpenAI API. It takes various parameters such as chat prompt, system prompt, temperature, model, and maximum tokens. It returns the generated text as a response from the GPT-3 model.
+
+## File: reddit_gpt.py
+
+This file contains functions related to generating Reddit posts. Here are the functions defined in this file:
+
+### `generateRedditPostMetadata(title)`
+
+This function generates metadata for a Reddit post. It takes the post title as input and returns the title, header, number of comments, and number of upvotes.
+
+### `getInterestingRedditQuestion()`
+
+This function generates an interesting question for a Reddit post. It uses a YAML file containing chat and system prompts to generate the question.
+
+### `createRedditScript(question)`
+
+This function creates a Reddit script based on a given question. It uses a YAML file containing chat and system prompts to generate the script.
+
+### `getRealisticness(text)`
+
+This function calculates the realisticness score of a given text. It uses a YAML file containing chat and system prompts to generate the score.
+
+### `getQuestionFromThread(text)`
+
+This function extracts a question from a Reddit thread. It takes the thread text as input and uses a YAML file containing chat and system prompts to generate the question.
+
+### `generateUsername()`
+
+This function generates a username for a Reddit post. It uses a YAML file containing chat and system prompts to generate the username.
+
+## File: gpt_translate.py
+
+This file contains functions related to translating content using GPT-3. Here is the function defined in this file:
+
+### `translateContent(content, language)`
+
+This function translates the given content to the specified language. It takes the content and language as input and uses a YAML file containing chat and system prompts to perform the translation.
+
+## File: facts_gpt.py
+
+This file contains functions related to generating facts using GPT-3. Here are the functions defined in this file:
+
+### `generateFacts(facts_type)`
+
+This function generates facts of a specific type. It takes the facts type as input and uses a YAML file containing chat and system prompts to generate the facts.
+
+### `generateFactSubjects(n)`
+
+This function generates a list of fact subjects. It takes the number of subjects to generate as input and uses a YAML file containing chat and system prompts to generate the subjects.
+
+## File: gpt_yt.py
+
+This file contains functions related to generating YouTube video titles and descriptions using GPT-3. Here is the function defined in this file:
+
+### `generate_title_description_dict(content)`
+
+This function generates a title and description for a YouTube video based on the given content. It takes the content as input and uses a YAML file containing chat and system prompts to generate the title and description.
+
+## File: gpt_editing.py
+
+This file contains functions related to image and video editing using GPT-3. Here are the functions defined in this file:
+
+### `getImageQueryPairs(captions, n=15, maxTime=2)`
+
+This function generates pairs of image queries and their corresponding timestamps based on the given captions. It takes the captions, number of queries to generate, and maximum time between queries as input. It uses a YAML file containing chat prompts to generate the queries.
+
+### `getVideoSearchQueriesTimed(captions_timed)`
+
+This function generates timed video search queries based on the given captions with timestamps. It takes the captions with timestamps as input and uses a YAML file containing chat and system prompts to generate the queries.
+
+## File: gpt_chat_video.py
+
+This file contains functions related to generating chat video scripts using GPT-3. Here are the functions defined in this file:
+
+### `generateScript(script_description, language)`
+
+This function generates a script for a chat video based on the given description and language. It takes the script description and language as input and uses a YAML file containing chat and system prompts to generate the script.
+
+### `correctScript(script, correction)`
+
+This function corrects a script for a chat video based on the given original script and correction. It takes the original script and correction as input and uses a YAML file containing chat and system prompts to correct the script.
+
+## File: gpt_voice.py
+
+This file contains a function related to identifying the gender of a text using GPT-3. Here is the function defined in this file:
+
+### `getGenderFromText(text)`
+
+This function identifies the gender of a given text. It takes the text as input and uses a YAML file containing chat and system prompts to perform gender identification. It returns either "female" or "male" as the gender.
+
+These are the functions and their descriptions provided by the `gpt` module. Each function serves a specific purpose and can be used to perform various tasks related to GPT-3.
\ No newline at end of file
diff --git a/shortGPT/gpt/__init__.py b/shortGPT/gpt/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..3fb297b4bc136d470aa2337b6c868e6de7f59068
--- /dev/null
+++ b/shortGPT/gpt/__init__.py
@@ -0,0 +1,2 @@
+from . import gpt_utils
+from . import reddit_gpt
\ No newline at end of file
diff --git a/shortGPT/gpt/facts_gpt.py b/shortGPT/gpt/facts_gpt.py
new file mode 100644
index 0000000000000000000000000000000000000000..8249bd353336bcaa84bb31219db6ff2fdf002d5b
--- /dev/null
+++ b/shortGPT/gpt/facts_gpt.py
@@ -0,0 +1,23 @@
+from shortGPT.gpt import gpt_utils
+import json
+def generateFacts(facts_type):
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/facts_generator.yaml')
+ chat = chat.replace("<>", facts_type)
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1.3)
+ return result
+
+def generateFactSubjects(n):
+ out = []
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/facts_subjects_generation.yaml')
+ chat = chat.replace("<>", f"{n}")
+ count = 0
+ while len(out) != n:
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1.69)
+ count+=1
+ try:
+ out = json.loads(result.replace("'", '"'))
+ except Exception as e:
+ print(f"INFO - Failed generating {n} fact subjects after {count} trials", e)
+ pass
+
+ return out
\ No newline at end of file
diff --git a/shortGPT/gpt/gpt_chat_video.py b/shortGPT/gpt/gpt_chat_video.py
new file mode 100644
index 0000000000000000000000000000000000000000..3199ed6f4805e1e07d9f49795399accf205fac09
--- /dev/null
+++ b/shortGPT/gpt/gpt_chat_video.py
@@ -0,0 +1,26 @@
+from shortGPT.gpt import gpt_utils
+import json
+def generateScript(script_description, language):
+ out = {'script': ''}
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/chat_video_script.yaml')
+ chat = chat.replace("<>", script_description).replace("<>", language)
+ while not ('script' in out and out['script']):
+ try:
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1)
+ out = json.loads(result)
+ except Exception as e:
+ print(e, "Difficulty parsing the output in gpt_chat_video.generateScript")
+ return out['script']
+
+def correctScript(script, correction):
+ out = {'script': ''}
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/chat_video_edit_script.yaml')
+ chat = chat.replace("<>", script).replace("<>", correction)
+
+ while not ('script' in out and out['script']):
+ try:
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1)
+ out = json.loads(result)
+ except Exception as e:
+ print("Difficulty parsing the output in gpt_chat_video.generateScript")
+ return out['script']
\ No newline at end of file
diff --git a/shortGPT/gpt/gpt_editing.py b/shortGPT/gpt/gpt_editing.py
new file mode 100644
index 0000000000000000000000000000000000000000..492e659863a470f22c1b0a765620633bbc565396
--- /dev/null
+++ b/shortGPT/gpt/gpt_editing.py
@@ -0,0 +1,40 @@
+from shortGPT.gpt import gpt_utils
+import json
+def getImageQueryPairs(captions,n=15 ,maxTime=2):
+ chat, _ = gpt_utils.load_local_yaml_prompt('prompt_templates/editing_generate_images.yaml')
+ prompt = chat.replace('<>', f"{captions}").replace("<>", f"{n}")
+ res = gpt_utils.gpt3Turbo_completion(chat_prompt=prompt)
+ imagesCouples = ('{'+res).replace('{','').replace('}','').replace('\n', '').split(',')
+ pairs = []
+ t0 = 0
+ end_audio = captions[-1][0][1]
+ for a in imagesCouples:
+ try:
+ query = a[a.find("'")+1:a.rfind("'")]
+ time = float(a.split(":")[0].replace(' ',''))
+ if (time > t0 and time< end_audio):
+ pairs.append((time, query+" image"))
+ t0 = time
+ except:
+ print('problem extracting image queries from ', a)
+ for i in range(len(pairs)):
+ if(i!= len(pairs)-1):
+ end = pairs[i][0]+ maxTime if (pairs[i+1][0] - pairs[i][0]) > maxTime else pairs[i+1][0]
+ else:
+ end = pairs[i][0]+ maxTime if (end_audio - pairs[i][0]) > maxTime else end_audio
+ pairs[i] = ((pairs[i][0], end), pairs[i][1])
+ return pairs
+
+
+def getVideoSearchQueriesTimed(captions_timed):
+ end = captions_timed[-1][0][1]
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/editing_generate_videos.yaml')
+ chat = chat.replace("<>", f"{captions_timed}")
+ out = [[[0,0],""]]
+ while out[-1][0][1] != end:
+ try:
+ out = json.loads(gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1).replace("'", '"'))
+ except Exception as e:
+ print(e)
+ print("not the right format")
+ return out
\ No newline at end of file
diff --git a/shortGPT/gpt/gpt_translate.py b/shortGPT/gpt/gpt_translate.py
new file mode 100644
index 0000000000000000000000000000000000000000..8c6406e6b0644f6b89b307f5fb72dd9d56fcd0fa
--- /dev/null
+++ b/shortGPT/gpt/gpt_translate.py
@@ -0,0 +1,10 @@
+from shortGPT.gpt import gpt_utils
+
+def translateContent(content, language):
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/translate_content.yaml')
+ if language == "arabic":
+ language =="arabic, and make the translated text two third of the length of the original."
+ system = system.replace("<>", language)
+ chat = chat.replace("<>", content)
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1)
+ return result
\ No newline at end of file
diff --git a/shortGPT/gpt/gpt_utils.py b/shortGPT/gpt/gpt_utils.py
new file mode 100644
index 0000000000000000000000000000000000000000..e5ffa0896001c6c2680c9bb3c93145ed937b4b4a
--- /dev/null
+++ b/shortGPT/gpt/gpt_utils.py
@@ -0,0 +1,104 @@
+import json
+import os
+import re
+from time import sleep, time
+
+import openai
+import tiktoken
+import yaml
+
+from shortGPT.config.api_db import ApiKeyManager
+
+
+def num_tokens_from_messages(texts, model="gpt-3.5-turbo-0301"):
+ """Returns the number of tokens used by a list of messages."""
+ try:
+ encoding = tiktoken.encoding_for_model(model)
+ except KeyError:
+ encoding = tiktoken.get_encoding("cl100k_base")
+ if model == "gpt-3.5-turbo-0301": # note: future models may deviate from this
+ if isinstance(texts, str):
+ texts = [texts]
+ score = 0
+ for text in texts:
+ score += 4 + len(encoding.encode(text))
+ return score
+ else:
+ raise NotImplementedError(f"""num_tokens_from_messages() is not presently implemented for model {model}.
+ See https://github.com/openai/openai-python/blob/main/chatml.md for information""")
+
+
+def extract_biggest_json(string):
+ json_regex = r"\{(?:[^{}]|(?R))*\}"
+ json_objects = re.findall(json_regex, string)
+ if json_objects:
+ return max(json_objects, key=len)
+ return None
+
+
+def get_first_number(string):
+ pattern = r'\b(0|[1-9]|10)\b'
+ match = re.search(pattern, string)
+ if match:
+ return int(match.group())
+ else:
+ return None
+
+
+def load_yaml_file(file_path: str) -> dict:
+ """Reads and returns the contents of a YAML file as dictionary"""
+ return yaml.safe_load(open_file(file_path))
+
+
+def load_json_file(file_path):
+ with open(file_path, 'r', encoding='utf-8') as f:
+ json_data = json.load(f)
+ return json_data
+
+from pathlib import Path
+
+def load_local_yaml_prompt(file_path):
+ _here = Path(__file__).parent
+ _absolute_path = (_here / '..' / file_path).resolve()
+ json_template = load_yaml_file(str(_absolute_path))
+ return json_template['chat_prompt'], json_template['system_prompt']
+
+
+def open_file(filepath):
+ with open(filepath, 'r', encoding='utf-8') as infile:
+ return infile.read()
+
+
+def gpt3Turbo_completion(chat_prompt="", system="You are an AI that can give the answer to anything", temp=0.7, model="gpt-3.5-turbo", max_tokens=1000, remove_nl=True, conversation=None):
+ openai.api_key = ApiKeyManager.get_api_key("OPENAI")
+ max_retry = 5
+ retry = 0
+ while True:
+ try:
+ if conversation:
+ messages = conversation
+ else:
+ messages = [
+ {"role": "system", "content": system},
+ {"role": "user", "content": chat_prompt}
+ ]
+ response = openai.ChatCompletion.create(
+ model=model,
+ messages=messages,
+ max_tokens=max_tokens,
+ temperature=temp)
+ text = response['choices'][0]['message']['content'].strip()
+ if remove_nl:
+ text = re.sub('\s+', ' ', text)
+ filename = '%s_gpt3.txt' % time()
+ if not os.path.exists('.logs/gpt_logs'):
+ os.makedirs('.logs/gpt_logs')
+ with open('.logs/gpt_logs/%s' % filename, 'w', encoding='utf-8') as outfile:
+ outfile.write(f"System prompt: ===\n{system}\n===\n"+f"Chat prompt: ===\n{chat_prompt}\n===\n" + f'RESPONSE:\n====\n{text}\n===\n')
+ return text
+ except Exception as oops:
+ retry += 1
+ if retry >= max_retry:
+ raise Exception("GPT3 error: %s" % oops)
+ print('Error communicating with OpenAI:', oops)
+ sleep(1)
diff --git a/shortGPT/gpt/gpt_voice.py b/shortGPT/gpt/gpt_voice.py
new file mode 100644
index 0000000000000000000000000000000000000000..49a5c30788922f55c19cc5518c46d9762d816af1
--- /dev/null
+++ b/shortGPT/gpt/gpt_voice.py
@@ -0,0 +1,9 @@
+
+from shortGPT.gpt import gpt_utils
+def getGenderFromText(text):
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/voice_identify_gender.yaml')
+ chat = chat.replace("<>", text)
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system).replace("\n", "").lower()
+ if 'female' in result:
+ return 'female'
+ return 'male'
\ No newline at end of file
diff --git a/shortGPT/gpt/gpt_yt.py b/shortGPT/gpt/gpt_yt.py
new file mode 100644
index 0000000000000000000000000000000000000000..346efd2034f22fea863cdb95b42b755a8786e207
--- /dev/null
+++ b/shortGPT/gpt/gpt_yt.py
@@ -0,0 +1,20 @@
+from shortGPT.gpt import gpt_utils
+import json
+
+def generate_title_description_dict(content):
+ out = {"title": "", "description":""}
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/yt_title_description.yaml')
+ chat = chat.replace("<>", f"{content}")
+
+ while out["title"] == "" or out["description"] == "":
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1)
+ try:
+ response = json.loads(result)
+ if "title" in response:
+ out["title"] = response["title"]
+ if "description" in response:
+ out["description"] = response["description"]
+ except Exception as e:
+ pass
+
+ return out['title'], out['description']
diff --git a/shortGPT/gpt/reddit_gpt.py b/shortGPT/gpt/reddit_gpt.py
new file mode 100644
index 0000000000000000000000000000000000000000..8c917880054d2e239c05fe1e6982b63abf8bc9e0
--- /dev/null
+++ b/shortGPT/gpt/reddit_gpt.py
@@ -0,0 +1,52 @@
+from shortGPT.gpt import gpt_utils
+import random
+import json
+def generateRedditPostMetadata(title):
+ name = generateUsername()
+ if title and title[0] == '"':
+ title = title.replace('"', '')
+ n_months = random.randint(1,11)
+ header = f"{name} - {n_months} months ago"
+ n_comments = random.random() * 10 + 2
+ n_upvotes = n_comments*(1.2+ random.random()*2.5)
+ return title, header, f"{n_comments:.1f}k", f"{n_upvotes:.1f}k"
+
+
+def getInterestingRedditQuestion():
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/reddit_generate_question.yaml')
+ return gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1.08)
+
+def createRedditScript(question):
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/reddit_generate_script.yaml')
+ chat = chat.replace("<>", question)
+ result = "Reddit, " + question +" "+gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1.08)
+ return result
+
+
+def getRealisticness(text):
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/reddit_filter_realistic.yaml')
+ chat = chat.replace("<>", text)
+ while True:
+ try:
+ result = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1)
+ return json.loads(result)['score']
+ except Exception as e:
+ print("Error in getRealisticness", e.args[0])
+
+
+def getQuestionFromThread(text):
+ if ((text.find("Reddit, ") < 15) and (10 < text.find("?") < 100)):
+ question = text.split("?")[0].replace("Reddit, ", "").strip().capitalize()
+ else:
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/reddit_filter_realistic.yaml')
+ chat = chat.replace("<>", text)
+ question = gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system).replace("\n", "")
+ question = question.replace('"', '').replace("?", "")
+ return question
+
+
+def generateUsername():
+ chat, system = gpt_utils.load_local_yaml_prompt('prompt_templates/reddit_username.yaml')
+ return gpt_utils.gpt3Turbo_completion(chat_prompt=chat, system=system, temp=1.2).replace("u/", "")
+
+
diff --git a/shortGPT/prompt_templates/__init__.py b/shortGPT/prompt_templates/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/shortGPT/prompt_templates/chat_video_edit_script.yaml b/shortGPT/prompt_templates/chat_video_edit_script.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..304dae60b7dc293b5eb7fcbb94bfd198ea704f14
--- /dev/null
+++ b/shortGPT/prompt_templates/chat_video_edit_script.yaml
@@ -0,0 +1,15 @@
+system_prompt: |
+ You are an expert video script writer / editor. You ONLY write text that is read. You only write the script that will be read by a voice actor for a video. The user will give you a script they have already written and the corrections they want you to make. From that, you will edit the script. Make sure to directly edit the script in response to the corrections given.
+ Your edited script will not have any reference to the audio footage / video footage shown. Only the text that will be narrated by the voice actor.
+ You will edit purely text.
+ Don't write any other textual thing than the text itself.
+ Make sure the text is not longer than 200 words (keep the video pretty short and neat).
+ # Output
+ You will output the edited script in a JSON format of this kind, and only a parsable JSON object
+ {"script": "did you know that ... ?"}
+
+chat_prompt: |
+ Original script:
+ <>
+ Corrections:
+ <>
\ No newline at end of file
diff --git a/shortGPT/prompt_templates/chat_video_script.yaml b/shortGPT/prompt_templates/chat_video_script.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..5ab4d6c81027a2ee1afdf29589dcfcf6eaf114f7
--- /dev/null
+++ b/shortGPT/prompt_templates/chat_video_script.yaml
@@ -0,0 +1,14 @@
+system_prompt: |
+ You are an expert video writer. You ONLY produce text that is read. You only produce the script. that will be read by a voice actor for a video. The user will give you the description of the video they want you to make and from that, you will write the script. Make sure to directly write the script in response to the video description.
+ Your script will not have any reference to the audio footage / video footage shown. Only the text that will be narrated by the voice actor.
+ You will produce purely text.
+ Don't write any other textual thing than the text itself.
+ Make sure the text is not longer than 200 words (keep the video pretty short and neat).
+ # Output
+ You will output the script in a JSON format of this kind, and only a parsable JSON object
+ {"script": "did you know that ... ?"}
+
+chat_prompt: |
+ Language: <>
+ Video description:
+ <>
diff --git a/shortGPT/prompt_templates/editing_generate_images.yaml b/shortGPT/prompt_templates/editing_generate_images.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..2691c3e550315da574a2b858067f574ed9d16dab
--- /dev/null
+++ b/shortGPT/prompt_templates/editing_generate_images.yaml
@@ -0,0 +1,22 @@
+system_prompt: |
+
+chat_prompt: |
+ You are a shorts video editor. Your audience is people from 18 yo to 40yo. Your style of editing is pretty simple, you take the transcript of your short and put a very simple google image to illustrate the narrated sentances.
+
+ Each google image is searched with a short query of two words maximum. So let's say someone is talking about being sad, you would query on google `sad person frowning` and show that image around that sentence.
+
+ I will give you a transcript which contains which words are shown at the screen, and the timestamps where they are shown. Understand the transcript, and time images at timestamps and, write me the query for each image. For the image queries you have two choices: concrete objects, like 'cash', 'old table', and other objects, or people in situations like 'sad person', 'happy family', ect... Generate a maximum of <> image queries equally distributed in the video.
+
+ Avoid depicting shocking or nude / crude images, since your video will get demonetized. The queries should bring images that represent objects and persons that are useful to understand the emotions and what is happening in the transcript. The queries should describe OBJECTS or PERSONS. So for something romantic, maybe a couple hugging, or a heart-shaped balloon. For the image queries you have two choices: concrete objects, like 'cash', 'old table', and other objects, or people in situations like 'sad person', 'happy family', ect..
+
+ The images should be an image representation of what is happening. Use places and real life people as image queries if you find any in the transcript. Avoid using overly generic queries like 'smiling man' that can bring up horror movie pictures, use the word 'person instead'. Instead, try to use more specific words that describe the action or emotion in the scene. Also, try to avoid queries that don't represent anything in images, such as abstract concepts, ideas, or feelings. MAKE SURE THAT THE QUERIES ARE VERY DESCRIPTIVE AND VISUAL AND CAN BE DRAWN AND NEVER USE WORDS THAT ONLY DESCRIBE AN ABSTRACT IDEA. NEVER USE ABSTRACT NOUNS IN THE QUERIES. ALWAYS USE REAL OBJECTS OR PERSONS IN THE QUERIES.
+
+ Transcript:
+
+ <>
+
+
+ Every few transcript captions, find an image that can be shown. Really understand the context and emotions for the image to be good ! The queries should describe OBJECTS or PERSONS. Write it in a dictionary with timestamp to query format like { 1.0: 'happy person', 3.2: 'sad person', ...} . DON'T GENERATE A QUERY FOR EACH CAPTION. Generate <> image queries and time them accordingly in the video. NEVER use the same search query for multiple captions. Make sure that the timestamps make sense.
+ NEVER USE ABSTRACT NOUNS IN THE QUERIES. ALWAYS USE REAL OBJECTS OR PERSONS IN THE QUERIES.
+ For the image queries you have two choices: concrete objects, like 'cash', 'old table', 'red car', 'broken pen' and other objects, or people in situations like 'sad person', 'happy family', ect.. Choose more objects than people.
+ The <> generated image queries and their timestamps, make sure to respect the number <>:
diff --git a/shortGPT/prompt_templates/editing_generate_videos.yaml b/shortGPT/prompt_templates/editing_generate_videos.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..6f27297dcdcb66726bb55113c24747aa2537ecd7
--- /dev/null
+++ b/shortGPT/prompt_templates/editing_generate_videos.yaml
@@ -0,0 +1,32 @@
+system_prompt: |
+ # Instructions
+
+ You're a video research expert. The user will give you the timed captions of a video they will make, and you will give back a list of couples of text search queries that will be used to search for background video footage, and the time t1 and t2 when it will be shown in the video.
+ # Output format
+ The format will be JSON parasable and look like this:
+ [[[0.0, 4.4], ["Dog barking", "Dog angry", Canine angry"]], [[4.4, 7.8], "bone", "pet food", "food", "canine"], ect...
+
+ # Time periods t1 and t2
+ Time periods t1 and t2 must always be consecutive, and last between 4 to 5 seconds, and must cover the whole video.
+ For example, [0, 2.5] <= IS BAD, because 2.5-0 = 2.5 < 3
+ [0, 11] <= IS BAD, because 11sec > 5 sec
+ [0, 4.2] <= IS GOOD
+
+ # Query search string list
+ YOU ALWAYS USE ENGLISH IN YOUR TEXT QUERIES
+ As you have seen above, for each time period you will be tasked to generate 3 strings that will be searched on the video search engine, to find the appropriate clip to find.
+ Each string has to be between ONE to TWO words.
+ Each search string must DEPICT something visual.
+ The depictions have to be extremely visually concrete, like `coffee beans`, or `dog running`.
+ 'confused feelings' <= BAD, because it doesn't depict something visually
+ 'heartbroken man' <= GOOD, because it depicts something visual.
+ 'man feeling very lonely' <= BAD, because it contains 4 words.
+ The list must always contain 3 query searches.
+ ['Sad person'] <= BAD, because it's one string
+ ['Sad person', 'depressed man', 'depressed person'] <= GOOD, because it's 3 strings
+ ['Une Pomme', 'un enfant qui rit', 'une personne heureuse'] <= BAD, because the text query is NOT in english
+
+chat_prompt: |
+ Timed captions:
+ <>
+ Video search queries:
diff --git a/shortGPT/prompt_templates/facts_generator.yaml b/shortGPT/prompt_templates/facts_generator.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..c5bf8f1e55d98700bb9dc1bb1640e327787eeb4a
--- /dev/null
+++ b/shortGPT/prompt_templates/facts_generator.yaml
@@ -0,0 +1,35 @@
+system_prompt: >
+ You are an expert content writer of a YouTube shorts channel. You specialize in `facts` shorts.
+ Your facts shorts are less than 50 seconds verbally ( around 140 words maximum). They are extremely captivating, and original.
+ The user will ask you a type of facts short and you will produce it.
+ For examples, when the user Asks :
+ `Weird facts`
+ You produce the following content script:
+
+ ---
+ Weird facts you don't know.
+ A swarm of 20,000 bees followed a car for two days because their queen was stuck inside.
+ Rockados cannot stick their tongue out because it's attached to the roof of their mouths.
+
+ If you tickle a rat day after day, it will start laughing whenever it sees you.
+
+ In 2013, police and the Maldives arrested a coconut for lordering near a polling station for the presidential election.
+ Locals fear the coconut may have been ingrained with a black magic spell to influence the election.
+
+ A Chinese farmer who always wanted to own his own plane built a full scale,
+ non-working replica of an airbus A320 out of 50 tons of steel. It took him and his friends over two years and costed over $400,000.
+
+ When invited by a lady to spend a night with her, Benjamin Franklin asked to postpone until winter when nights were longer.
+ ---
+
+ You are now tasked to produce the greatest short script depending on the user's request type of 'facts'.
+ Only give the first `hook`, like "Weird facts you don't know. " in the example. Then the facts.
+ Keep it short, extremely interesting and original.
+
+chat_prompt: >
+ <>
+
+
+
+
+
diff --git a/shortGPT/prompt_templates/facts_subjects_generation.yaml b/shortGPT/prompt_templates/facts_subjects_generation.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..499ee157a815aead995daa264a3354e0849e86a8
--- /dev/null
+++ b/shortGPT/prompt_templates/facts_subjects_generation.yaml
@@ -0,0 +1,7 @@
+system_prompt: >
+
+chat_prompt: >
+ For a series of <> youtube video about top 10 facts on a certain subject,
+ pick a random subject. Be very original. Put it in the '`Subject` facts' format.
+ Give the output in an array format that's json parseable., like ['Police facts', 'prison facts'].
+ Only give the array and nothing else.
diff --git a/shortGPT/prompt_templates/reddit_extract_question.yaml b/shortGPT/prompt_templates/reddit_extract_question.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..fe26440f9b6252b8ee657c93994437dcab5f4cf8
--- /dev/null
+++ b/shortGPT/prompt_templates/reddit_extract_question.yaml
@@ -0,0 +1,24 @@
+system_prompt: |
+ From the transcript of a reddit ask, tell me the question in the title. The transcript always answers the question that a redditor asks in the title of the thread.
+ The question in the title must be a very shorts open-ended question that requires opinion/anecdotal-based answers. Examples of questions are:
+ ---
+ Whatโs the worst part of having a child?
+ What screams โthis person peaked in high schoolโ to you?
+ What was your โit canโt be that easy / it was that easyโ moment in your life?
+ ---
+ Rules:
+ Most important rule : The question MUST be directed at the person reading it, the subject of the question should ALWAYS be the reader. It must contain 'you' or 'your', or something asking THEM their experience.
+ * The question is always very general, and then, people answer it with a specific anecdote that is related to that question. The question is always short and can bring spicy answers. By taking inspiration from the questions above, try to find the reddit thread question where we get the following anecdote.
+ * The question NEVER contains "I" as it is NOT answered by the person asking it.
+ * The question is NEVER specific too specific about a certain situation.
+ * The question should be as short and consise as possible. NEVER be too wordy, it must be fast and concise, and it doesn't matter if it's too general.
+ * The question must sound good to the ear, and bring interest. It should sound natural.
+ * The question must use the vocabulary of reddit users. Young, not too complicated, and very straight to the point.
+ * The question must be relatable for anyone, girl or guy.
+ The question should ALWAYS START with "What"
+chat_prompt: |
+ -Transcript:
+ <>
+ The question should ALWAYS START with "What"
+ -Most probable very short and conssise open-ended question from the transcript (50 characters MAXIMUM):
+
\ No newline at end of file
diff --git a/shortGPT/prompt_templates/reddit_filter_realistic.yaml b/shortGPT/prompt_templates/reddit_filter_realistic.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..7d4c4b0f76ef7c02722676459d19387864c5663c
--- /dev/null
+++ b/shortGPT/prompt_templates/reddit_filter_realistic.yaml
@@ -0,0 +1,13 @@
+system_prompt: |
+ You are the judge of the story. Your goal will be to judge if it can possibly happen.
+ If it's possible and the story makes sense, then it's a 10, and if it's something that wouldn't ever happen in real life or something that doesn't make sense at all, it's a 0.
+ You have to be tolerant and keep in mind that the stories are sometimes very unlikely, but really happened, so you will only give a low score when something doesn't make sense in the story.
+
+ For parsing purposes, you will ALWAYS the output as a JSON OBJECT with the key `score` and the value being the number between 1 to 10 and.
+ The output should look like:
+ {score: 1.3}
+
+chat_prompt: |
+ Story:
+ <>
+ Output:
\ No newline at end of file
diff --git a/shortGPT/prompt_templates/reddit_generate_question.yaml b/shortGPT/prompt_templates/reddit_generate_question.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..d46266d2e956810ccaa28241f09710756ed4aac4
--- /dev/null
+++ b/shortGPT/prompt_templates/reddit_generate_question.yaml
@@ -0,0 +1,25 @@
+system_prompt: |
+ You will write an interesting reddit ask thread question.
+
+ Instructions for the question:
+ The question in the must be a very shorts open-ended question that requires opinion/anecdotal-based answers. Examples of questions are:
+ ---
+ Whatโs the worst part of having a child?
+ What screams โthis person peaked in high schoolโ to you?
+ What was your โit canโt be that easy / it was that easyโ moment in your life?
+ Have you ever had a bad date turning into a good one?
+ ---
+ Most important rule for questions : The question MUST be directed at the person reading it, the subject of the question should ALWAYS be the reader. It must contain 'you' or 'your', or something asking THEM their experience.
+ * The question is always very general, and then, people answer it with a specific anecdote that is related to that question. The question is always short and can bring spicy answers.
+ * The question NEVER contains 'I' as it is NOT answered by the person asking it.
+ * The question is NEVER too specific about a certain situation.
+ * The question should be as short and consise as possible. NEVER be too wordy, it must be fast and concise.
+ * The question must sound good to the ear, and bring interest. It should sound natural.
+ * The question must use the vocabulary of reddit users. Young, not too complicated, and very straight to the point.
+ The question must spark curiosity and interest, and must create very entertaining answers
+ * The question must be relatable for anyone, girl or guy.
+ * The question is maximum 80 characters long
+
+chat_prompt: |
+ Totally new question:
+
\ No newline at end of file
diff --git a/shortGPT/prompt_templates/reddit_generate_script.yaml b/shortGPT/prompt_templates/reddit_generate_script.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..890b5de8af16f03d503ab0ec5918a942ae093561
--- /dev/null
+++ b/shortGPT/prompt_templates/reddit_generate_script.yaml
@@ -0,0 +1,18 @@
+system_prompt: |
+ Instructions for the new story:
+ You are a YouTube shorts content creator who makes extremely good YouTube shorts over answers from AskReddit questions. I'm going to give you a question, and you will give an anecdote as if you are a redditor than answered that question (narrated with 'I' in the first person). The anecdote you will create will be used in a YouTube short that will get 1 million views.
+ 1- The story must be between 120 and 140 words MAXIMUM.
+ 2- DO NOT end the story with a moral conclusion or any sort of conclusion that elongates the personal story. Just stop it when it makes sense.
+ 3- Make sure that the story is very SPICY, very unusual, HIGHLY entertaining to listen to, not boring, and not a classic story that everyone tells.
+ 4- Make sure that the new short's content is totally captivating and will bang with the YouTube algorithm.
+ 5- Make sure that the story directly answers the title.
+ 6- Make the question sound like an r/AskReddit question: open-ended and very interesting, very short and not too specific.
+ 7- The language used in the story must be familiar, casual that a normal person telling an story would use. Even youthful.
+ 8- The story must be narrated as if you're a friend of the viewer telling them about the story.
+ 9- Start the the story with 'I'
+
+chat_prompt: |
+ Reddit question: <>
+
+ -New Generated story. The story has to be highly unusual and spicy and must really surprise its listeners and hook them up to the story. Don't forget to make it between 120 and 140 words:
+ Reddit, <>
\ No newline at end of file
diff --git a/shortGPT/prompt_templates/reddit_story_filter.yaml b/shortGPT/prompt_templates/reddit_story_filter.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..4f8a48e7a34464a438f5fabd0d01ea78ce4f8635
--- /dev/null
+++ b/shortGPT/prompt_templates/reddit_story_filter.yaml
@@ -0,0 +1,26 @@
+system_prompt: >
+ You're a judge of the realisticness of a story for a youtube short.
+ You must put yourself in the shoes of the youtube viewer hearing this story
+ and determine if it's totally nonsense.
+ Your goal will be to judge if it can possibly happen.
+ If it's possible and the story makes sense, then it's a 10,
+ and if it's something that wouldn't ever happen in real life or
+ something that doesn't make sense at all, it's a 0.
+
+ You have to be tolerant and keep in mind that the stories are meant to be unusual, they are sometimes very unlikely,
+ but really happened, so you will only give a low score when something doesn't make sense in the story.
+ For parsing purposes, you will ALWAYS the output as a JSON OBJECT with the key
+ 'score' and the value being the number between 1 to 10 and the key 'explanation'
+ with one sentence to explain why it's not. Make this explanation maximum 4 words.
+ The output should look like:
+ {score: number, explanation: "some words..."}
+
+ Give perfect json with keys score and explanation, and nothing else.
+
+chat_prompt: >
+ Story:
+
+ <>
+
+ Output:
+
diff --git a/shortGPT/prompt_templates/reddit_username.yaml b/shortGPT/prompt_templates/reddit_username.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..b7da0f0add87f3d4104de649104a009817a03608
--- /dev/null
+++ b/shortGPT/prompt_templates/reddit_username.yaml
@@ -0,0 +1,6 @@
+system_prompt: >
+
+chat_prompt: >
+ Generate a random Reddit name with one or two numbers inside the name. Only generate one name, and don't output anything else. Make it sound natural. The name must be between 7 and 10 characters:
+ u/
+
diff --git a/shortGPT/prompt_templates/translate_content.yaml b/shortGPT/prompt_templates/translate_content.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..bc6832185d3a8204da9663a72dab009ee6cf85a4
--- /dev/null
+++ b/shortGPT/prompt_templates/translate_content.yaml
@@ -0,0 +1,26 @@
+system_prompt: >
+ You're an expert content translator to <>.
+ You always translate sentences very properly, and you write down numbers in WORDS, you never write digits in your text.
+
+ IMPORTANT INSTRUCTION:
+ ***You write down numbers in words
+ For example:
+ Input: "There are 7 days in a week."
+ Translation: "Existem sete dias em uma semana."
+
+ Example 2:
+ Input: "She bought 4 apples at the market."
+ Translation: "Existem sete dias em uma semana."
+
+ Example 3:
+ Input:"The temperature is -2 degrees Celsius."
+ Translation: "A temperatura estรก dois graus Celsius negativos."
+
+
+ Example 4:
+ Input: "He is 30 years old."
+ Translation: "Ele tem trinta anos de idade."
+ **
+
+chat_prompt: >
+ <>
\ No newline at end of file
diff --git a/shortGPT/prompt_templates/voice_identify_gender.yaml b/shortGPT/prompt_templates/voice_identify_gender.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..8ecf5ea315c86eb4c09aedfe4179faf84f9ac14d
--- /dev/null
+++ b/shortGPT/prompt_templates/voice_identify_gender.yaml
@@ -0,0 +1,13 @@
+system_prompt: |
+ I will give you a narrated transcript and you must identify if it's most probably a male or female.
+ If you think the narrator is more probable to be a male, answer "male" and if you think it's female, say "female".
+ If you don't know, just say male.
+
+
+chat_prompt: |
+ Transcript:
+
+ <>
+
+ Gender of narrator:
+
diff --git a/shortGPT/prompt_templates/yt_title_description.yaml b/shortGPT/prompt_templates/yt_title_description.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..eec5e0e83b4c4623a2d2e2266e48eae238f23a57
--- /dev/null
+++ b/shortGPT/prompt_templates/yt_title_description.yaml
@@ -0,0 +1,11 @@
+system_prompt: >
+ You are a youtube shorts title and description expert writer.
+ The user will give you the transcript of a youtube short, and you will create a title, and a description. In function of the audience, demography of viewers, you will adapt the title to be catchy.
+ Use only MAXIMUM 2 emojis in the title of the video ( very depending on the context, be careful)
+ and use hashtags in the description
+ The title has to be less than 80 characters (one small sentance of 10 words max)
+ And the description maximum 240 characters (keep it small)
+ You will give the title and description in a perfect json format. You will give nothing else but the perfect json object with key `title` and `description`
+ In your JSON, use the double quotes "" instead of ''
+chat_prompt: >
+ <>
diff --git a/shortGPT/tracking/README.md b/shortGPT/tracking/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..25bec3e9afb594ec70c5ed9e8380986d2aba9cb1
--- /dev/null
+++ b/shortGPT/tracking/README.md
@@ -0,0 +1,56 @@
+# Module: Tracking
+
+## Goal
+The `tracking` module is responsible for tracking and analyzing the usage and cost of various APIs used in the project. It includes two files: `api_tracking.py` and `cost_analytics.py`.
+
+## File: api_tracking.py
+
+### Class: APITracker
+This class is responsible for tracking the usage of APIs and saving the data to a content manager.
+
+#### Method: `__init__()`
+- Initializes the APITracker object.
+- Calls the `initiateAPITracking()` method.
+
+#### Method: `setDataManager(contentManager: ContentDataManager)`
+- Sets the content manager for storing the API usage data.
+- Raises an exception if the content manager is null.
+
+#### Method: `openAIWrapper(gptFunc)`
+- Wrapper function for OpenAI API calls.
+- Saves the API usage data to the content manager.
+- Returns the result of the API call.
+
+#### Method: `elevenWrapper(audioFunc)`
+- Wrapper function for Eleven API calls.
+- Saves the API usage data to the content manager.
+- Returns the result of the API call.
+
+#### Method: `wrap_turbo()`
+- Wraps the `gpt3Turbo_completion` function from the `gpt_utils` module using the `openAIWrapper` method.
+- Replaces the original function with the wrapped function.
+
+#### Method: `wrap_eleven()`
+- Wraps the `generateVoice` function from the `audio_generation` module using the `elevenWrapper` method.
+- Replaces the original function with the wrapped function.
+
+#### Method: `initiateAPITracking()`
+- Initiates the tracking of APIs by wrapping the necessary functions using the `wrap_turbo` and `wrap_eleven` methods.
+
+
+## File: cost_analytics.py
+
+### Function: calculateCostAnalytics()
+This function calculates the average usage and cost of OpenAI and Eleven APIs based on the data stored in the content database.
+
+- Initializes the content database.
+- Retrieves the API usage data from the database.
+- Calculates the average usage and cost for OpenAI and Eleven APIs.
+- Prints the results.
+
+### Usage example:
+```python
+calculateCostAnalytics()
+```
+
+Note: The commented code at the end of the file is unrelated and can be ignored.
\ No newline at end of file
diff --git a/shortGPT/tracking/__init__.py b/shortGPT/tracking/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..47fca8ef18752bce148c7ce6f1656c733063f79b
--- /dev/null
+++ b/shortGPT/tracking/__init__.py
@@ -0,0 +1 @@
+from . import api_tracking
\ No newline at end of file
diff --git a/shortGPT/tracking/api_tracking.py b/shortGPT/tracking/api_tracking.py
new file mode 100644
index 0000000000000000000000000000000000000000..bda95f625816baf68cf164fb5ee5e7b27957f1db
--- /dev/null
+++ b/shortGPT/tracking/api_tracking.py
@@ -0,0 +1,60 @@
+from shortGPT.gpt import gpt_utils
+from shortGPT.database.content_data_manager import ContentDataManager
+import json
+
+class APITracker:
+
+ def __init__(self):
+ self.initiateAPITracking()
+
+ def setDataManager(self, contentManager : ContentDataManager):
+ if(not contentManager):
+ raise Exception("contentManager is null")
+ self.datastore = contentManager
+
+ def openAIWrapper(self, gptFunc):
+
+ def wrapper(*args, **kwargs):
+ result = gptFunc(*args, **kwargs)
+ prompt = kwargs.get('prompt') or kwargs.get('conversation') or args[0]
+ prompt = json.dumps(prompt)
+ if self.datastore and result:
+ tokensUsed = gpt_utils.num_tokens_from_messages([prompt, result])
+ self.datastore.save('api_openai', tokensUsed, add=True)
+ return result
+
+ return wrapper
+
+ def elevenWrapper(self, audioFunc):
+
+ def wrapper(*args, **kwargs):
+ result = audioFunc(*args, **kwargs)
+ textInput = kwargs.get('text') or args[0]
+ if self.datastore and result:
+ self.datastore.save('api_eleven', len(textInput), add=True)
+ return result
+
+ return wrapper
+
+
+ def wrap_turbo(self):
+ func_name = "gpt3Turbo_completion"
+ module = __import__("gpt_utils", fromlist=["gpt3Turbo_completion"])
+ func = getattr(module, func_name)
+ wrapped_func = self.openAIWrapper(func)
+ setattr(module, func_name, wrapped_func)
+
+ def wrap_eleven(self):
+ func_name = "generateVoice"
+ module = __import__("audio_generation", fromlist=["generateVoice"])
+ func = getattr(module, func_name)
+ wrapped_func = self.elevenWrapper(func)
+ setattr(module, func_name, wrapped_func)
+
+
+ def initiateAPITracking(self):
+ self.wrap_turbo()
+ self.wrap_eleven()
+
+
+
diff --git a/shortGPT/tracking/cost_analytics.py b/shortGPT/tracking/cost_analytics.py
new file mode 100644
index 0000000000000000000000000000000000000000..c7f708a5605fe00327575536aabd6ebfa8ef6d51
--- /dev/null
+++ b/shortGPT/tracking/cost_analytics.py
@@ -0,0 +1,48 @@
+import numpy as np
+from shortGPT.database.content_database import ContentDatabase
+db = ContentDatabase()
+all = []
+# Calculate average and price of the average for OpenAI
+openai_array = [short.get('api_openai') for short in all]
+avr_openai = np.mean(openai_array)
+OPENAI_CONST = 0.002 / 1000
+price_openai = avr_openai * OPENAI_CONST
+max_openai = max(openai_array)
+price_max_openai = max_openai * OPENAI_CONST
+
+# Calculate average and price of the average for Eleven
+eleven_array = [short.get('api_openai') for short in all]
+avr_eleven = np.mean(eleven_array)
+ELEVEN_CONST = 0.3 / 1000
+price_eleven = avr_eleven * ELEVEN_CONST
+max_eleven = max(eleven_array)
+price_max_eleven = max_eleven * ELEVEN_CONST
+
+
+
+# Print results
+print("OpenAI:")
+print("- Average:", avr_openai)
+print("- Price of the average:", price_openai)
+print("- Max:", max_openai)
+print("- Price of the max:", price_max_openai)
+
+print("Eleven:")
+print("- Average:", avr_eleven)
+print("- Price of the average:", price_eleven)
+print("- Max:", max_eleven)
+print("- Price of the max:", price_max_eleven)
+
+
+
+# for id in ids:
+# builder = AskingRedditorShortBuilder(AR, id)
+# print(id, builder.dataManager.getVideoPath())
+#createShorts(30, 'AskingRedditors')
+# AR = ChannelManager("AskingRedditors")
+# newShort = AskingRedditorShortBuilder(channelDB= AR, short_id="FyhKkqx9xDxTEtRpanSD")
+# print(newShort.channelDB.getStaticEditingAsset('background_onepiece'))
+# print(newShort.channelDB.getStaticEditingAsset('reddit_template_dark'))
+# print(newShort.channelDB.getStaticEditingAsset('subscribe_animation'))
+#print("Scraping requests remaining: ",image_api.getScrapingCredits())
+
diff --git a/shortGPT/utils/cli.py b/shortGPT/utils/cli.py
new file mode 100644
index 0000000000000000000000000000000000000000..2938841a82e04f252d7d51d08f68b1f3e60114e0
--- /dev/null
+++ b/shortGPT/utils/cli.py
@@ -0,0 +1,140 @@
+from shortGPT.utils.requirements import Requirements
+
+
+class CLI:
+
+ @staticmethod
+ def display_header():
+ '''Display the header of the CLI'''
+ CLI.display_green_text('''
+.d88888b dP dP .88888. 888888ba d888888P .88888. 888888ba d888888P
+88. "' 88 88 d8' `8b 88 `8b 88 d8' `88 88 `8b 88
+`Y88888b. 88aaaaa88 88 88 88aaaa8P' 88 88 88aaaa8P' 88
+ `8b 88 88 88 88 88 `8b. 88 88 YP88 88 88
+d8' .8P 88 88 Y8. .8P 88 88 88 Y8. .88 88 88
+ Y88888P dP dP `8888P' dP dP dP `88888' dP dP
+
+ ''')
+ CLI.display_green_text("Welcome to ShortGPT! This is an experimental AI framework to automate all aspects of content creation.")
+ print("")
+ CLI.display_requirements_check()
+
+ @staticmethod
+ def display_help():
+ '''Display help'''
+ print("Usage: python shortGPT.py [options]")
+ print("")
+ print("Options:")
+ print(" -h, --help show this help message and exit")
+
+ @staticmethod
+ def display_requirements_check():
+ '''Display information about the system and requirements'''
+ print("Checking requirements...")
+ requirements_manager = Requirements()
+ print(" - Requirements : List of requirements and installed version:")
+ all_req_versions = requirements_manager.get_all_requirements_versions()
+ for req_name, req_version in all_req_versions.items():
+ if req_version is None:
+ CLI.display_red_text(f"---> Error : {req_name} is not installed")
+ print(f"{req_name}=={req_version}")
+
+ print("")
+ # Skipping for now, because it assumes package have the same name as the python import itself, which is not true most sometimes.
+ # if not requirements_manager.is_all_requirements_installed():
+ # CLI.display_red_text("Error : Some requirements are missing")
+ # print("Please install the missing requirements using the following command :")
+ # print("pip install -r requirements.txt")
+ # print("")
+ # requirements_manager.get_all_requirements_not_installed()
+ # print("")
+
+ class bcolors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKCYAN = '\033[96m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+ BOLD = '\033[1m'
+ UNDERLINE = '\033[4m'
+
+ @staticmethod
+ def display_error(error_message, stack_trace):
+ '''Display an error message in the console'''
+ print(CLI.bcolors.FAIL + "ERROR : " + error_message + CLI.bcolors.ENDC)
+ print(stack_trace)
+ print("If the problem persists, don't hesitate to contact our support. We're here to assist you.")
+ print("Get Help on Discord : https://discord.gg/qn2WJaRH")
+
+ @staticmethod
+ def get_console_green_text(text):
+ '''Get the text in green color'''
+ return CLI.bcolors.OKGREEN + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_red_text(text):
+ '''Get the text in red color'''
+ return CLI.bcolors.FAIL + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_yellow_text(text):
+ '''Get the text in yellow color'''
+ return CLI.bcolors.WARNING + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_blue_text(text):
+ return CLI.bcolors.OKBLUE + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_bold_text(text):
+ return CLI.bcolors.BOLD + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_underline_text(text):
+ return CLI.bcolors.UNDERLINE + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_cyan_text(text):
+ return CLI.bcolors.OKCYAN + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_header_text(text):
+ return CLI.bcolors.HEADER + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def get_console_text(text, color):
+ return color + text + CLI.bcolors.ENDC
+
+ @staticmethod
+ def display_blue_text(text):
+ print(CLI.get_console_blue_text(text))
+
+ @staticmethod
+ def display_green_text(text):
+ print(CLI.get_console_green_text(text))
+
+ @staticmethod
+ def display_red_text(text):
+ print(CLI.get_console_red_text(text))
+
+ @staticmethod
+ def display_yellow_text(text):
+ print(CLI.get_console_yellow_text(text))
+
+ @staticmethod
+ def display_bold_text(text):
+ print(CLI.get_console_bold_text(text))
+
+ @staticmethod
+ def display_underline_text(text):
+ print(CLI.get_console_underline_text(text))
+
+ @staticmethod
+ def display_cyan_text(text):
+ print(CLI.get_console_cyan_text(text))
+
+ @staticmethod
+ def display_header_text(text):
+ print(CLI.get_console_header_text(text))
diff --git a/shortGPT/utils/requirements.py b/shortGPT/utils/requirements.py
new file mode 100644
index 0000000000000000000000000000000000000000..034290dd3a54122405ccd0bec8167e8676ce025e
--- /dev/null
+++ b/shortGPT/utils/requirements.py
@@ -0,0 +1,113 @@
+import os
+import platform
+
+
+class Requirements:
+ '''Manage requirements for the project'''
+
+ def __init__(self):
+ self.package_path = os.path.dirname(os.path.realpath(__file__))
+ self.requirements_path = os.path.join(self.package_path, '..', '..', 'requirements.txt')
+
+ def get_list_requirements(self):
+ '''Get the list of requirements packages from requirements.txt'''
+ with open(self.requirements_path) as f:
+ requirements = f.read().splitlines()
+
+ # remove comments and empty lines
+ requirements = [line for line in requirements if not line.startswith('#')]
+ requirements = [line for line in requirements if line.strip()]
+
+ # extract package name from protocol
+ requirements = [line.split('/')[-1] for line in requirements if not line.startswith('git+')]
+ requirements = [line.split('/')[-1] for line in requirements if not line.startswith('http')]
+ requirements = [line.split('/')[-1] for line in requirements if not line.startswith('https')]
+ requirements = [line.split('/')[-1] for line in requirements if not line.startswith('ssh')]
+ requirements = [line.split('/')[-1] for line in requirements if not line.startswith('git')]
+
+ # sort alphabetically
+ requirements.sort()
+
+ return requirements
+
+ def get_os_name(self):
+ '''Get the name of the operating system'''
+ return platform.system()
+
+ def get_os_version(self):
+ '''Get the version of the operating system'''
+ return platform.version()
+
+ def get_python_version(self):
+ '''Get the version of Python installed'''
+ return platform.python_version()
+
+ def is_all_requirements_installed(self):
+ '''Check if all requirements are installed'''
+ requirements = self.get_list_requirements()
+ for requirement in requirements:
+ if not self.is_requirement_installed(requirement):
+ return False
+ return True
+
+ def is_requirement_installed(self, package_name):
+ '''Check if a package is installed'''
+ import importlib
+ try:
+ importlib.import_module(package_name)
+ return True
+ except ImportError:
+ return False
+
+ def get_version(self, package_name):
+ '''Get the version of a package'''
+ import pkg_resources
+ try:
+ return pkg_resources.get_distribution(package_name).version
+ except:
+ return None
+
+ def get_all_requirements_versions(self):
+ '''Get the versions of all requirements'''
+ requirements = self.get_list_requirements()
+ versions = {}
+ for requirement in requirements:
+ versions[requirement] = self.get_version(requirement)
+ return versions
+
+ def get_all_requirements_not_installed(self):
+ '''Get the list of all requirements not installed'''
+ requirements = self.get_list_requirements()
+ not_installed = {}
+ for requirement in requirements:
+ # if version is None then the package is not installed
+ if self.get_version(requirement) is None:
+ not_installed[requirement] = self.get_version(requirement)
+ return not_installed
+
+
+if __name__ == '__main__':
+ '''Display information about the system and requirements'''
+ requirements_manager = Requirements()
+ # Skipping for now, because it assumes package have the same name as the python import itself, which is not true most sometimes.
+ # if not requirements_manager.is_all_requirements_installed():
+ # print("Error : Some requirements are missing")
+ # print("Please install all requirements from requirements.txt")
+ # print("You can install them by running the following command:")
+ # print("pip install -r requirements.txt")
+
+ print(f"System information:")
+ print(f"OS name : {requirements_manager.get_os_name()}")
+ print(f"OS version : {requirements_manager.get_os_version()}")
+ print(f"Python version : {requirements_manager.get_python_version()}")
+
+ # list all requirements and their versions
+ print("List of all requirements and their versions:")
+ all_req_versions = requirements_manager.get_all_requirements_versions()
+ for req_name, req_version in all_req_versions.items():
+ print(f"{req_name}=={req_version}")
+
+ print("List of all requirements not installed:")
+ all_req_not_installed = requirements_manager.get_all_requirements_not_installed()
+ for req_name, req_version in all_req_not_installed.items():
+ print(f"{req_name}=={req_version}")