Install Requirements. This is 1 Click Run App to create Short Videos
\n",
"# 📦 Install ImageMagick and ffmpeg\n",
"!sudo apt-get install imagemagick\n",
"!sudo apt-get install ffmpeg\n",
"\n",
"# 📝 Fix Imagemagick policy.xml bug in linux using MoviePy\n",
"!sed -i '/
Script To Video
Make Sure To Select ElevenLabs Or Edge TTS Only \n",
"# Import necessary modules from the ShortGPT framework\n",
"from shortGPT.config.api_db import ApiKeyManager, ApiProvider\n",
"from shortGPT.config.asset_db import AssetDatabase, AssetType\n",
"from shortGPT.engine.content_video_engine import ContentVideoEngine\n",
"from shortGPT.config.languages import Language, EDGE_TTS_VOICENAME_MAPPING\n",
"from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule\n",
"from shortGPT.audio.eleven_voice_module import ElevenLabsVoiceModule\n",
"from shortGPT.audio.coqui_voice_module import CoquiVoiceModule\n",
"\n",
"# Load API keys from hardcoded values - Consider using environment variables for better security\n",
"OPENAI_KEY = \"\" # @param {type:\"string\"}\n",
"ELEVEN_KEY = \"\" # @param {type:\"string\"}\n",
"PEXELS_KEY = \"\" # @param {type:\"string\"}\n",
"\n",
"# Set API Keys\n",
"ApiKeyManager.set_api_key(ApiProvider.OPENAI, OPENAI_KEY)\n",
"ApiKeyManager.set_api_key(ApiProvider.ELEVEN_LABS, ELEVEN_KEY)\n",
"ApiKeyManager.set_api_key(ApiProvider.PEXELS, PEXELS_KEY)\n",
"\n",
"# Add Assets\n",
"AssetDatabase.add_remote_asset('chill music', AssetType.BACKGROUND_MUSIC, \"https://www.youtube.com/watch?v=uUu1NcSHg2E\")\n",
"\n",
"# Function to select the voice module based on user preference\n",
"def select_voice_module(tts_engine, language, voice):\n",
" if tts_engine == \"Edge TTS\":\n",
" voice_name = EDGE_TTS_VOICENAME_MAPPING[Language[language.upper()]]['male'] # Defaulting to male if specific voice not handled\n",
" return EdgeTTSVoiceModule(voice_name)\n",
" elif tts_engine == \"ElevenLabs\":\n",
" if language not in eleven_labs_languages or voice not in eleven_labs_voices:\n",
" raise ValueError(f\"Selected language '{language}' or voice '{voice}' is not supported by ElevenLabs. Supported languages are: {', '.join(eleven_labs_languages)}. Supported voices are: {', '.join(eleven_labs_voices)}.\")\n",
" return ElevenLabsVoiceModule(api_key=ELEVEN_KEY, voiceName=voice)\n",
" elif tts_engine == \"Coqui TTS\":\n",
" if language not in coqui_tts_languages or voice not in coqui_tts_voices:\n",
" raise ValueError(f\"Selected language '{language}' or voice '{voice}' is not supported by Coqui TTS. Supported languages are: {', '.join(coqui_tts_languages)}. Supported voices are: {', '.join(coqui_tts_voices)}.\")\n",
" return CoquiVoiceModule(voiceName=voice, language=language)\n",
" else:\n",
" raise ValueError(\"Unsupported TTS Engine\")\n",
"\n",
"# Configure the Voice Module\n",
"TEXT_TO_SPEECH = \"Edge TTS\" # @param [\"Edge TTS\", \"ElevenLabs\", \"Coqui TTS\"]\n",
"LANGUAGE = \"English\" # @param [\"English\", \"Spanish\", \"French\", \"Arabic\", \"German\", \"Polish\", \"Italian\", \"Portuguese\"]\n",
"VOICE = \"Damjan Chapman\" # @param ['Rachel', 'Drew', 'Clyde', 'Paul', 'Domi', 'Dave', 'Fin', 'Sarah', 'Antoni', 'Thomas', 'Charlie', 'George', 'Emily', 'Elli', 'Callum', 'Patrick', 'Harry', 'Liam', 'Dorothy', 'Josh', 'Arnold', 'Charlotte', 'Matilda', 'Matthew', 'James', 'Joseph', 'Jeremy', 'Michael', 'Ethan', 'Gigi', 'Freya', 'Grace', 'Daniel', 'Lily', 'Serena', 'Adam', 'Nicole', 'Bill', 'Jessie', 'Sam', 'Glinda', 'Giovanni', 'Mimi', 'Claribel Dervla', 'Daisy Studious', 'Gracie Wise', 'Tammie Ema', 'Alison Dietlinde', 'Ana Florence', 'Annmarie Nele', 'Asya Anara', 'Brenda Stern', 'Gitta Nikolina', 'Henriette Usha', 'Sofia Hellen', 'Tammy Grit', 'Tanja Adelina', 'Vjollca Johnnie', 'Andrew Chipper', 'Badr Odhiambo', 'Dionisio Schuyler', 'Royston Min', 'Viktor Eka', 'Abrahan Mack', 'Adde Michal', 'Baldur Sanjin', 'Craig Gutsy', 'Damien Black', 'Gilberto Mathias', 'Ilkin Urbano', 'Kazuhiko Atallah', 'Ludvig Milivoj', 'Suad Qasim', 'Torcull Diarmuid', 'Viktor Menelaos', 'Zacharie Aimilios', 'Nova Hogarth', 'Maja Ruoho', 'Uta Obando', 'Barbora MacLean', 'Alexandra Hisakawa', 'Alma María', 'Rosemary Okafor', 'Ige Behringer', 'Filip Traverse', 'Damjan Chapman', 'Wulf Carlevaro', 'Aaron Dreschner', 'Kumar Dahl', 'Eugenio Mataracı', 'Ferran Simen', 'Xavier Hayasaka', 'Luis Moray', 'Marcos Rudaski']\n",
"try:\n",
" voice_module = select_voice_module(TEXT_TO_SPEECH, LANGUAGE, VOICE)\n",
"except ValueError as e:\n",
" print(f\"Error selecting voice module: {e}\")\n",
" # Fallback to a default voice module if error occurs\n",
" voice_module = EdgeTTSVoiceModule(EDGE_TTS_VOICENAME_MAPPING[Language.ENGLISH]['male'])\n",
"\n",
"# Prepare the script\n",
"SCRIPT = \"\\\"Artificial intelligence (AI) is revolutionizing our world in surprising ways. Robots and virtual assistants help us in our daily tasks and simplify our lives. In medicine, AI enables more accurate diagnoses and advances in treatments. In the automotive industry, autonomous vehicles are changing the way we get around. However, questions arise about the impact on employment and the ethics of its use. Despite the challenges, AI promises an exciting future full of possibilities. Are we ready to embrace this technological advancement?\" # @param {type:\"string\"}\n",
"\n",
"# Configure Content Engine\n",
"content_engine = ContentVideoEngine(voice_module, SCRIPT, background_music_name='chill music', language=Language[LANGUAGE.upper()])\n",
"\n",
"# Generate Content with error handling\n",
"try:\n",
" for step_num, step_logs in content_engine.makeContent():\n",
" print(f\"Step {step_num}: {step_logs}\")\n",
"except Exception as e:\n",
" print(f\"Error generating content: {e}\")\n",
"\n",
"# Get Video Output Path\n",
"print(\"Video Output Path:\", content_engine.get_video_output_path())"
],
"metadata": {
"cellView": "form",
"id": "lBqNgUmbacdF"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Import necessary modules from the ShortGPT framework\n",
"from shortGPT.config.api_db import ApiKeyManager, ApiProvider\n",
"from shortGPT.config.asset_db import AssetDatabase, AssetType\n",
"from shortGPT.engine.content_video_engine import ContentVideoEngine\n",
"from shortGPT.config.languages import Language, EDGE_TTS_VOICENAME_MAPPING, LANGUAGE_ACRONYM_MAPPING\n",
"from shortGPT.audio.edge_voice_module import EdgeTTSVoiceModule\n",
"from shortGPT.audio.eleven_voice_module import ElevenLabsVoiceModule\n",
"from shortGPT.audio.coqui_voice_module import CoquiVoiceModule\n",
"\n",
"# Load API keys from hardcoded values - Consider using environment variables for better security\n",
"OPENAI_KEY = \"\" # @param {type:\"string\"}\n",
"ELEVEN_KEY = \"\" # @param {type:\"string\"}\n",
"PEXELS_KEY = \"\" # @param {type:\"string\"}\n",
"\n",
"# Set API Keys\n",
"ApiKeyManager.set_api_key(ApiProvider.OPENAI, OPENAI_KEY)\n",
"ApiKeyManager.set_api_key(ApiProvider.ELEVEN_LABS, ELEVEN_KEY)\n",
"ApiKeyManager.set_api_key(ApiProvider.PEXELS, PEXELS_KEY)\n",
"\n",
"# Add Assets\n",
"AssetDatabase.add_remote_asset('chill music', AssetType.BACKGROUND_MUSIC, \"https://www.youtube.com/watch?v=uUu1NcSHg2E\")\n",
"\n",
"# Function to select the voice module based on user preference\n",
"def select_voice_module(tts_engine, language, voice):\n",
" if tts_engine == \"Edge TTS\":\n",
" voice_name = EDGE_TTS_VOICENAME_MAPPING[Language[language.upper()]]['male'] # Defaulting to male if specific voice not handled\n",
" return EdgeTTSVoiceModule(voice_name)\n",
" elif tts_engine == \"ElevenLabs\":\n",
" # Assuming eleven_labs_languages and eleven_labs_voices are defined elsewhere\n",
" return ElevenLabsVoiceModule(api_key=ELEVEN_KEY, voiceName=voice)\n",
" elif tts_engine == \"Coqui TTS\":\n",
" language_code = LANGUAGE_ACRONYM_MAPPING.get(Language[language.upper()], 'en') # Default to 'en' if not found\n",
" return CoquiVoiceModule(voiceName=voice, language=language_code)\n",
" else:\n",
" raise ValueError(\"Unsupported TTS Engine\")\n",
"\n",
"# Configure the Voice Module\n",
"TEXT_TO_SPEECH = \"Coqui TTS\" # @param [\"Edge TTS\", \"ElevenLabs\", \"Coqui TTS\"]\n",
"LANGUAGE = \"Hindi\" # @param [\"English\", \"Hindi\", \"French\", \"Arabic\", \"Urdu\", \"Roman Urdu\", \"Italian\", \"Portuguese\"]\n",
"VOICE = \"Damjan Chapman\" # @param ['Rachel', 'Drew', 'Clyde', 'Paul', 'Domi', 'Dave', 'Fin', 'Sarah', 'Antoni', 'Thomas', 'Charlie', 'George', 'Emily', 'Elli', 'Callum', 'Patrick', 'Harry', 'Liam', 'Dorothy', 'Josh', 'Arnold', 'Charlotte', 'Matilda', 'Matthew', 'James', 'Joseph', 'Jeremy', 'Michael', 'Ethan', 'Gigi', 'Freya', 'Grace', 'Daniel', 'Lily', 'Serena', 'Adam', 'Nicole', 'Bill', 'Jessie', 'Sam', 'Glinda', 'Giovanni', 'Mimi', 'Claribel Dervla', 'Daisy Studious', 'Gracie Wise', 'Tammie Ema', 'Alison Dietlinde', 'Ana Florence', 'Annmarie Nele', 'Asya Anara', 'Brenda Stern', 'Gitta Nikolina', 'Henriette Usha', 'Sofia Hellen', 'Tammy Grit', 'Tanja Adelina', 'Vjollca Johnnie', 'Andrew Chipper', 'Badr Odhiambo', 'Dionisio Schuyler', 'Royston Min', 'Viktor Eka', 'Abrahan Mack', 'Adde Michal', 'Baldur Sanjin', 'Craig Gutsy', 'Damien Black', 'Gilberto Mathias', 'Ilkin Urbano', 'Kazuhiko Atallah', 'Ludvig Milivoj', 'Suad Qasim', 'Torcull Diarmuid', 'Viktor Menelaos', 'Zacharie Aimilios', 'Nova Hogarth', 'Maja Ruoho', 'Uta Obando', 'Barbora MacLean', 'Alexandra Hisakawa', 'Alma María', 'Rosemary Okafor', 'Ige Behringer', 'Filip Traverse', 'Damjan Chapman', 'Wulf Carlevaro', 'Aaron Dreschner', 'Kumar Dahl', 'Eugenio Mataracı', 'Ferran Simen', 'Xavier Hayasaka', 'Luis Moray', 'Marcos Rudaski']\n",
"# Prepare the script\n",
"SCRIPT = \"SCRIPT = \\\"एक समय की बात है, जब पृथ्वी पर जीवन की शुरुआत हुई थी। इस ग्रह पर एक अनोखी प्रजाति ने अपने कदम रखे, जिसे हम मानव कहते हैं। यह कहानी है उस मानव जाति की, जिसने समय के साथ अपने जीवन को नई दिशा दी। शुरुआत में, मानव जंगलों और गुफाओं में रहते थे। उनका जीवन संघर्षों से भरा था। उन्होंने आग की खोज की, जिससे उनके जीवन में एक नई रोशनी आई। आग ने उन्हें ठंड से बचाया और खाना पकाने का तरीका सिखाया। समय के साथ, मानव ने खेती की शुरुआत की। उन्होंने अनाज उगाना शुरू किया और पशुओं को पालना सीखा। इससे उनके जीवन में स्थिरता आई और समाज का विकास हुआ। फिर आया सभ्यताओं का युग। मानव ने नदियों के किनारे बस्तियाँ बसाईं और विशाल साम्राज्यों की नींव रखी। उन्होंने लिपि का आविष्कार किया, जिससे ज्ञान का संचार हुआ। विज्ञान, कला, और साहित्य के क्षेत्र में उन्होंने अद्भुत कार्य किए। लेकिन मानव इतिहास में संघर्ष भी रहे। युद्ध, महामारी, और प्राकृतिक आपदाओं ने मानवता की परीक्षा ली। फिर भी, मानव ने कभी हार नहीं मानी। उन्होंने हर बार उठकर एक नई शुरुआत की। आज, हम एक ऐसे युग में हैं, जहाँ तकनीकी ने हमारे जीवन को बदल दिया है। हमने चाँद पर कदम रखा है और अंतरिक्ष की गहराइयों को छूने की कोशिश की है। यह कहानी हमें याद दिलाती है कि मानव जाति का इतिहास संघर्ष और विजय की कहानी है। हमारी यात्रा अद्भुत रही है, और हमारा भविष्य अभी भी लिखा जा रहा है। हमें अपने पूर्वजों की विरासत को आगे बढ़ा\" # @param {type:\"string\"}\n",
"\n",
"try:\n",
" voice_module = select_voice_module(TEXT_TO_SPEECH, LANGUAGE, VOICE)\n",
"except ValueError as e:\n",
" print(f\"Error selecting voice module: {e}\")\n",
" # Fallback to a default voice module if error occurs\n",
" voice_module = EdgeTTSVoiceModule(EDGE_TTS_VOICENAME_MAPPING[Language.ENGLISH]['male'])\n",
"\n",
"# Prepare the script\n",
"SCRIPT = \"\\\"Artificial intelligence (AI) is revolutionizing our world in surprising ways. Robots and virtual assistants help us in our daily tasks and simplify our lives. In medicine, AI enables more accurate diagnoses and advances in treatments. In the automotive industry, autonomous vehicles are changing the way we get around. However, questions arise about the impact on employment and the ethics of its use. Despite the challenges, AI promises an exciting future full of possibilities. Are we ready to embrace this technological advancement?\"\n",
"\n",
"# Configure Content Engine\n",
"content_engine = ContentVideoEngine(voice_module, SCRIPT, background_music_name='chill music', language=Language[LANGUAGE.upper()])\n",
"\n",
"# Generate Content with error handling\n",
"try:\n",
" for step_num, step_logs in content_engine.makeContent():\n",
" print(f\"Step {step_num}: {step_logs}\")\n",
"except Exception as e:\n",
" print(f\"Error generating content: {e}\")\n",
"\n",
"# Get Video Output Path\n",
"print(\"Video Output Path:\", content_engine.get_video_output_path())"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"cellView": "form",
"id": "s8eBfDIO6Ayl",
"outputId": "b54a9d5f-aa05-47f6-c195-9e1b2812fa92"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" > tts_models/multilingual/multi-dataset/xtts_v2 is already downloaded.\n",
"Error selecting voice module: Expecting value: line 1 column 1 (char 0)\n",
"Step 1: Current step (1 / 10) : _generateTempAudio\n",
"Step 2: Current step (2 / 10) : _speedUpAudio\n",
"Step 3: Current step (3 / 10) : _timeCaptions\n",
"Importing the dtw module. When using in academic works please cite:\n",
" T. Giorgino. Computing and Visualizing Dynamic Time Warping Alignments in R: The dtw Package.\n",
" J. Stat. Soft., doi:10.18637/jss.v031.i07.\n",
"\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|███████████████████████████████████████| 139M/139M [00:03<00:00, 39.6MiB/s]\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Detected language: English\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|██████████| 396/396 [00:00<00:00, 858.28frames/s]\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Step 4: Current step (4 / 10) : _generateVideoSearchTerms\n",
"Expecting value: line 1 column 1 (char 0)\n",
"not the right format\n",
"Expecting value: line 1 column 1 (char 0)\n",
"not the right format\n",
"Expecting value: line 1 column 1 (char 0)\n",
"not the right format\n",
"Expecting value: line 1 column 1 (char 0)\n",
"not the right format\n",
"Expecting value: line 1 column 1 (char 0)\n",
"not the right format\n",
"Expecting value: line 1 column 1 (char 0)\n",
"not the right format\n",
"Expecting value: line 1 column 1 (char 0)\n",
"not the right format\n",
"Step 5: Current step (5 / 10) : _generateVideoUrls\n",
"Step 6: Current step (6 / 10) : _chooseBackgroundMusic\n",
"\u001b[KStep 7: Current step (7 / 10) : _prepareBackgroundAssets\n",
"Step 8: Current step (8 / 10) : _prepareCustomAssets\n",
"Step 9: Current step (9 / 10) : Preparing rendering assets...\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\n",
"\u001b[A\n",
"100%|██████████| 68.0/68.0 [09:58<00:00, 8.80s/iB]\u001b[A\n",
"\u001b[A\n",
"100%|██████████| 68.0/68.0 [09:58<00:00, 8.80s/iB]\u001b[A"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Moviepy - Building video .editing_assets/general_video_assets/d497348cbfcb418d835889a4/rendered_video.mp4.\n",
"MoviePy - Writing audio in rendered_videoTEMP_MPY_wvf_snd.mp4\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\n",
"\u001b[A\n",
"100%|██████████| 68.0/68.0 [09:58<00:00, 8.80s/iB]\u001b[A\n",
"\u001b[A\n",
"100%|██████████| 68.0/68.0 [09:58<00:00, 8.80s/iB]\u001b[A"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"MoviePy - Done.\n",
"Moviepy - Writing video .editing_assets/general_video_assets/d497348cbfcb418d835889a4/rendered_video.mp4\n",
"\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\n",
"\u001b[A\n",
"100%|██████████| 68.0/68.0 [10:05<00:00, 8.90s/iB]\u001b[A\n",
"\u001b[A\n",
"100%|██████████| 68.0/68.0 [10:05<00:00, 8.90s/iB]\u001b[A"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Moviepy - Done !\n",
"Moviepy - video ready .editing_assets/general_video_assets/d497348cbfcb418d835889a4/rendered_video.mp4\n",
"Step 10: Current step (10 / 10) : _addMetadata\n",
"Video Output Path: videos/2024-02-28_21-37-54 - The Future of AI Boon or Bane .mp4\n"
]
}
]
}
],
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"nbformat": 4,
"nbformat_minor": 0
}