diff --git a/demo.ipynb b/demo.ipynb index cb8a74d..c00b6d6 100644 --- a/demo.ipynb +++ b/demo.ipynb @@ -780,6 +780,23 @@ "outputs": [], "source": [ "from IPython.display import HTML, display\n", + "import base64\n", + "import os\n", + "\n", + "def get_video_base64(video_path):\n", + " \"\"\"\n", + " Reads a local video file and encodes it to a base64 data URI to play in sandboxed Colab iframes.\n", + " \"\"\"\n", + " if not os.path.exists(video_path):\n", + " return \"\"\n", + " try:\n", + " with open(video_path, \"rb\") as f:\n", + " data = f.read()\n", + " b64_str = base64.b64encode(data).decode(\"utf-8\")\n", + " return f\"data:video/mp4;base64,{b64_str}\"\n", + " except Exception as e:\n", + " print(f\"Warning: Failed to encode video {video_path} to base64: {e}\")\n", + " return \"\"\n", "\n", "def display_comparison(\n", " video_path,\n", @@ -792,6 +809,13 @@ " \"\"\"\n", " Renders a beautifully styled comparison board with local HTML5 video player.\n", " \"\"\"\n", + " video_src = get_video_base64(video_path)\n", + " if not video_src:\n", + " if video_path.startswith((\"http://\", \"https://\")):\n", + " video_src = video_path\n", + " else:\n", + " video_src = f\"https://video2lora.github.io/{video_path}\"\n", + " \n", " html_content = f\"\"\"\n", "
\n", " \n", @@ -803,7 +827,7 @@ "\n", " \n", "
\n", - " \n", + " \n", "
\n", " \n", " \n",