{"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/VideoCrafter-colab/blob/main/VideoCrafter2_Text2Video_colab.ipynb)"]},{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":30513,"status":"ok","timestamp":1713870077040,"user":{"displayName":"Emm宥","userId":"02154495825231234225"},"user_tz":-480},"id":"CNvwy0Cv18wX","outputId":"5112ac4e-9b96-4b14-8068-0350a7cd04a9"},"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}],"source":["from google.colab import drive\n","drive.mount('/content/drive')"]},{"cell_type":"code","execution_count":2,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":1136,"status":"ok","timestamp":1713870309378,"user":{"displayName":"Emm宥","userId":"02154495825231234225"},"user_tz":-480},"id":"vAClybTp2HOm","outputId":"65efc670-482d-4eff-c988-5fe091410dad"},"outputs":[{"output_type":"stream","name":"stdout","text":["/content/drive/.shortcut-targets-by-id/1XIExHgH8yTJSya4f1RGhW5Z-hwQwqif_/FYP/Code/VideoCrafter\n"]}],"source":["%cd /content/drive/MyDrive/FYP/Code/VideoCrafter"]},{"cell_type":"markdown","metadata":{"id":"d3GbIcnTAVTO"},"source":["### Install packages"]},{"cell_type":"code","execution_count":3,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":93702,"status":"ok","timestamp":1713870407193,"user":{"displayName":"Emm宥","userId":"02154495825231234225"},"user_tz":-480},"id":"6W2VgRanJCUK","outputId":"6b8ab9f6-2f5d-424f-ef7b-349ab29403f1"},"outputs":[{"output_type":"stream","name":"stdout","text":["\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.6/13.6 MB\u001b[0m \u001b[31m43.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m44.6/44.6 kB\u001b[0m \u001b[31m5.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m79.5/79.5 kB\u001b[0m \u001b[31m11.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m801.9/801.9 kB\u001b[0m \u001b[31m48.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m33.8/33.8 MB\u001b[0m \u001b[31m44.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.1/17.1 MB\u001b[0m \u001b[31m78.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m86.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.5/1.5 MB\u001b[0m \u001b[31m72.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m825.4/825.4 kB\u001b[0m \u001b[31m63.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m117.0/117.0 kB\u001b[0m \u001b[31m16.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m841.5/841.5 kB\u001b[0m \u001b[31m65.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m91.9/91.9 kB\u001b[0m \u001b[31m12.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m313.6/313.6 kB\u001b[0m \u001b[31m38.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m9.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.1/141.1 kB\u001b[0m \u001b[31m18.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m8.7/8.7 MB\u001b[0m \u001b[31m37.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m47.2/47.2 kB\u001b[0m \u001b[31m5.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m60.8/60.8 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m129.9/129.9 kB\u001b[0m \u001b[31m14.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m54.4/54.4 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m103.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m12.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.9/71.9 kB\u001b[0m \u001b[31m9.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h Building wheel for antlr4-python3-runtime (setup.py) ... \u001b[?25l\u001b[?25hdone\n"," Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n","\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n","spacy 3.7.4 requires typer<0.10.0,>=0.3.0, but you have typer 0.12.3 which is incompatible.\n","weasel 0.3.4 requires typer<0.10.0,>=0.3.0, but you have typer 0.12.3 which is incompatible.\u001b[0m\u001b[31m\n","\u001b[0m"]}],"source":["# install packages for VideoCrafer\n","!pip install -q decord einops omegaconf pytorch_lightning transformers av gradio timm open_clip_torch kornia gradio"]},{"cell_type":"code","execution_count":4,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":1000},"executionInfo":{"elapsed":22435,"status":"ok","timestamp":1713870436003,"user":{"displayName":"Emm宥","userId":"02154495825231234225"},"user_tz":-480},"id":"ibCOXjPCmrri","outputId":"a6859489-e601-4a5a-f170-5070ccbd7037"},"outputs":[{"output_type":"stream","name":"stdout","text":["/content/drive/.shortcut-targets-by-id/1XIExHgH8yTJSya4f1RGhW5Z-hwQwqif_/FYP/Code/VideoCrafter/ECCV2022-RIFE\n","Collecting numpy<=1.23.5,>=1.16 (from -r requirements.txt (line 1))\n"," Downloading numpy-1.23.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.1/17.1 MB\u001b[0m \u001b[31m19.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: tqdm>=4.35.0 in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 2)) (4.66.2)\n","Collecting sk-video>=1.1.10 (from -r requirements.txt (line 3))\n"," Downloading sk_video-1.1.10-py2.py3-none-any.whl (2.3 MB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.3/2.3 MB\u001b[0m \u001b[31m45.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25hRequirement already satisfied: torch>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 4)) (2.2.1+cu121)\n","Requirement already satisfied: opencv-python>=4.1.2 in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 5)) (4.8.0.76)\n","Requirement already satisfied: moviepy>=1.0.3 in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 6)) (1.0.3)\n","Requirement already satisfied: torchvision>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 7)) (0.17.1+cu121)\n","Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from sk-video>=1.1.10->-r requirements.txt (line 3)) (1.11.4)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (3.13.4)\n","Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (4.11.0)\n","Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (1.12)\n","Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (3.3)\n","Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (3.1.3)\n","Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (2023.6.0)\n","Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (12.1.105)\n","Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (12.1.105)\n","Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (12.1.105)\n","Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (8.9.2.26)\n","Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (12.1.3.1)\n","Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (11.0.2.54)\n","Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (10.3.2.106)\n","Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (11.4.5.107)\n","Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (12.1.0.106)\n","Requirement already satisfied: nvidia-nccl-cu12==2.19.3 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (2.19.3)\n","Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (12.1.105)\n","Requirement already satisfied: triton==2.2.0 in /usr/local/lib/python3.10/dist-packages (from torch>=1.6.0->-r requirements.txt (line 4)) (2.2.0)\n","Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/lib/python3.10/dist-packages (from nvidia-cusolver-cu12==11.4.5.107->torch>=1.6.0->-r requirements.txt (line 4)) (12.4.127)\n","Requirement already satisfied: decorator<5.0,>=4.0.2 in /usr/local/lib/python3.10/dist-packages (from moviepy>=1.0.3->-r requirements.txt (line 6)) (4.4.2)\n","Requirement already satisfied: requests<3.0,>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from moviepy>=1.0.3->-r requirements.txt (line 6)) (2.31.0)\n","Requirement already satisfied: proglog<=1.0.0 in /usr/local/lib/python3.10/dist-packages (from moviepy>=1.0.3->-r requirements.txt (line 6)) (0.1.10)\n","Requirement already satisfied: imageio<3.0,>=2.5 in /usr/local/lib/python3.10/dist-packages (from moviepy>=1.0.3->-r requirements.txt (line 6)) (2.31.6)\n","Requirement already satisfied: imageio-ffmpeg>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from moviepy>=1.0.3->-r requirements.txt (line 6)) (0.4.9)\n","Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.10/dist-packages (from torchvision>=0.7.0->-r requirements.txt (line 7)) (9.4.0)\n","Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from imageio-ffmpeg>=0.2.0->moviepy>=1.0.3->-r requirements.txt (line 6)) (67.7.2)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3.0,>=2.8.1->moviepy>=1.0.3->-r requirements.txt (line 6)) (3.3.2)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3.0,>=2.8.1->moviepy>=1.0.3->-r requirements.txt (line 6)) (3.7)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3.0,>=2.8.1->moviepy>=1.0.3->-r requirements.txt (line 6)) (2.0.7)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3.0,>=2.8.1->moviepy>=1.0.3->-r requirements.txt (line 6)) (2024.2.2)\n","Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=1.6.0->-r requirements.txt (line 4)) (2.1.5)\n","Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch>=1.6.0->-r requirements.txt (line 4)) (1.3.0)\n","Installing collected packages: numpy, sk-video\n"," Attempting uninstall: numpy\n"," Found existing installation: numpy 1.25.2\n"," Uninstalling numpy-1.25.2:\n"," Successfully uninstalled numpy-1.25.2\n","\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n","chex 0.1.86 requires numpy>=1.24.1, but you have numpy 1.23.5 which is incompatible.\n","pandas-stubs 2.0.3.230814 requires numpy>=1.25.0; python_version >= \"3.9\", but you have numpy 1.23.5 which is incompatible.\n","spacy 3.7.4 requires typer<0.10.0,>=0.3.0, but you have typer 0.12.3 which is incompatible.\u001b[0m\u001b[31m\n","\u001b[0mSuccessfully installed numpy-1.23.5 sk-video-1.1.10\n"]},{"output_type":"display_data","data":{"application/vnd.colab-display-data+json":{"pip_warning":{"packages":["numpy"]},"id":"80691009eccd4f729689e4bff2982353"}},"metadata":{}},{"output_type":"stream","name":"stdout","text":["/content/drive/.shortcut-targets-by-id/1XIExHgH8yTJSya4f1RGhW5Z-hwQwqif_/FYP/Code/VideoCrafter\n"]}],"source":["# install packages for RIFE\n","%cd /content/drive/MyDrive/FYP/Code/VideoCrafter/ECCV2022-RIFE\n","!pip3 install -r requirements.txt\n","%cd /content/drive/MyDrive/FYP/Code/VideoCrafter"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bC4FaN2G7QRB"},"outputs":[],"source":["!pip install vbench\n","!pip install detectron2@git+https://github.com/facebookresearch/detectron2.git"]},{"cell_type":"code","execution_count":5,"metadata":{"id":"jy9B5y2jqMhY","executionInfo":{"status":"ok","timestamp":1713870436003,"user_tz":-480,"elapsed":7,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["basedir = \"/content/drive/MyDrive/FYP/Code/VideoCrafter\"\n","# if you change the variables here, remember to change the \"name\" in .sh file\n","vidOut = \"results/10videos\"\n","uvqOut = \"results/modified_prompts_eval\"\n","evalOut = \"evaluation_results\"\n","num_of_vid = 3\n","vid_length = 2\n","uvq_threshold = 3.8\n","fps = 24"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"V_rIhU83pDz1"},"outputs":[],"source":["# install packages for UVQ\n","# !pip3 install -r ./uvq/requirements.txt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"w8XE9VY8QXXe"},"outputs":[],"source":["# Testing cell (do not modify)\n","!sh {basedir}/scripts/run_text2video.sh"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":7684,"status":"ok","timestamp":1712657429572,"user":{"displayName":"Hsin-ning LEE","userId":"07731733937501311439"},"user_tz":-480},"id":"23QwbfryQy3t","outputId":"c56cc194-9538-40b9-a5ef-5b00269ab634"},"outputs":[{"name":"stdout","output_type":"stream","text":["/content/drive/MyDrive/FYP/Code/VideoCrafter/ECCV2022-RIFE\n","Loaded v3.x HD model.\n","/content/drive/MyDrive/FYP/Code/VideoCrafter/results/test/000155204.mp4, 20.0 frames in total, 4.0FPS to 10FPS\n","Will not merge audio because using png or fps flag!\n"," 95% 19/20.0 [00:01<00:00, 9.81it/s]\n","/content/drive/MyDrive/FYP/Code/VideoCrafter\n"]}],"source":["# Testing cell (do not modify)\n","%cd /content/drive/MyDrive/FYP/Code/VideoCrafter/ECCV2022-RIFE\n","!python3 inference_video.py --exp=2 --video={basedir}/{vidOut}/000155204.mp4 --fps 10\n","%cd /content/drive/MyDrive/FYP/Code/VideoCrafter"]},{"cell_type":"markdown","source":["### Train Refined RIFE"],"metadata":{"id":"d0j0AowURpdD"}},{"cell_type":"code","source":["%cd /content/drive/MyDrive/FYP/Code/VideoCrafter/ECCV2022-RIFE"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"MGHih9yURo5H","executionInfo":{"status":"ok","timestamp":1713846073935,"user_tz":-480,"elapsed":5,"user":{"displayName":"Hsin-ning LEE","userId":"07731733937501311439"}},"outputId":"eeaa4c10-c280-4809-fcf1-2c375de4b727"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["/content/drive/MyDrive/FYP/Code/VideoCrafter/ECCV2022-RIFE\n"]}]},{"cell_type":"code","source":["!python -m torch.distributed.launch --use-env --nproc_per_node=1 train.py --world_size=1 --epoch 1"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"v1FuythZL9IN","executionInfo":{"status":"ok","timestamp":1713852053069,"user_tz":-480,"elapsed":27010,"user":{"displayName":"Hsin-ning LEE","userId":"07731733937501311439"}},"outputId":"5ee68051-31f2-4924-eb4a-624976bb1917"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["/usr/local/lib/python3.10/dist-packages/torch/distributed/launch.py:183: FutureWarning: The module torch.distributed.launch is deprecated\n","and will be removed in future. Use torchrun.\n","Note that --use-env is set by default in torchrun.\n","If your script expects `--local-rank` argument to be set, please\n","change it to read from `os.environ['LOCAL_RANK']` instead. See \n","https://pytorch.org/docs/stable/distributed.html#launch-utility for \n","further instructions\n","\n"," warnings.warn(\n","2024-04-23 06:00:30.957374: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n","2024-04-23 06:00:30.957421: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n","2024-04-23 06:00:30.958820: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n","2024-04-23 06:00:32.110672: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n","training...\n","/usr/lib/python3.10/multiprocessing/popen_fork.py:66: RuntimeWarning: os.fork() was called. os.fork() is incompatible with multithreaded code, and JAX is multithreaded, so this will likely lead to a deadlock.\n"," self.pid = os.fork()\n","epoch:0 0/47 time:1.49+3.39 loss_l1:5.3578e-02\n","epoch:0 4/47 time:0.00+0.14 loss_l1:6.0883e-02\n","epoch:0 2/47 time:1.24+0.12 loss_l1:6.3038e-02\n","epoch:0 3/47 time:0.03+0.12 loss_l1:6.2967e-02\n","epoch:0 4/47 time:0.03+0.12 loss_l1:6.3533e-02\n","epoch:0 5/47 time:0.03+0.12 loss_l1:6.4046e-02\n","epoch:0 6/47 time:0.03+0.12 loss_l1:4.8200e-02\n","epoch:0 7/47 time:0.03+0.13 loss_l1:6.3455e-02\n","epoch:0 8/47 time:0.02+0.11 loss_l1:6.7046e-02\n","epoch:0 9/47 time:0.03+0.12 loss_l1:5.6069e-02\n","epoch:0 10/47 time:0.03+0.12 loss_l1:6.7603e-02\n","epoch:0 11/47 time:0.04+0.11 loss_l1:6.4369e-02\n","epoch:0 12/47 time:0.03+0.12 loss_l1:6.2070e-02\n","epoch:0 13/47 time:0.03+0.12 loss_l1:6.2684e-02\n","epoch:0 14/47 time:0.03+0.13 loss_l1:6.6060e-02\n","epoch:0 15/47 time:0.02+0.12 loss_l1:6.0925e-02\n","epoch:0 16/47 time:0.03+0.13 loss_l1:7.1971e-02\n","epoch:0 17/47 time:0.02+0.13 loss_l1:7.0101e-02\n","epoch:0 18/47 time:0.03+0.12 loss_l1:6.0825e-02\n","epoch:0 19/47 time:0.03+0.12 loss_l1:5.1351e-02\n","epoch:0 20/47 time:0.03+0.13 loss_l1:6.6889e-02\n","epoch:0 21/47 time:0.02+0.12 loss_l1:4.5618e-02\n","epoch:0 22/47 time:0.02+0.12 loss_l1:5.7932e-02\n","epoch:0 23/47 time:0.03+0.12 loss_l1:7.1512e-02\n","epoch:0 24/47 time:0.03+0.11 loss_l1:6.1411e-02\n","epoch:0 25/47 time:0.03+0.13 loss_l1:7.0757e-02\n","epoch:0 26/47 time:0.03+0.12 loss_l1:5.6132e-02\n","epoch:0 27/47 time:0.03+0.12 loss_l1:4.7736e-02\n","epoch:0 28/47 time:0.03+0.12 loss_l1:4.5259e-02\n","epoch:0 29/47 time:0.03+0.12 loss_l1:5.7784e-02\n","epoch:0 30/47 time:0.02+0.13 loss_l1:6.3638e-02\n","epoch:0 31/47 time:0.02+0.13 loss_l1:4.9310e-02\n","epoch:0 32/47 time:0.03+0.12 loss_l1:6.6088e-02\n","epoch:0 33/47 time:0.03+0.12 loss_l1:4.3592e-02\n","epoch:0 34/47 time:0.03+0.12 loss_l1:5.6855e-02\n","epoch:0 35/47 time:0.03+0.11 loss_l1:5.9936e-02\n","epoch:0 36/47 time:0.03+0.13 loss_l1:6.7456e-02\n","epoch:0 37/47 time:0.02+0.12 loss_l1:6.4922e-02\n","epoch:0 38/47 time:0.02+0.12 loss_l1:4.9365e-02\n","epoch:0 39/47 time:0.03+0.11 loss_l1:6.3052e-02\n","epoch:0 40/47 time:0.03+0.14 loss_l1:6.0425e-02\n","epoch:0 41/47 time:0.01+0.12 loss_l1:5.6650e-02\n","epoch:0 42/47 time:0.03+0.11 loss_l1:5.6433e-02\n","epoch:0 43/47 time:0.04+0.11 loss_l1:5.1068e-02\n","epoch:0 44/47 time:0.02+0.10 loss_l1:6.8567e-02\n","epoch:0 45/47 time:0.04+0.11 loss_l1:5.3305e-02\n","epoch:0 46/47 time:0.04+0.10 loss_l1:5.6352e-02\n"]}]},{"cell_type":"markdown","metadata":{"id":"KLj0mG90KWu0"},"source":["### Function: Modify text prompts using GPT API"]},{"cell_type":"code","execution_count":6,"metadata":{"id":"WR3zkT1s1x20","executionInfo":{"status":"ok","timestamp":1713870560892,"user_tz":-480,"elapsed":517,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["# call the GPT API here\n","import requests\n","import fileinput\n","\n","# file = \"/content/drive/MyDrive/FYP/Code/VideoCrafter/scripts/run_text2video.sh\"\n","# file = \"/content/drive/MyDrive/FYP/Code/VideoCrafter/prompts/test_prompts.txt\"\n","\n","def call_gpt_api(prompt):\n"," api_key = \"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\"\n","\n"," response = requests.post(\n"," 'https://api.openai.com/v1/chat/completions',\n"," headers = {\n"," 'Content-Type': 'application/json',\n"," 'Authorization': f'Bearer {api_key}'\n"," },\n"," json = {\n"," 'messages': [{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': prompt}],\n"," 'model': 'gpt-3.5-turbo',\n"," # 'prompt': prompt,\n"," 'temperature': 0.4,\n"," 'max_tokens': 200\n"," })\n"," response_json = response.json()\n"," choices = response_json['choices']\n"," contents = [choice['message']['content'] for choice in choices]\n"," contents = [sentence for sublist in contents for sentence in sublist.split('\\n')]\n"," # Remove the leading number and dot from each sentence\n"," sentences = [content.lstrip('1234567890.- ') for content in contents]\n"," if len(sentences)>2:\n"," sentences = sentences[1:]\n"," return sentences\n"]},{"cell_type":"markdown","metadata":{"id":"2XzrqkFAKz5m"},"source":["### Functions: Select highest scored video using UVQ (genScore & getScore)"]},{"cell_type":"code","execution_count":7,"metadata":{"id":"GCw41_GYNvoL","executionInfo":{"status":"ok","timestamp":1713870562450,"user_tz":-480,"elapsed":3,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["# Generate the scores in csv files\n","def genScore():\n"," for i in range(1, num_of_vid+1):\n"," fileindex= f\"{i:04d}\"\n"," !python3 ./uvq/uvq_main.py --input_files=\"{fileindex},2,{basedir}/{vidOut}/{fileindex}.mp4\" --output_dir {uvqOut} --model_dir ./uvq/models"]},{"cell_type":"code","execution_count":8,"metadata":{"id":"gHP5Dskvz6od","executionInfo":{"status":"ok","timestamp":1713870562948,"user_tz":-480,"elapsed":4,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["def getScore(filename):\n"," # MOS_score defines the output of the uvq score\n"," lines = str(filename).split('\\n')\n"," last_line = lines[-1]\n"," MOS_score = last_line.split(',')[-1]\n"," MOS_score = MOS_score[:-2]\n","\n"," return MOS_score"]},{"cell_type":"code","execution_count":9,"metadata":{"id":"xWeSOyAcgFxN","executionInfo":{"status":"ok","timestamp":1713870564230,"user_tz":-480,"elapsed":2,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["# MOS_score defines the Mean Opinion Score of prediction, if the video's MOS exceeds the threshold then we directly use this video\n","def chooseBestVideo():\n"," MOS_score_high = 0\n"," preferred_output = \"\"\n"," chosen_idx = 0\n","\n"," for i in range(1, num_of_vid+1):\n"," '''We loop thru this current processed video'''\n"," filedir = f\"{i:04d}\"\n"," filename = f\"{i:04d}_uvq.csv\"\n"," MOS = !cat \"{basedir}/{uvqOut}/{filedir}/{filename}\"\n","\n"," MOS_score = getScore(MOS)\n"," print(\"Video Index:\", f\"{i:04d}\", \"Score:\", MOS_score)\n","\n"," #if the MOS_score is higher than the previous video, we choose this video as our preferred video output\n"," if float(MOS_score)>float(MOS_score_high) or float(MOS_score) > uvq_threshold:\n"," MOS_score_high = MOS_score\n"," preferred_output = filename\n"," chosen_idx = i\n","\n"," if float(MOS_score) > uvq_threshold:\n"," break\n"," return chosen_idx\n"," # print(MOS_score_high)\n"," # print(preferred_output)"]},{"cell_type":"markdown","metadata":{"id":"WJLO0unQ6Zu6"},"source":["### Functions: VBench Evaluation"]},{"cell_type":"code","execution_count":10,"metadata":{"id":"pN6qKWbKlmS0","executionInfo":{"status":"ok","timestamp":1713870565417,"user_tz":-480,"elapsed":4,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["import json\n","\n","def extract_scores_from_json(json_path):\n"," with open(json_path) as file:\n"," data = json.load(file)\n","\n"," for key, value in data.items():\n"," if isinstance(value, list) and len(value) > 1 and isinstance(value[0], float):\n"," motion_score = value[0]\n","\n"," return motion_score"]},{"cell_type":"code","execution_count":11,"metadata":{"id":"XdvfuQZJohMa","executionInfo":{"status":"ok","timestamp":1713870566002,"user_tz":-480,"elapsed":3,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["def VBench_eval(vid_filename):\n"," # vid_filename: video filename without .mp4\n"," !python VBench/evaluate.py --dimension 'motion_smoothness' --videos_path /{basedir}/{vidOut}/{vid_filename}.mp4 --custom_input --output_filename {vid_filename}\n"," eval_file_path = f\"{basedir}/{evalOut}/{vid_filename}_eval_results.json\"\n"," motion_score = extract_scores_from_json(eval_file_path)\n","\n"," return motion_score\n"]},{"cell_type":"markdown","metadata":{"id":"HmaA44Yxefgr"},"source":["### Function: Interpolation using RIFE"]},{"cell_type":"code","execution_count":12,"metadata":{"id":"1voR6Lg7WIPw","executionInfo":{"status":"ok","timestamp":1713870568746,"user_tz":-480,"elapsed":556,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["import math\n","\n","def interpolation(chosen_idx, fps):\n"," vid_filename = f\"{chosen_idx:04d}.mp4\"\n"," %cd /content/drive/MyDrive/FYP/Code/VideoCrafter/ECCV2022-RIFE\n"," !python3 inference_video.py --exp=2 --video={basedir}/{vidOut}/{vid_filename} --fps {fps}\n"," %cd /content/drive/MyDrive/FYP/Code/VideoCrafter\n"," out_name = f\"{chosen_idx:04d}_4X_{fps}fps.mp4\"\n"," return out_name"]},{"cell_type":"markdown","metadata":{"id":"H1zP8F6pZoD_"},"source":["### Function: Generate videos\n"]},{"cell_type":"code","execution_count":13,"metadata":{"id":"e4S2_P_HfFNQ","executionInfo":{"status":"ok","timestamp":1713870569273,"user_tz":-480,"elapsed":2,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["# call the GPT API here\n","import requests\n","import fileinput\n","\n","def call_gpt_api(prompt, isSentence = False):\n"," api_key = \"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\"\n","\n"," response = requests.post(\n"," 'https://api.openai.com/v1/chat/completions',\n"," headers = {\n"," 'Content-Type': 'application/json',\n"," 'Authorization': f'Bearer {api_key}'\n"," },\n"," json = {\n"," 'messages': [{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': prompt}],\n"," 'model': 'gpt-3.5-turbo',\n"," # 'prompt': prompt,\n"," 'temperature': 0.4,\n"," 'max_tokens': 200\n"," })\n"," response_json = response.json()\n"," choices = response_json['choices']\n"," contents = [choice['message']['content'] for choice in choices]\n"," contents = [sentence for sublist in contents for sentence in sublist.split('\\n')]\n"," # Remove the leading number and dot from each sentence\n"," sentences = [content.lstrip('1234567890.- ') for content in contents]\n"," if len(sentences)>2 and isSentence:\n"," sentences = sentences[1:]\n"," return sentences\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SGCRY6x0prpB"},"outputs":[],"source":["!pip install gradio"]},{"cell_type":"markdown","source":["Function: Retrive user feedback values"],"metadata":{"id":"ShxxeL5cd6cm"}},{"cell_type":"code","source":["!pip install firebase-admin"],"metadata":{"id":"Lh9VbTpIehvb","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1713870584843,"user_tz":-480,"elapsed":6411,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}},"outputId":"ec676aa8-addb-45d6-cf4a-5870c4a996f8"},"execution_count":14,"outputs":[{"output_type":"stream","name":"stdout","text":["Requirement already satisfied: firebase-admin in /usr/local/lib/python3.10/dist-packages (5.3.0)\n","Requirement already satisfied: cachecontrol>=0.12.6 in /usr/local/lib/python3.10/dist-packages (from firebase-admin) (0.14.0)\n","Requirement already satisfied: google-api-python-client>=1.7.8 in /usr/local/lib/python3.10/dist-packages (from firebase-admin) (2.84.0)\n","Requirement already satisfied: google-cloud-storage>=1.37.1 in /usr/local/lib/python3.10/dist-packages (from firebase-admin) (2.8.0)\n","Requirement already satisfied: google-api-core[grpc]<3.0.0dev,>=1.22.1 in /usr/local/lib/python3.10/dist-packages (from firebase-admin) (2.11.1)\n","Requirement already satisfied: google-cloud-firestore>=2.1.0 in /usr/local/lib/python3.10/dist-packages (from firebase-admin) (2.11.1)\n","Requirement already satisfied: requests>=2.16.0 in /usr/local/lib/python3.10/dist-packages (from cachecontrol>=0.12.6->firebase-admin) (2.31.0)\n","Requirement already satisfied: msgpack<2.0.0,>=0.5.2 in /usr/local/lib/python3.10/dist-packages (from cachecontrol>=0.12.6->firebase-admin) (1.0.8)\n","Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in /usr/local/lib/python3.10/dist-packages (from google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (1.63.0)\n","Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0.dev0,>=3.19.5 in /usr/local/lib/python3.10/dist-packages (from google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (3.20.3)\n","Requirement already satisfied: google-auth<3.0.dev0,>=2.14.1 in /usr/local/lib/python3.10/dist-packages (from google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (2.27.0)\n","Requirement already satisfied: grpcio<2.0dev,>=1.33.2 in /usr/local/lib/python3.10/dist-packages (from google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (1.62.2)\n","Requirement already satisfied: grpcio-status<2.0.dev0,>=1.33.2 in /usr/local/lib/python3.10/dist-packages (from google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (1.48.2)\n","Requirement already satisfied: httplib2<1dev,>=0.15.0 in /usr/local/lib/python3.10/dist-packages (from google-api-python-client>=1.7.8->firebase-admin) (0.22.0)\n","Requirement already satisfied: google-auth-httplib2>=0.1.0 in /usr/local/lib/python3.10/dist-packages (from google-api-python-client>=1.7.8->firebase-admin) (0.1.1)\n","Requirement already satisfied: uritemplate<5,>=3.0.1 in /usr/local/lib/python3.10/dist-packages (from google-api-python-client>=1.7.8->firebase-admin) (4.1.1)\n","Requirement already satisfied: google-cloud-core<3.0.0dev,>=1.4.1 in /usr/local/lib/python3.10/dist-packages (from google-cloud-firestore>=2.1.0->firebase-admin) (2.3.3)\n","Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.0 in /usr/local/lib/python3.10/dist-packages (from google-cloud-firestore>=2.1.0->firebase-admin) (1.23.0)\n","Requirement already satisfied: google-resumable-media>=2.3.2 in /usr/local/lib/python3.10/dist-packages (from google-cloud-storage>=1.37.1->firebase-admin) (2.7.0)\n","Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth<3.0.dev0,>=2.14.1->google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (5.3.3)\n","Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth<3.0.dev0,>=2.14.1->google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (0.4.0)\n","Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth<3.0.dev0,>=2.14.1->google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (4.9)\n","Requirement already satisfied: google-crc32c<2.0dev,>=1.0 in /usr/local/lib/python3.10/dist-packages (from google-resumable-media>=2.3.2->google-cloud-storage>=1.37.1->firebase-admin) (1.5.0)\n","Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in /usr/local/lib/python3.10/dist-packages (from httplib2<1dev,>=0.15.0->google-api-python-client>=1.7.8->firebase-admin) (3.1.2)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.16.0->cachecontrol>=0.12.6->firebase-admin) (3.3.2)\n","Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.16.0->cachecontrol>=0.12.6->firebase-admin) (3.7)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.16.0->cachecontrol>=0.12.6->firebase-admin) (2.0.7)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.16.0->cachecontrol>=0.12.6->firebase-admin) (2024.2.2)\n","Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3.0.dev0,>=2.14.1->google-api-core[grpc]<3.0.0dev,>=1.22.1->firebase-admin) (0.6.0)\n"]}]},{"cell_type":"code","source":["import firebase_admin\n","from firebase_admin import credentials\n","from firebase_admin import firestore\n","\n","# Initialize Firebase Admin SDK\n","cred = credentials.Certificate(f\"{basedir}/final-year-project-443dd-df6f48af0796.json\")\n","firebase_admin.initialize_app(cred)\n","# Initialize Firestore client\n","db = firestore.client()"],"metadata":{"id":"kybrlGMfYU7M","executionInfo":{"status":"ok","timestamp":1713870606811,"user_tz":-480,"elapsed":1054,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"execution_count":15,"outputs":[]},{"cell_type":"code","source":["def retrieve_user_feedback():\n"," # Retrieve user feedback from Firestore\n"," feedback_collection = db.collection(\"user_feedbacks\")\n"," feedback_docs = feedback_collection.get()\n","\n"," feedback_text = []\n"," experience = []\n"," for doc in feedback_docs:\n"," data = doc.to_dict()\n"," feedback_text.append(data.get('feedback_text', None))\n"," experience.append(data.get('experience', None))\n","\n"," return feedback_text, experience\n","\n","feedback_text, experience = retrieve_user_feedback()\n","# print(\"Feedback Text:\", feedback_text)\n","# print(\"Experience:\", experience)\n","\n","def store_user_feedback(feedback_text, experience):\n"," # Get a reference to the Firestore collection\n"," feedback_collection = db.collection(\"user_feedbacks\")\n","\n"," # Create a new document with feedback_text and experience fields\n"," feedback_collection.add({\n"," 'feedback_text': feedback_text,\n"," 'experience': experience\n"," })\n"," return\n"],"metadata":{"id":"QZoVCsRhd5kU","executionInfo":{"status":"ok","timestamp":1713870611476,"user_tz":-480,"elapsed":1938,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"execution_count":16,"outputs":[]},{"cell_type":"code","execution_count":26,"metadata":{"id":"gDcr_y_JZqmh","executionInfo":{"status":"ok","timestamp":1713871358978,"user_tz":-480,"elapsed":7,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}}},"outputs":[],"source":["import gradio as gr\n","\n","t2v_examples = [\n"," ['A tiger walks in the forest, photorealistic, 4k, high definition'],\n"," ['an elephant is walking under the sea, 4K, high definition'],\n"," ['an astronaut riding a horse in outer space'],\n"," ['a monkey is playing a piano'],\n"," ['A fire is burning on a candle'],\n"," ['a horse is drinking in the river'],\n"," ['Robot dancing in times square'],\n","]\n","\n","def generate_output(input_text, output_video_1 , fps , examples):\n"," def generate_output_fn(input_text, output_video_1, fps, examples):\n"," if input_text == \"\":\n"," return input_text, output_video_1,examples\n"," output = call_gpt_api(prompt = f\"Generate 2 similar prompts and add some reasonable words to the given prompt and not change the meaning, each within 30 words: {input_text}\", isSentence = True)\n"," output.append(input_text)\n"," with open(f\"{basedir}/prompts/test_prompts.txt\", 'w') as file:\n"," for i, sentence in enumerate(output):\n"," if i < len(output) - 1:\n"," file.write(sentence + '\\n')\n"," else:\n"," file.write(sentence)\n"," !sh {basedir}/scripts/run_text2video.sh\n"," #Connect the video output and return the video corresponding link\n"," genScore()\n"," chosen_idx = chooseBestVideo()\n"," chosen_vid_path = interpolation(chosen_idx, fps)\n"," chosen_vid_path = f\"{basedir}/{vidOut}/{chosen_vid_path}\"\n"," # chosen_vid_path = \"/content/drive/MyDrive/FYP/Code/VideoCrafter/results/cat/0002_4X_16fps.mp4\"\n"," output_video_1 = gr.Video(value = chosen_vid_path, show_download_button = True)\n","\n"," examples_list =call_gpt_api(prompt = f\"Generate 5 similar prompts that makes a storyline coming after the given input, each within 10 words: {input_text}\" )\n"," examples = []\n"," for prompt in examples_list:\n"," examples.append([prompt])\n"," input_text = \"\"\n","\n"," return input_text, output_video_1,examples\n","\n"," return generate_output_fn(input_text, output_video_1, fps, examples)\n"]},{"cell_type":"code","source":["interpolation(3,16)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":144},"id":"XwoaLMJTuRSR","executionInfo":{"status":"ok","timestamp":1713871924768,"user_tz":-480,"elapsed":43841,"user":{"displayName":"Emm宥","userId":"02154495825231234225"}},"outputId":"2abd0b74-409f-43f8-f5fe-893bb2f00f2a"},"execution_count":28,"outputs":[{"output_type":"stream","name":"stdout","text":["/content/drive/.shortcut-targets-by-id/1XIExHgH8yTJSya4f1RGhW5Z-hwQwqif_/FYP/Code/VideoCrafter/ECCV2022-RIFE\n","Loaded ArXiv-RIFE model\n","/content/drive/MyDrive/FYP/Code/VideoCrafter/results/10videos/0003.mp4, 20.0 frames in total, 4.0FPS to 16FPS\n","Will not merge audio because using png or fps flag!\n"," 95% 19/20.0 [00:04<00:00, 4.08it/s]\n","/content/drive/.shortcut-targets-by-id/1XIExHgH8yTJSya4f1RGhW5Z-hwQwqif_/FYP/Code/VideoCrafter\n"]},{"output_type":"execute_result","data":{"text/plain":["'0003_4X_16fps.mp4'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":28}]},{"cell_type":"markdown","metadata":{"id":"oALpEY53BFaa"},"source":["### Gradio Interface"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"atwHicx6ZQ-G"},"outputs":[],"source":["import os\n","import sys\n","import gradio as gr\n","import math\n","import matplotlib.pyplot as plt\n","\n","def t2v_demo(result_dir='./tmp/'):\n"," with gr.Blocks() as videocrafter_iface:\n"," gr.Markdown(\"