Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
camenduru authored Jun 5, 2023
1 parent ca3be72 commit 416afc8
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions potat1_text_to_video_diffusers.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github"
},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/text-to-video-synthesis-colab/blob/main/potat1_text_to_video_diffusers.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#https://github.com/huggingface/diffusers/pull/2738 modified\n",
"!pip install git+https://github.com/huggingface/diffusers transformers accelerate imageio[ffmpeg] -U\n",
"!pip install -q torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 torchtext==0.14.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu116 -U"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "n2ibl97e2yM4"
},
"outputs": [],
"source": [
"import torch\n",
"from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler\n",
"from diffusers.utils import export_to_video\n",
"from IPython.display import HTML\n",
"from base64 import b64encode\n",
"import datetime\n",
"\n",
"pipe = DiffusionPipeline.from_pretrained(\"camenduru/potat1\", torch_dtype=torch.float16)\n",
"pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)\n",
"pipe.enable_model_cpu_offload()\n",
"pipe.enable_vae_slicing()\n",
"\n",
"!mkdir /content/videos"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"prompt = 'Darth Vader surfing a wave' #@param {type:\"string\"}\n",
"negative_prompt = \"low quality\" #@param {type:\"string\"}\n",
"num_frames = 30 #@param {type:\"raw\"}\n",
"video_frames = pipe(prompt, negative_prompt=negative_prompt, width=1024, height=576, num_inference_steps=25, num_frames=num_frames).frames\n",
"output_video_path = export_to_video(video_frames)\n",
"\n",
"new_video_path = f'/content/videos/{datetime.datetime.now().strftime(\"%Y-%m-%d_%H:%M:%S\")}.mp4'\n",
"!ffmpeg -y -i {output_video_path} -c:v libx264 -c:a aac -strict -2 {new_video_path} >/dev/null 2>&1\n",
"\n",
"print(output_video_path, '->', new_video_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!cp {new_video_path} /content/videos/tmp.mp4\n",
"mp4 = open('/content/videos/tmp.mp4','rb').read()\n",
"\n",
"decoded_vid = \"data:video/mp4;base64,\" + b64encode(mp4).decode()\n",
"HTML(f'<video width=400 controls><source src=\"{decoded_vid}\" type=\"video/mp4\"></video>')"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 416afc8

Please sign in to comment.